Thread: Which language to start with

  1. #31
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    In C++, you would use a vector and the .at member.
    No, you would do that. I wouldn't. Not the at() member, at least.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Unfortunately, due to some people who thought it was wise to make it undefined to invoke [] for out-of-bounds, they are forcing us to keep a lot of unsafe code around if we don't want to go around it using things such as .at.
    Sometimes I really don't know what they were thinking when they created it. And don't tell me if it was for C compability.
    Safe code before unsafe code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    But we could argue that example is C.
    In C++, you would use a vector and the .at member.
    Preferably, also a safe iterator that can throw if you access out-of-bounds.
    The standard library is sometimes just as unsafe as the C library.
    It is VALID, compilable in C and C++ - and don't tell me that you use vector for every single array that you ever need? There are cases when vector is the right solution, there are others where an ordinary array is just fine.

    It is very likely, in my mind, that a C++ book doesn't start with STL, but begins by teaching the basic concepts that are part of the basic C++ language first, then introduces C++. In my C++ book ["C++ for programmers" or some such], the first 6-7 chapters are about the basic language, only in chapter 7 (or 8?) does it get onto templates, and only after that does it get into STL.

    Maybe I'm also not writing enough user-mode code tho' - I try to avoid code that allocates memory or adds overhead more than necessary.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by matsp View Post
    It is VALID, compilable in C and C++ - and don't tell me that you use vector for every single array that you ever need? There are cases when vector is the right solution, there are others where an ordinary array is just fine.
    If an "array" is the right solution, then IMHO, there simply isn't a good standard container available. Plain "old arrays" are never the best solution unless you're looking for speed.

    It is very likely, in my mind, that a C++ book doesn't start with STL, but begins by teaching the basic concepts that are part of the basic C++ language first, then introduces C++. In my C++ book ["C++ for programmers" or some such], the first 6-7 chapters are about the basic language, only in chapter 7 (or 8?) does it get onto templates, and only after that does it get into STL.
    Of course, I wasn't intentionally implying that it would apply to all programs. Beginners typically always begins with C++/C and moves on to more real C++ later. But when they are full fledged programmers, they should be using C++ and not C++/C.

    Quote Originally Posted by matsp View Post
    Maybe I'm also not writing enough user-mode code tho' - I try to avoid code that allocates memory or adds overhead more than necessary.
    Also this suggests to me that kernel mode really needs to overgo a rehaul. There should be no limit on memory to use and be scared of overhead. That makes code unsafe and that makes the OS crash.
    Safe code before unsafe code, as I say.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #35
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is VALID, compilable in C and C++ - and don't tell me that you use vector for every single array that you ever need? There are cases when vector is the right solution, there are others where an ordinary array is just fine.
    If an "array" is the right solution, then IMHO, there simply isn't a good standard container available. Plain "old arrays" are never the best solution unless you're looking for speed.
    std::tr1::array FTW!
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #36
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    TR1 seems to add a lot of new goodies, doesn't it?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #37
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    But we could argue that example is C.
    In C++, you would use a vector and the .at member.
    Preferably, also a safe iterator that can throw if you access out-of-bounds.
    The standard library is sometimes just as unsafe as the C library.
    Personally I don't think any of the things you mentioned are what really define it as a C++ program. In fact those things all strike me as a Java-like C++ program. C++ has features such as operator overloading specifically so you can do myvector[i] and not myvector.at(i). When I first learned Java I thought it was ridiculous (and I still think so) that everything used the clunky CompareTo() function.

    I also think that the "safety nets" which have been mentioned by various people that Java supplies are needless. How often do most n00bs end up using pointers anyways? When I took my first C++ course in high school, it was an entire year before I really handled a pointer, and by that time I had a solid grasp on the core of the language so when the time came around for me to learn pointers it wasn't a disaster. In terms of other things (such as array-out-of-bounds errors), it provides good learning experiences for people to go through some of those things.

    In terms of the speed of Java compared to the speed of C++: the only thing I will say on that subject is that Netbeans is written in Java and that Netbeans is the slowest IDE I have ever seen in my life. Obviously a bad choice of language for that project in my opinion.
    My Website

    "Circular logic is good because it is."

  8. #38
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    If an "array" is the right solution, then IMHO, there simply isn't a good standard container available. Plain "old arrays" are never the best solution unless you're looking for speed.
    Yeah, well, I think we'll just agree to disagree on this one. There are plenty of places where an array is fine.

    A very clear example is a constant array - they are known size at compile-time, and just gets very complicated if you have to set it up with vector instead,
    Of course, I wasn't intentionally implying that it would apply to all programs. Beginners typically always begins with C++/C and moves on to more real C++ later. But when they are full fledged programmers, they should be using C++ and not C++/C.
    But again, the WHOLE language is there to be used - whatever solves the problem in way of:
    - correct
    - maintainable
    - sufficently efficient
    should be allowed, don't you think?
    Also this suggests to me that kernel mode really needs to overgo a rehaul. There should be no limit on memory to use and be scared of overhead. That makes code unsafe and that makes the OS crash.
    Safe code before unsafe code, as I say.
    If you wish to rewrite the entire OS, feel free. But it's a pretty huge task.

    But there's nothing unsafe about arrays as such - it's only unsafe if you mess up how many elements are actually available in the array - and if you use names constants it can be checked (e.g. using asserts).

    Also, as pointed out in other places, STL doesn't work particularly well across module boundaries (EXE->DLL or User->Kernel). So whilst it may be possible to come up with a class that does work across those boundaries, STL will not work - nor any other template libraries, AFAIK.

    Have you ever written kernel code?

    --
    Mats

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #39
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by DavidP View Post
    Personally I don't think any of the things you mentioned are what really define it as a C++ program. In fact those things all strike me as a Java-like C++ program. C++ has features such as operator overloading specifically so you can do myvector[i] and not myvector.at(i). When I first learned Java I thought it was ridiculous (and I still think so) that everything used the clunky CompareTo() function.
    Absolutely. I can agree no less.
    Unfortunately, some members who designed the library thought it fit to make the default index operator unsafe. So they are forcing us to use .at instead if we want a safe program.

    I also think that the "safety nets" which have been mentioned by various people that Java supplies are needless. How often do most n00bs end up using pointers anyways? When I took my first C++ course in high school, it was an entire year before I really handled a pointer, and by that time I had a solid grasp on the core of the language so when the time came around for me to learn pointers it wasn't a disaster. In terms of other things (such as array-out-of-bounds errors), it provides good learning experiences for people to go through some of those things.
    But, as you understand, just because you think your program is running right, one fine day, your program will crash. If we had a safety net, that would lessen the risk by a lot.
    And it will create a safer environment, as well, because buffer overruns are a security risk.

    Quote Originally Posted by matsp View Post
    Yeah, well, I think we'll just agree to disagree on this one. There are plenty of places where an array is fine.

    A very clear example is a constant array - they are known size at compile-time, and just gets very complicated if you have to set it up with vector instead,
    The problem about vector is unable to initialize it well (but that should be solved in C++0x). Otherwise, even if constant, I would still think it's better with some kind of container, as a safety net or as to provide more functionality to arrays.
    If used correctly, it can make the code more reusable, as well.

    But again, the WHOLE language is there to be used - whatever solves the problem in way of:
    - correct
    - maintainable
    - sufficently efficient
    - sufficiently secure
    should be allowed, don't you think?
    I'd like to add another category, though.
    Constant, non-container arrays fails the red line

    If you wish to rewrite the entire OS, feel free. But it's a pretty huge task.
    Yes, I'm sure this is why the current state of the kernel is as it is. To some extent, anyway.
    It's a shame.

    Have you ever written kernel code?
    No, I'm afraid not. I'm used to user mode where there's plenty of memory and protection available.

    Also note that I wouldn't recommend just std::vector. Obviously, and safe container is a viable choice in this matter. Std::vector is just one of many containers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #40
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    But, as you understand, just because you think your program is running right, one fine day, your program will crash. If we had a safety net, that would lessen the risk by a lot.
    And it will create a safer environment, as well, because buffer overruns are a security risk.
    Can I just point out that there are other ways to create a safety-net than to use C++?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #41
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sure, the argument was for a safety-net within C++, should you use it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #42
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Elysia View Post
    Absolutely. I can agree no less.
    Unfortunately, some members who designed the library thought it fit to make the default index operator unsafe. So they are forcing us to use .at instead if we want a safe program.
    Only if by safe you mean 'I can be a bloody retard and not stay aware of what Im doing in my application'. So you lose track of the size of your arrays and index into a 'safe' array, which instead of crashing and letting you know you wrote sloppy code, proceeds to act like nothings wrong until 6 months after deployment your customers want to know why their databases are trashed and grew 5000%.

  13. #43
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That's an entirely different issue.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #44
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by manav View Post
    Well that basically applies to all the languages, Java, C++ or Python!
    But newbies need to write small programs to get started! I found C++ version to be smaller, more clear, easy!
    Every language allows you to "write small programs to get started". C++ is not smaller than any other language on that respect. You agree then code can be extended or simplified to some extent in all languages. So you can agree the size of the code is not a good measure of how easy the programming language is to learn.

    The next one was performance. However performance is not in the mind of the apprentice when evaluating how easy a certain language is to learn or how easy it is to be taught.

    Ultimately no language is easier to learn than some other language. This is probably most true for at least the mainstream languages; after all there's the fact they are indeed mainstream. You can hear a crowd of Java programmers swearing over how easy that programming language is, the same from Ruby, C, etc...

    Every language presents the newcomer with its own set of challenges and simplifications. What can be asked instead is if some language is easy to learn or can be made easier to learn. I'd say there is a common knowledge around C++ that the language certainly can be improved towards minimizing the learning curve, which if it doesn't contrast with the idea C++ is an easy programming language to learn, at least provides a good case against it in court.

    What is more important instead is that learning a programming language is a personal process that is dependent on many factors, some of them external and out of one's control. At the lowest level our own motivation, background, age and computer literacy can determine how easy a language is to learn. But invariably the method and quality of the teaching will have the strongest impact. Two different people can have completely opposite feelings about how easy C++ is to learn and possibly they are both right.

    Finally, the same programming language can provide the apprentice with rather easy to acquire concepts and concepts that take a lifetime to master. C++ is no stranger to this since if at one hand you have procedural programming that is a rather easy to understand concept, somewhere along the line you'll meet object oriented programming which will take a good chunk of a programmer's life to master and generic programming which, despite being the most sexy thing, shouldn't ever been invented.

    In fact, even at the lowest levels one can meet these apparent idiosyncrasies in the learning process. When learning C++, arrays, pointers and references all can be somewhat easy to acquire. But many, me included, stumble and fall flat on their faces once the keyword const is introduced in their context.

    So to conclude... I dare you to prove some language is easier to learn than the next one
    Last edited by Mario F.; 05-14-2008 at 09:14 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  15. #45
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Most people I know who tried to learn Java (most of them after PHP) had a somewhat hard time grasping the reference semantics of the variables. (PHP 4 didn't use reference semantics.)

    The language isn't without its traps.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Anamoly
    By gemini_shooter in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2005, 05:32 PM
  2. Languages dying
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 07-29-2003, 10:08 AM
  3. Language Script..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-30-2003, 06:48 AM
  4. One Unique Universal Programming Language ?
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 01-29-2003, 12:36 AM
  5. What language did you start with?
    By Fool in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 09-03-2001, 09:21 AM