Slashdot Mirror


Interview With Bjarne Stroustrup

koval writes "artima.com has published an initial portion of interview with Bjarne Stroustrup. The scope of first part is mostly about improving the style of C++ programming and getting maximum from a language."

502 comments

  1. Java ? by Krapangor · · Score: 0, Offtopic

    What do you think of Java ?

    --
    Owner of a Mensa membership card.
    1. Re:Java ? by AKAImBatman · · Score: 1

      > What do you think of Java ?

      PLEASE don't ask that. The guy is a bit touchy on the subject.

    2. Re:Java ? by Drantin · · Score: 1

      Err... I know topics with a title that begin "Interview with" usually mean you can ask questions to the person... but this is an interview done by another site...

      --
      Actio personalis moritur cum persona. (Dead men don't sue)
    3. Re:Java ? by Anonymous Coward · · Score: 0

      What do you think of Java ?

      I think it suxxors.

      Sincerely, B. S.

    4. Re:Java ? by Anonymous Coward · · Score: 0

      Worst programming language in the histroy. Yes, I mean stupid Java

    5. Re:Java ? by cK-Gunslinger · · Score: 1

      Let me answer that for you, since this is a story *about* an interview that has already taken place, not a story for gathering questions for an interview:

      "I think Java is kinda nifty."

      Best answer you'll get. :)

    6. Re:Java ? by mirko · · Score: 1

      It lacks operators, seriously : when I had to develop my cellar for Qtopia, it saved me a huge time and code ergonomy to just use some operator to add new records to my db...

      --
      Trolling using another account since 2005.
    7. Re:Java ? by Anonymous Coward · · Score: 0

      No troll this time, Krapasshole? I'm impressed.

    8. Re:Java ? by Anonymous Coward · · Score: 0

      FUCK YOU you double plated mother fucking nigger bastard mother fucker.

    9. Re:Java ? by ripleymj · · Score: 3, Informative
    10. Re:Java ? by Euphonious+Coward · · Score: 0
      You might as well ask about Delphi, or Object-Pascal. Anybody interested in languages feels the same way about them as about Java and a host of other languages whose names neither you nor I can even remember. They're all proprietary languages that broke no new ground, and were promoted for a while by dying companies, and will all soon be forgotten.

      In five years we'll wonder why anybody even mentioned Java.

    11. Re:Java ? by Anonymous Coward · · Score: 0

      you do realize these operators are nothing more then syntactic sugar? you could have easily created functions such as a.plus(b) or a.equals(b). its possible though you didnt think of this cause the names are so ambiguous.

    12. Re:Java ? by mirko · · Score: 1

      I explicitely wrote about my code ergonomy : C++ is a language...
      Related behavior depends on the compiler as well as on the code cleanness.
      Now, I just prefer a language with which I can add different kinds of virtual objects using the fanciest syntax I may imagine instead of some rigid language like Java in which anything has to be.like(this).

      --
      Trolling using another account since 2005.
    13. Re:Java ? by El_Ge_Ex · · Score: 1

      What do you think of Java ?

      Argh! I hate it when people ask this question! I heard it asked to him on more than one occasion. I dislike it only because it shows a lack of knowledge on the asker's part.

      C++ and Java are two very different languages that just happens to share syntax. A good C++ programmer is not necessarily a good Java programmer and vice versa. In fact, its probably harder to be a good Java programmer if you already have a good amount of experience with C++ (an argument Bjarne himself makes for those going from c to C++).

      C++ and Java are two different languages that are best used for different purposes. If you don't believe then try: dynamic server pages in C++, hardware-accelerated 3D gaming in Java, platform-independent applications in C++, or embedded systems in Java.

      Just because a program _can_ be written in a certain langauge doesn't mean it's the best option.

      -B

    14. Re:Java ? by WWE-TicK · · Score: 1

      > or embedded systems in Java.

      J2ME.

    15. Re:Java ? by Anonymous Coward · · Score: 0

      They're all proprietary languages that broke no new ground, and were promoted for a while by dying companies, and will all soon be forgotten.

      In five years we'll wonder why anybody even mentioned Java.


      You are either pig ignorant or trolling... I only answer you because I'm afraid someone might belive you.

      Java is the number one language taught in beginner Comp Sci classes these days... It is so versatile and powerful that the same language can run on smart cards, mobile phones and huge enterprise servers.

      They survived all the dirty attempts by Microsoft to kill it off, in the end they had to make a complete copy of it, basically changing only the names.

      Unlike the other languages you mentioned, you will find lots of jobs knowing Java.

      It has survived for close to 10 years, and is still evolving.

      And THAT is why we will still be talking about, and programming in, java in 5 years.

    16. Re:Java ? by nocomment · · Score: 1

      people are still using java and C++? Did I migrate completely to C# to early??? Dang!

      --
      /* oops I accidentally made a comment, sorry */
      /* http://allyourbasearebelongto.us */
    17. Re:Java ? by orthogonal · · Score: 1

      C++ and Java are two very different languages that just happens to share syntax. A good C++ programmer is not necessarily a good Java programmer and vice versa.

      Well...

      Java works very much like a (poor) subset of C++.

      My own experience is that, having learned C++ well (and it is a steep learning curve), I was able to easily pass Sun's own Java certification before I had compiled a single Java program (Ok, I did one "Hello World"), because of the surface similarities of the languages.

      One data point only, but either it says something about the similarity of the languages, or what Sun, at least according to its certification, expects of a Java programmer.

      But you are right about the differences required in good programmers in the respective languages. Perhaps the biggest problems in Java are dangling pointers (null pointer exception) and pointer aliasing. The first Java deals with with a run-time exception -- and run time is too late, in my opinion. The second is dealt with by making most language/library objects (String, primitive wrappers (Integer, Boolean, etc.) immutable -- but while immutable objects dion't suffer from pointer aliasing, they're also not efficient (to "change" a value, you have to new up a new instance, and point all pointers to it, often not easy in Java because you can't pass a pointer-to-pointer), and most user objects aren't made immutable anayway.

      C++, on the other hand, strives mightily to treat everything as a value object, even (especially?) when it's not a value object -- thus references, and smart pointers, and the handle-body idiom in general. A down-side can exist when what would be cheap and efficient on a primitive, such as pre-increment (++i) can be very inefficient on an object of class type (thus the C++ism of using post increment even for primitives in for loops, to strengthen the habit of only using pre-increment when trult needed.

      More generally, C++ allows the programmer a great deal of freedom, and expects him to use it wisely (e.g., operator overloading); Java doesn't trust programmers but paradoxically allows dangling pointer problems and unecessary casts that C++ will catch at compile time.

      The run-time versus compile-time costs are perhaps the biggest practical differences of the two languages: C++ requires much more of the compiler (think templates) and of the programmer (e.g, remember method overridding does not happen until an object is fully constructed) in order to endsure that as many costs as possible are paid once, at compile time and not at run-time; Java prefers to pay run-time costs, on the theory that machines are fast enough to pay the run-time costs and the benefit comes from easier, quicker coding. Which trade-off you prefer must really come down to where you fell you can best pay the costs; my take is that good C++ code will be more ribust in general, if robust is what you need.

    18. Re:Java ? by Anonymous Coward · · Score: 0


      you do realize these operators are nothing more then syntactic sugar?


      Well, not quite. In fact that you can't overide operator new() (which you can't even override in C#) breaks encapsulation all over the place.

      When you are designing a class, the decision to use a factory method instead of letting the class user simply call operator new() had better be the right decision for the lifecycle of the code, because changing your mind down the line breaks all users of the class.

      The only safe decision is to always make constructors protected and provide some factory method to create the object. That way, even if the factory simply calls operator new() to start with, you have wiggle room to revisit that decision down the line without breaking everything. But of course this would be stupid, so no one does it unless the need for the factory is clear from the start.

      I understand that the inability to override operator new() is due to the lack of operator delete() in garbage collected languages. (If finalize() comes to mind as an equivalent to operator delete(), please go back to school and try again) but this lack is significant and painful.

      This whole "syntactic sugar" thing came into vogue as a way for ~MS dittoheads to sling FUD at C#. It is too bad that it seems impossible to talk about advantages/disadvantages of language features and capabilities without degenerating into "My language is better than your language, and your mother dresses you funny."

    19. Re:Java ? by AKAImBatman · · Score: 1

      I think you just made the grandparent's point by example. I wasn't going to respond, but I had to ask one question:

      > but paradoxically allows dangling pointer problems

      WTF are you talking about? Java doesn't even have the concept of pointers, much less the ability to leave them dangling. Everything in the system is an Object reference. When all the references no longer point to an object, the object magically goes away. Either you've got an object or you've got a null reference (which IS NOT a critical issue in Java like it is in C/C++).

    20. Re:Java ? by ckaminski · · Score: 1

      In five years we'll wonder why anybody even mentioned Java.
      <P>
      People have been saying that for the past 5 years. It's just as wrong today as it was then.
      <P>

    21. Re:Java ? by Curien · · Score: 1

      Java doesn't even have the concept of pointers, much less the ability to leave them dangling.

      If you truly believe that, you really are a dumbass. Why do you think there's a NullPointerException in Java?

      --
      It's always a long day... 86400 doesn't fit into a short.
    22. Re:Java ? by orthogonal · · Score: 1

      Everything in the system is an Object reference. When all the references no longer point to an object, the object magically goes away.

      (Well, your "magic" is my "serious overhead that makes real-time programming esentially impossible".)

      But you are correct that I wrote "dangling" when I should have written "null".

      However, I don't agree that a null pointer exception is "IS NOT a critical issue in Java like it is in C/C++)". Java's "deals with" unexpected null pointers by throwing an exception; a exception does (or should) signal a critical problem.

      Part of the problem with Java is that run-time exceptions (which are expensive) are used far mmore causually than they ought to be, in some cases even taking the place on nominal program flow.

    23. Re:Java ? by Vorx · · Score: 1

      JOGL (www.javagaming.org)

      --
      Yes this is my real UID. No, it was not bought from EBay.
    24. Re:Java ? by AKAImBatman · · Score: 1

      > Why do you think there's a NullPointerException in Java?

      Because it has a NULL OBJECT REFERENCE. Like I stated above. Nulls are standard in Java and are quite often used without causing program crashes. Besides, it's hardly a dangling reference. You have to intentionally give a variable a Null value or the compiler will throw a fit.

    25. Re:Java ? by Curien · · Score: 1

      Oh, and the designers at Sun must have misspelled "Reference" as "Pointer". Right. Because those keys are right next to each other. Oh, wait... they're not.

      References in Java are pretty much the same thing as pointers in C except that you can't do arithmetic on them.

      In C, pointers have three uses: dynamic memory allocation, aliasing, and array iterators. Java removed the last of those uses (which removed the need for pointer arithmetic), threw on some syntactic sugar (automatic dereference in most contexts) and called them "references" so people like you wouldn't be scared off by the big bad boogeyman.

      Saying Java doesn't have pointers is disingenuous. It's like me saying I don't have a television because I watch TV using my TV tuner card.

      --
      It's always a long day... 86400 doesn't fit into a short.
    26. Re:Java ? by AKAImBatman · · Score: 1

      > (Well, your "magic" is my "serious overhead that makes
      > real-time programming esentially impossible".)

      Let's be realistic here. How often do you *really* need those few hundred extra nano-seconds that the generational collector uses? You could create 50 temporary string references and they'll be deallocated *way* faster than most C code that does it manually.

      > However, I don't agree that a null pointer exception is "IS
      > NOT a critical issue in Java like it is in C/C++)". Java's
      > "deals with" unexpected null pointers by throwing an
      > exception; a exception does (or should) signal a critical
      > problem.

      If you try to use a Null object, you do have a serious problem. However, there are only two ways to get a Null object:

      1. You coded an object to be set to null.
      2. You didn't check if a return value was null.

      In both of these instances, the Null is an expected result that due to a failure to check the value, you have inadvertently used. Look in some professional Java code sometime. You'll see Nulls used all over the place. It simply means "No object could be obtained". (e.g. If I can't find a user preference in a Properties object, I get a Null.) 99% of nulls used in Java do not result in NullPointerExceptions.

      > Part of the problem with Java is that run-time exceptions
      > (which are expensive) are used far mmore causually than
      > they ought to be, in some cases even taking the place on
      > nominal program flow.

      This is not a problem. It is a feature. Just like in Lisp, Smalltalk, Eiffel and a variety of other languages. If you absolutely need the performance that is lost by exception and bounds checking, then don't use Java. Use a real time language such as C in situations where the risk to performance tradeoff is acceptable. But if you're going to try to convince me that your word processor needs those few extra cycles brought about by program safeguards, you might want to check your facts.

      BTW, in my experience, Java is fast everywhere except for windows. This is apparently because of Windows' Virtual Memory which is far to aggressive for programs with larger memory footprints. BSD, Linux, Solaris, Mac OS X, etc. all run Java programs just as fast as native. OS X even allows for Cocoa apps to be written in Java by way of an automatic Java to Object C bridge!

    27. Re:Java ? by Javagator · · Score: 1

      Without "syntactic sugar" you have to deal with expressions like this:

      equals(a, plus(minus(c,(plus(d,e))),f))

    28. Re:Java ? by AKAImBatman · · Score: 1

      > Saying Java doesn't have pointers is disingenuous. It's
      > like me saying I don't have a television because I watch
      > TV using my TV tuner card.

      Statements like this show how little people know about Comp-Sci these days. A pointer and a reference are two separate concepts. A reference CAN be implemented under the hood with a pointer, but there are other ways of doing it (including hardware).

      > References in Java are pretty much the same thing as
      > pointers in C except that you can't do arithmetic on them.

      The primary difference in real world programming is that a reference is managed. You can't arbitrarily assign things to it like you can with a pointer. Plus, you are always guaranteed that you'll have a whole object on the other end, unlike pointers which may point to memory that doesn't even exist!

      > In C, pointers have three uses: dynamic memory
      > allocation, aliasing, and array iterators. Java removed the
      > last of those uses (which removed the need for pointer
      > arithmetic)

      Actually, Java references do only the second. Dynamic memory is allocated outside of the Java program. Your best attempts at allocating new memory in Java may only result in a reuse of memory and objects without your knowledge. That's one of the advantages to references vs. pointers. They are safe and a party outside your program can use system resources in the most effective way possible instead of allowing your program (which may know very little about the system it's on) to manage memory willy-nilly.

    29. Re:Java ? by Canthros · · Score: 1

      Just FWIW, there was a time when Pascal was the language you taught to first-year Comp Sci. students and you could find a surprising amount of employment using it in the real world.

      Note where Pascal sits now.

      --
      Canthros
    30. Re:Java ? by Canthros · · Score: 1

      Sir, that is the funniest thing I have read all day. Bravo on your excellent grasp of pointers, references, and the languages of C++ and Java.

      --
      Canthros
    31. Re:Java ? by AKAImBatman · · Score: 1

      Thank you for your support. I wasn't really trying to be funny, but if it brought a smile to someone's face, I'm happy.

      I just wish I could beat some sense into these Young'uns. ;-)

    32. Re:Java ? by AKAImBatman · · Score: 1

      Heh. How about:

      > hardware-accelerated 3D gaming in Java

      JOGL, JOAL, and JInput. Arguably, most programmers aren't familiar with these APIs since they are rather new. And people have made the (somewhat valid) point before that J2ME devices go beyond being embedded devices and really become small computing platforms. Still, the grandparent post is correct about using the right tool for the right job.

    33. Re:Java ? by Curien · · Score: 1

      Not really. If there was a difference, why do "smart pointers" employ a "reference count"? Sometimes, the term "pointer" can imply an iterative functionality, but that is not strictly so (cf. "smart pointers").

      It has nothing to do with whether they're managed or not. You can have managed pointers, even in C. Heck, you can even plug them into a full-blown garbage collector (or another type of allocator).

      I was going to drop the first use of also, but I decided not to. Every object in Java is "dynamically allocated", so I left it in.

      Again, you're confusing allocators with handles. Even the C++ free store allocator generally has that behavior. It's not uncommon that if you do

      int *p = new int;
      delete p;
      p = new int;

      then p will receive the same address it had before. Reuse of memory is, again, not a difference between C pointers and Java references.

      --
      It's always a long day... 86400 doesn't fit into a short.
    34. Re:Java ? by Anonymous Coward · · Score: 0

      Oh c'mon... Tell him what you REALLY think.

    35. Re:Java ? by AKAImBatman · · Score: 1

      > Not really. If there was a difference, why do "smart
      > pointers" employ a "reference count"? Sometimes, the
      > term "pointer" can imply an iterative functionality, but
      > that is not strictly so (cf. "smart pointers").

      Apples and Oranges. I didn't mention reference counts because they are not inherent to references. Externally managed objects are. As I said before, a reference guarantees that the object on the other end is whole and of the type expected. Pointers don't do that without the compiler doing a little helpful checking for you (that works out to a few warnings).

      > Again, you're confusing allocators with handles.

      No, you are. An object/reference system is completely different from a memory/pointer system. The reason why you're getting confused is that modern day object/reference systems are mapped on top of memory/pointer systems. Machines have existed in the past (Symbolics for example) that quite literally had the hardware designed around the object/reference design.

      BTW, here's an example for you of how you could end up with the same thing:

      String string1 = new String("Hello World!");
      String string2 = new String("Hello World!");

      Without even realizing it, string1 and string2 are quite likely the same object (depending on your VM). The reason is that the Virtual Machine is an external party who is smart enough to know how to give out references that meet the needs of your program. If it can obtain those references by reusing existing objects, it will. Obviously, this example won't work with classes outside of the Java core (the VM isn't quite THAT smart), but it should give you an idea of what I'm attempting to communicate.

      In a similar fashion, the VM may pool shells of objects and initialize them on demand. Or it may preallocate memory for short lived objects and dump the entire memory block when most of the objects are dead (i.e. generational collection). It might defrag memory to make sure that bytes aren't going to waste. It might move an object in memory because it has "outgrown" the block it's in.

      Most of those examples would break pointers since they always point to a specific location. If you moved an object in memory, you need to update all pointers to it. A VM implementation might simply hold a lookup table for the current location of objects in memory and hand out lookup entries as object references. At that point, references would fail to meet the criteria of a pointer. You could still argue that it's "just like a pointer, but with indirection", but all you'll accomplish is displaying how poorly you comprehend CompSci.

    36. Re:Java ? by Curien · · Score: 1

      If you define the word "reference" to mean "exactly what Java's references do" and define "pointer" to mean "exactly what C's pointers do", you'd have a point. But that's not the language-independent definition of those terms. References predate Java, and pointers predate C.

      As far as ensuring that a Java reference always refers to a valid object (or null), that's the business of the allocator. It's got nothing to do with the reference itself. You could design a free store allocator for your C runtime that does the exact same thing (so long as you don't use pointer arithmetic, of course). There's /nothing/ in the C standard that prevents this.

      And as far as your example of the VM remapping memory, that meets the criteria for a pointer. Go read Knuth sometime. Really. Pointers have nothing to do with memory locations. (Nothing /precludes/ them for corresponding, but it's not necessary.)

      --
      It's always a long day... 86400 doesn't fit into a short.
    37. Re:Java ? by AKAImBatman · · Score: 1

      Sir, you are amazingly dense. I will leave it at that.

    38. Re:Java ? by El_Ge_Ex · · Score: 1

      Wow, I started that... :)

      Kudos to your Java knowledge. While my knowledge of C++ is good and mine of the STL has recently improved, my Java knowledge is only to the extent that I realize that its only a falicy: (anything Java can do, C++ can do more efficiently.)

      Ironically, an IBM consultant was the one that changed my thinking...

      -Brian

    39. Re:Java ? by pyrrhonist · · Score: 1

      Best troll ever.

      --
      Show me on the doll where his noodly appendage touched you.
    40. Re:Java ? by Haeleth · · Score: 1

      A minor correction: for VM in your post write "automatic memory manager" throughout. There exist numerous native-code runtimes which do all these things.

    41. Re:Java ? by AKAImBatman · · Score: 1

      > There exist numerous native-code runtimes which do all these things.

      Correct. I was simply flowing with the Java example I gave since I had already stated that the JVM was an example of an external party/entity responsible for handling references.

    42. Re:Java ? by smittyoneeach · · Score: 1

      Dewd:
      You came to the rongg place, you were looking for thoughtful, objective dialogue.
      R,
      C

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    43. Re:Java ? by Curien · · Score: 1

      Yes, that's fallacy number one. Java isn't necessarily slower (or faster). (Often, the VM is a bottleneck, but that's a QOI issue; it has nothing to do with the language per se.)

      Fallacy number two, of course, is that Java doesn't have pointers. :-} (A rose, by any other name...)

      Scratch that... that's fallacy number three. Fallacy number two is that Java is platform-independent. (Hint: the JVM is a platform.)

      --
      It's always a long day... 86400 doesn't fit into a short.
  2. Improvements? by Eric+Ass+Raymond · · Score: 2, Insightful

    How about eliminating the buffer overflows?

    1. Re:Improvements? by swtaarrs · · Score: 1

      There aren't any buffer overflows inherent in the c++ language, it's crappy programming that causes buffer overflows.

    2. Re:Improvements? by orthogonal · · Score: 1

      How about eliminating the buffer overflows?

      std::vector already does this. How about using it?

    3. Re:Improvements? by ultrabot · · Score: 1

      std::vector already does this. How about using it?

      I don't think it does. STL does very little checking in general, because it has to be blazingly fast in order to not be ignored by C++ mainstream (for which performance is everything, never mind the development costs).

      Besides, a lot of people who program C++ have to program in environments ( == old compilers) where such pansy features as STL, RTTI or exceptions are not available.

      --
      Save your wrists today - switch to Dvorak
    4. Re:Improvements? by Anonymous Coward · · Score: 0

      I would, if the STL objects were a little easier to handle. The reason people use arrays instead of vectors, lists or even maps is because they're easy to create and manipulate; it takes very little energy to create an array of 10 "things" and then iterate through each one in a for() loop. Dealing with iterators, and the slightly bizzare (IMHO) syntax required to access the "things" inside the vector (list, map, whatever) just seems far more clunky and requires more brainpower to do something that should in reality, be as easy as using an array.

      What do I know though, I've only been writing in C++ for a couple of years. I expect to get flamed for being an idiot and failing to understand some complex feature of the STL or (God forbid) templates, now.

    5. Re:Improvements? by Dr.+Photo · · Score: 2, Funny

      std::vector already does this. How about using it?

      Am I the first to think that maybe "STD vector" is possibly the worst name for a data type? ;)

    6. Re:Improvements? by Anonymous Coward · · Score: 0

      The funny thing is, most of the features of the STL are conceptually simpler than the pointer-based way of doing things.

      Unfortunately, when people are taught C++, they are first taught that subset of it which is the C programming language.

      So when you finally learn about vector and so on, the tendency is to ask yourself what the point is, when you already know a perfectly good way of accomplishing the same task.

    7. Re:Improvements? by GnuVince · · Score: 1

      Well then, there must be a whole lot of crappy C and C++ programmers and no crappy Java, Python, Ruby, Smalltalk, Lisp programmers.

    8. Re:Improvements? by panserg · · Score: 1

      Well, then how about elimating a crappy programming (by making it impossible) in C++, like it's done since the begining in Java, Python, Smalltalk, Erlang, Lisp, Prolog, ML and Haskell.

      --
      "I shall explain this by waving my hands about in an appropriate manner." -- Cambridge University Math Dept.
    9. Re:Improvements? by Eric+Ass+Raymond · · Score: 1
      Ah. A vulgar, brute-force anonymous coward troll.

      Keep up the good work in the gutter, son.

    10. Re:Improvements? by orthogonal · · Score: 3, Funny
      Am I the first to think that maybe "STD vector" is possibly the worst name for a data type? ;)

      try:
      using namespace condom ;
    11. Re:Improvements? by Anonymous Coward · · Score: 0

      Your lack of logic is astounding. The parent post said, in essence, "there are buffer overflows only if there are crappy programmers". From this you derive "there are no buffer overflows, so there are no crappy programmers"?? Can you say "denying the antecedent?". Good God man, grow a brain.

    12. Re:Improvements? by Anonymous Coward · · Score: 0


      Yes. Here is your obligitory flame:

      Templates and the STL are gigantic points of productivity in C++. Learn them and use them before posting again on this subject. Your meager brainpower should be spent on associating those "things" with objects. A small part of C++ is its ability to use OO. Re-read this chapter in your Dummies book, if it has one.

      Now please go back to the AOL domain.

    13. Re:Improvements? by johnnyb · · Score: 1

      What I don't understand is WHY DOESN'T ANYONE COMPILE BOEHM GC INTO THEIR PROGRAMS???????

      Is that so hard? Is it too much to ask?

      I mean, not only would it save bugs, it would make C++ 10000000 times easier to program in.

    14. Re:Improvements? by orthogonal · · Score: 1

      it takes very little energy to create an array of 10 "things"

      Well, see the first reply to your post -- the STL itsn't what any is used to from C, but it is consistent once you've taken teh trouble to learn it --, and, please recall that writing safe, non-exploitable code is never going to be easy or automatic.

      No offense, but if your primary criterion is "what's easiest" you probably shouldn't be writing high-risk code that processes arbitrary-length buffers which could be prone to buffer overflow. Limit yourself to less risky projects, and limit your buffers to a fixed length, and document that fixed length.

    15. Re:Improvements? by Anonymous Coward · · Score: 0

      Now please go back to the AOL domain.

      I see you have about as much command of the Internet as you have over the English language.

      P.S: If templates & the STL are such gigantic points of productivity in C++, why were they not part of the original C++ specification?

    16. Re:Improvements? by GnuVince · · Score: 1

      Most people believe in the 40 year old myth that started with Lisp that a garbage collector makes a program slow. Of course, that isn't true anymore, but myths stick for longer than facts.

    17. Re:Improvements? by scotch · · Score: 1
      P.S: If templates & the STL are such gigantic points of productivity in C++, why were they not part of the original C++ specification?

      Yeah!! And if seatbelts are such a good idea in cars, how come they weren't in the first Model T?? HuH??

      And if small cell phones are such a good idea, how come the first cell phones were BIG?? Well, mister smarty pants?

      And if journalling filesystems are so fucking hot, how come linux first came out with non-journalling filesystems!!!!? Huh

      And if Swing is such a great toolkit for Java, can you tell my why Java first came out with AWT?? Well, can you, genius??

      --
      XML causes global warming.
    18. Re:Improvements? by AArmadillo · · Score: 1

      Because explicit memory allocation is one of the things that makes C++ so much more efficient than every language you mentioned. You get a lot more out of a regular bike than a bike with training wheels -- as long as you know what you're doing.

    19. Re:Improvements? by some+guy+I+know · · Score: 1
      If templates & the STL are such gigantic points of productivity in C++, why were they not part of the original C++ specification?
      Maybe because they weren't invented yet?
      Maybe because the original C++ compilers compiled to C (cfront, ugh), and so templates were very inefficient at the time?

      C++ has evolved over the years.
      New things get added.
      Python only recently got generators.
      LISP has been around since the 1950's, but it didn't get CLOS until sometime in the 1980's.

      Just because something isn't in the original language doesn't mean it's not useful.
      Many times various extensions to languages/standards are tried.
      Those that are successful may make it into subsequent definitions of a language/standard; those that aren't tend not to.
      --
      Those who sacrifice security to condemn liberty deserve to repeat history or something. - Benjamin Santayana
    20. Re:Improvements? by Anonymous Coward · · Score: 1, Funny

      Just put a wrapper around your object and you shouldn't have to worry about it.

    21. Re:Improvements? by Anonymous Coward · · Score: 0

      No no no, you miss the point in an attempt to defend your bestest ever language.

      The original poster claimed that Templates and the STL were the greatest features of C++ EVAR . If that is the case, what was the point of C++ when it was first invented? The STL & templates didn't exist, so clearly Bjarne has something else in mind for C++ when he first spec'd it.

      The STL is an ugly wart but at least it functions. Templates are a horendous comittee development that turns what should be quite a clean, simple OO-like language into some sort of mutant monster bastard child that eats babies.

    22. Re:Improvements? by stonecypher · · Score: 1

      strncpy() has existed for quite some time, thanks. How about eliminating the coding practices that lead to buffer overflows? Oh, right, it's the *language's* fault. God forbid a language which is designed explicitly to allow you to do exactly what you want to in the nearest-to-machine way reasonable allow you to write security holes too.

      Maybe instead of asking your toolset to design for you - security is a design process, not a patch process, which is why it works for qmail but not for sendmail - you should just learn to write secure code.

      --
      StoneCypher is Full of BS
    23. Re:Improvements? by Eric+Ass+Raymond · · Score: 1
      Think about it.

      The fact is that if the language permits you to write insecure code most people will write insecure code.

    24. Re:Improvements? by scotch · · Score: 1

      Oh, I wasn't aware that the original post was Bjarne. Thanks for setting me straight anonymous coward! If Bjarne thinks that C++ should be a multi-paradigm language, who is he to argue with the wisdom of the drive-by comments of the slashdot AC?

      --
      XML causes global warming.
    25. Re:Improvements? by Troll_Kamikaze · · Score: 1

      There aren't any buffer overflows inherent in the c++ language, it's crappy programming that causes buffer overflows.

      That's a cute sentiment, but the reality is that in a large project that takes months to complete, every programmer--no matter how prodigious his skills--will produce at least some crappy code. In a language that allows buffer overflows, some of this crappy code will cause buffer overflows.

      So you're only correct in theory, not in practice.

    26. Re:Improvements? by GnuVince · · Score: 1

      Did you check out The Great Computer Language Shootout? O'Caml beat C++ in terms of speed, memory usage AND lines of codes (less == better), yet O'Caml does not allow the programmer to do explicit memory management.

    27. Re:Improvements? by Anonymous Coward · · Score: 0
      and kids last longer than a frat party fuck with a fat skank.


      What's your point?

    28. Re:Improvements? by Anonymous Coward · · Score: 0
      gc would eliminate memory leaks, but doesn't do jack shit about buffer overflows.


      IF you have a 1024 byte buffer on the stack and write 2048 bytes to it, you fucked up. If you allocate a 1024 byte buffer and write 2048 bytes to it, you still fucked up. Not having to manually free it later won't help you.

    29. Re:Improvements? by Curien · · Score: 1

      Why would I /want/ GC? I use RAII. My code is exception-safe, let alone pointer-safe. GC only solves a subset of the problems that RAII solves, so why should I bother to use it at all?

      --
      It's always a long day... 86400 doesn't fit into a short.
    30. Re:Improvements? by g_goblin · · Score: 0

      There are ways of getting around this... the *NIX world has the strlcpy family and Microsoft has come out with safe string functions (safestring.h).

      I admit you can get in more trouble with C++ when it comes to buffer overflows, but a programmer worth his salt will be able to spot problem areas before they start and use the before mentions functions when dealing with strings. It's called designing your code before you start tapping it.

      I'm not going to comment on JAVA. I have never used it and never will. So if you haven't programmed a real application in C/C++, you shouldn't comment on either one.

    31. Re:Improvements? by Anonymous Coward · · Score: 0


      There aren't any buffer overflows inherent in the c++ language, it's crappy programming that causes buffer overflows.


      Give programmers memory pointers and there will be buffer overflows. Full stop.

      Java (and others) solved this problem by eliminating memory pointers and replaced them with references. (the difference is that the language and the runtime makes it impossible for a reference to ever point to anything other than a valid object of the correct type or null (plus there is no such thing as "reference arithmetic" and operator [] is NOT a front for reference arithmetic))

      Now the cost (in stupid language tricks and in runtime performance) of takling pointers away from programmers is significant, so it isn'r the right answer for everything. But it does work.

    32. Re:Improvements? by Anonymous Coward · · Score: 0

      E.A.R. responded to me!!! :))) I hate George W. Bush and his administration! I hate living in the USA! It's no longer what it used to be. It's a lie foisted upon the idiots that are my fellow countrymen! Long live Noam Chomsky! Down with the neocons!

    33. Re:Improvements? by Curien · · Score: 1

      Oh fercrissakes! Just don't use pointers in anything but library code!

      It's not that hard.

      Oh, and std::string. Really, people. *sheesh*

      --
      It's always a long day... 86400 doesn't fit into a short.
    34. Re:Improvements? by Curien · · Score: 1

      Good point. Here's the solution:

      Foo tmparr[] = { foo1, foo2, foo3 ... };
      std::vector foos(tmparr, tmparr + sizeof tmparr / sizeof *tmparr);

      works every time, and it only requires one extra line of code.

      --
      It's always a long day... 86400 doesn't fit into a short.
    35. Re:Improvements? by Curien · · Score: 1

      In other news, the government should outlaw cars that can go faster than 65MPH. After all, it's the cars' fault that people speed.

      --
      It's always a long day... 86400 doesn't fit into a short.
    36. Re:Improvements? by stonecypher · · Score: 1

      That's a fairly mundane observation. I could just as easily suggest that "the fact is that if the language permits you to write anything you want, most people will write bad code."

      In fact, that's quite what I'm suggesting is going on. If you have a high power toolset, you have a high powered way to write shitty code. No amount of language alteration will change that bad programmers write bad software. Just as it's not the STL's fault if you can't handle iterators, it's not the language's fault if you can't handle ranges. Don't blame your inability to write secure code on the language. Read a fucking book.

      --
      StoneCypher is Full of BS
    37. Re:Improvements? by Eric+Ass+Raymond · · Score: 1

      As a matter of fact, that's already happening. Where I live, the trucks (semi and full) are limited to 60 mph by law. That's controlled by the tamper-proof electronics in the engine.

    38. Re:Improvements? by Anonymous Coward · · Score: 0

      No, that's legit. I knew her in high school.

    39. Re:Improvements? by johnnyb · · Score: 1

      RAII isn't very useful for memory allocation in C++, although it is useful for other types of resources. The reason is that C++ will often make copies of things even when you don't want to and haven't asked it to, and you have to be VERY aware of the implementation details of your copy constructors at those points. The default copy constructor will screw you over, because it will copy pointers, but if they were alloc'd by you and you free them on destruction, you will have a double-free. That means you have to custom-write ALL your copy constructors. THAT is a nightmare and a half. Using GC you don't have to worry about it nearly as much, because you don't have to worry about the possibility of a double-free in the case of C++ getting over-zealous with copying. There's copy constructors and casting constructors, and sometimes they are used in tandem, which is really screwy (cast to the right type, copy to the program).

      Anyway, using GC you don't have to worry _as much_ about this. Of course, I don't use C++ at all (although I teach it on occassion). I stick to languages that do my dirty work for my like Python, Perl, and Scheme.

    40. Re:Improvements? by bovinewasteproduct · · Score: 1

      Well then, there must be a whole lot of crappy C and C++ programmers and no crappy Java, Python, Ruby, Smalltalk, Lisp programmers.

      I can't speak for C programmers, but for C++, not using the standard library is one of the major sins.

      There are plenty of programmers that use only a little bit or none of the standard library. One of Stroustrup's primary examples is for inputing a string and it has ZERO chance of a memory leak. It uses Standard string and vectors (both of which do automatic memory allocation). For a good book on learning C++ lookup Koenig and Moo's "Accelerated C++".

      In well written C++, the chances of a buffer overrun or memory leak is almost zero. The problem is finding well written code... :(

      BWP

    41. Re:Improvements? by Curien · · Score: 1

      If your class contains more than one pointer, it's not exception safe and therefor hasn't met the requirements for RAII. Any time you use a pointer, it should be wrapped in a class that controlls it (even if it's just an std::auto_ptr).

      Part of RAII design means that you have to think about what to do when you copy your class. Not all classes are logically copyable; if so, just derive from boost::noncopyable and go on your merry way.

      If you use the standard containers and boost (or other) smart pointers, there's really no excuse for naked pointers lying around in your code.

      --
      It's always a long day... 86400 doesn't fit into a short.
    42. Re:Improvements? by God!+Awful+2 · · Score: 1


      strncpy() has existed for quite some time, thanks.

      strncpy, in itself, does not eliminate buffer overflows.

      -a

    43. Re:Improvements? by Anonymous Coward · · Score: 0

      Between the STL and Boost Smart Pointer's, I haven't had a memory leak or buffer overflow in a while.

    44. Re:Improvements? by ckaminski · · Score: 1

      And what you're forgetting is that EVERY language will permit you to write insecure code. Some just don't have buffer overflows. Security is a process, not some magic bullet you can shoot at a project.

      Some languages make it easier than others to write insecure code.

    45. Re:Improvements? by Emil+Brink · · Score: 1

      Sure, strncpy() exists, but is has truly weird semantics in my opinion, I never use it as a no-overrun string copying function. For those, I prefer snprintf() if available, or just use glib and go for its g_snprintf() call. All of these, of course, are C. Oh, and for the size argument of these calls, I always try to use sizeof on the destination buffer, if it is an ordinary C vector. If it's on the heap, there's usually a variable holding the size from the allocation call anyway, and then that is used of course. Just my two hundredths of a currency unit.

      --
      main(O){10<putchar(4^--O?77-(15&5128 >>4*O):10)&&main(2+O);}
    46. Re:Improvements? by aled · · Score: 1

      Because is dangerous. Yes, it is. Really.

      --

      "I think this line is mostly filler"
    47. Re:Improvements? by Anonymous Coward · · Score: 0

      Oh, yeah, tamper proof electronics in the engine. That'll stop 'em from changing the speed sensor...

    48. Re:Improvements? by __past__ · · Score: 1
      Maybe instead of asking your toolset to design for you - security is a design process, not a patch process, which is why it works for qmail but not for sendmail - you should just learn to write secure code.
      Can you name any project of significant size implemented in C and not written by DJB that never suffered from buffer overflows, double frees or format string errors?

      Sorry, but the argument that it's the stupid programmers fault and not the language fails if there is only one non-stupid programmer. Dan Bernstein is just too damn slow to write all the software the whole world needs himself. I'll go for a language where people only fuck up in the ways not due to a too low level of abstraction, like the bugs that occur in high-level-language programs and those of DJB (although he won't admit them usually).

    49. Re:Improvements? by HuguesT · · Score: 1

      the Boehm GC protects you against leaks, not against buffer overflows. The latter is much worse than the former.

    50. Re:Improvements? by Anonymous Coward · · Score: 0

      I am sorry but I "grew" up on the old C language and can say given the constraints at the time mid to late 80's and the youth of "real" languages you were nothing unless you were proficient in C.
      C allows you to take enough rope to shoot yourself in the foot. (little funny there)

      C/C++ assumes you know what you're doing and doesn't forbid the buffer overflow.

      At the time of my education the reason Basic was so slooow besides being interperted was because it was WASTING CPU cycles checking whether you were violating the bounds restrictions that C/C++ ASSUMED were correct.

    51. Re:Improvements? by aled · · Score: 1

      What's the point of using C without pointers?

      --

      "I think this line is mostly filler"
    52. Re:Improvements? by aled · · Score: 1

      Exactly why you need a car designed to violate the law?

      --

      "I think this line is mostly filler"
    53. Re:Improvements? by Anonymous Coward · · Score: 0

      Christ is my saviour.

    54. Re:Improvements? by Curien · · Score: 1

      We're talking about C++, not C. Try to keep up.

      --
      It's always a long day... 86400 doesn't fit into a short.
    55. Re:Improvements? by Curien · · Score: 1

      Well, first of all, there are sometimes valid reasons for breaking speed limits (emergencies, etc). Second of all, not all roads are public. Thirdly, no one would pay lots of money for a new machine unless it went faster, etc. At least, the enthusiasts wouldn't, and we all know who drives the market.

      --
      It's always a long day... 86400 doesn't fit into a short.
    56. Re:Improvements? by mattgreen · · Score: 1

      The parent comment should be marked ignorant, as its clear he has no idea what he's talking about.

      Eliminating the possibility of buffer overflows is not in line with the "philosophy" of C++: you only pay for what you use. As is noted in other posts, std::vector is range checked when you use the at() member function, which works in the same way as the subscript operator.

      It is trivial to inherit publically from std::vector and fit bounds checking on it as well.

  3. Scott Meyers by CyberGarp · · Score: 2, Funny

    Any language that allows for someone making a living pointing out everything one shouldn't do needs more than a face-lift.

    --

    I used to wonder what was so holy about a silent night, now I have a child.
    1. Re:Scott Meyers by gaijin99 · · Score: 2, Funny
      Any language that allows for someone making a living pointing out everything one shouldn't do needs more than a face-lift.

      Cute, but meaningless. Any language has features that are easily overused or abused. One of the things a programming teacher has to do with any beginning class is explain what you shouldn't do. Or at least he should be spending time on that.

      C++ has problems, yes; pretty unavoidable since it was the first real object oriented language. Java has a different set of problems since it was the first language that was OO from the ground up. I'd say its time to learn from the mistakes of both, scrap 'em, and build a language with the pitfalls of neither. 'Course that's a bundle of work, and you can get along well enough in either of them, so people tend to try and patch rather than start from scratch.

      The funny thing is that C still stands out as an excellent general purpose programming language. Possibly a bit akward for use in writing GUI's, but overall it still works after all these years. K&R deserve more praise than they've been getting.

      --
      "Mission Accomplished" -- George W. Bush May 1, 2003
    2. Re:Scott Meyers by kyrre · · Score: 1

      >since it was the first real object oriented language.

      Huh? What about Simula, the first object oriented language?

    3. Re:Scott Meyers by CyberGarp · · Score: 2, Interesting

      C++ has problems, yes; pretty unavoidable since it was the first real object oriented language.

      This comment alone summarizes the posters knowledge of programming languages. For a better understanding of C++, check it out on the Computer Languages History website

      My reply: Cute, but it unfortunately does mean something. C++ has more features that are so easily misused (not abused), that Scott Meyers wrote 3 large volumes on the subject. Other languages have similar featuers, but not in near the quantity of C++. Java has been jokingly refered to as C++--++. The "--" refers to the stripping away of all the majority of the problems that Scott Meyers addresses in his books.

      PS Object Oriented is a concept adapted from functional programming languages, i.e. LISP.

      --

      I used to wonder what was so holy about a silent night, now I have a child.
    4. Re:Scott Meyers by Waffle+Iron · · Score: 5, Funny
      C++ has problems, yes; pretty unavoidable since it was the first real object oriented language. Java has a different set of problems since it was the first language that was OO from the ground up.

      Let me guess... you work as a prior art researcher for the USPTO.

    5. Re:Scott Meyers by PD · · Score: 2, Funny

      Or assembly. You could have any object you wanted, as long as it fit in a register.

    6. Re:Scott Meyers by Anonymous Coward · · Score: 0

      > C++ has problems, yes; pretty unavoidable since it was the first real object oriented language

      OMG, you're so clueless.

      Simula, Smalltalk, and a shitload of others predate C++.

      And, C++ is not object oriented. It is inheritance based, but certainly not object oriented...

    7. Re:Scott Meyers by Frater+219 · · Score: 1
      since it was the first real object oriented language.
      Huh? What about Simula, the first object oriented language?
      Or what about Common Lisp, the first object-oriented language with a published standard?

      It doesn't make much sense to say that any particular language was "the first real object-oriented language" because people have different religious beliefs as to what constitutes a "real" object-oriented language.

      People get into hideous flamewars about that word "real" when applied to categories like "object-oriented", "functional", or "Christian". :)

    8. Re:Scott Meyers by kyrre · · Score: 1

      Ole-Johan Dahl and Kristen Nygaard first published the ideas of object oriented programming. The ideas was implemented in Simula. The story

    9. Re:Scott Meyers by kyrre · · Score: 1

      Really blew it with the url there. http://java.sun.com/people/jag/SimulaHistory.html

    10. Re:Scott Meyers by kraut · · Score: 1

      For a real understanding of C++, read Bjarne's "Design and Evolution of C++". It is truly enlightening.

      --
      no taxation without representation!
    11. Re:Scott Meyers by Frans+Faase · · Score: 1
      > PS Object Oriented is a concept adapted from functional programming languages, i.e. LISP.

      It is definitely not. Functional programming languages work with "values" not "objects". Objects (with having a state) and Functional languages are mutually exclussive. All attempts to introduce objects into functional programming languages have failed.

    12. Re:Scott Meyers by Anonymous+Brave+Guy · · Score: 1
      PS Object Oriented is a concept adapted from functional programming languages, i.e. LISP.

      This comment alone summarizes the posters[sic] knowledge of programming languages. :-)

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    13. Re:Scott Meyers by SumoRoach · · Score: 1

      So, Scott Meyers has 3 volumes of books advocating you not to use C++? Or 3 volumes that advocate using C++ *correctly*? Maybe He's just a money grubber, publishing books on how to use a language that sucks, or maybe he's telling you how to use a good, powerful language correctly without abusing it.

    14. Re:Scott Meyers by stonecypher · · Score: 1

      that Scott Meyers wrote 3 large volumes on the subject.

      To bolster the point, there are a fair number of other authors which have written such series, and some of them arguably more difficult than the effective trio. Notably, Dewhurst's C++ Gotchas and Sutter's Exceptional/More Exceptional C++ are similar vein, similar-or-greater difficulty issues. None quite so well written as Meyers', though.

      --
      StoneCypher is Full of BS
    15. Re:Scott Meyers by Dr.+Photo · · Score: 1

      I swore off C++ almost a year ago (wish I had done it sooner), and in retrospect, getting "the maximum" from C++ felt like getting blood from a turnip.

      Check out Ruby, Python, Scheme, OCaml, Smalltalk, Haskell, Objective-C [I mention this last one because a competent programmer in either C or C++ can pick up the language in 20 minutes...], or some other language you've thought about but never made time to learn. Any and all of these languages will change the way you program, and the way you think about programming. If you've done it right, C++ will feel like an iron lung. (After Ruby [whee!], even Perl seems stuffy. *dons asbestos bodysuit and runs*)

    16. Re:Scott Meyers by WWE-TicK · · Score: 1

      > Or what about Common Lisp, the first
      > object-oriented language with a published
      > standard?

      I thought that honor belonged to Ada 95?

    17. Re:Scott Meyers by Anonymous Coward · · Score: 0

      Are you out of your mind or just clueless?

      C++ was not the first object-oriented language, Simula was.

      Java was not the first language that was completely object-oriented (and still isn't, since it's not), Smalltalk was.

      Both predated C++ and Java.

      CLOS also predated C++ and Java, and it's more flexible than either.

      No wonder people don't know how to choose the right programming languages, if they actually believe things like your post...

    18. Re:Scott Meyers by CyberGarp · · Score: 1

      PS Object Oriented is a concept adapted from functional programming languages, i.e. LISP.

      This comment alone summarizes the posters[sic] knowledge of programming languages. :-)

      Okay smartee pants. LISP was a functional language based on lambda calculus. Early versions had very weak typing. Once the concept of strong typing was introduced, the operations associated with a type formed a neat package. Thus any strongly typed language based on lambda calculus created nice associates between "types" and the allowed operations. Imperative programming language designers saw the obvious benefit of this association and came up with their own retro-fit of the concept into an imperative structure which has come to be known as "object-oriented". Lisp itself wasn't the progenitor of the idea, but the idea of implementing lambda calulus as a language was.

      :-P

      --

      I used to wonder what was so holy about a silent night, now I have a child.
    19. Re:Scott Meyers by RealAlaskan · · Score: 1
      My understanding of it is that Lisp is neither strongly nor weakly typed, but rather dynamically typed: type is determined at runtime, rather than at compile time (compiling is possible, in most dialects, but optional in all).

      More to the point, I believe that the first implementation of OOP was in Lisp. Further, I think that the Common Lisp Object System (CLOS) precedes C++. Finally, folks who probably know what they're talking about tell me that CLOS and the Meta Object Protocol is still the most sophisticated and powerful system there is for OOP.

    20. Re:Scott Meyers by Matthew+Austern · · Score: 1
      I thought that honor belonged to Ada 95?

      The first Common Lisp standard was published in 1984. The Ada 95 standard was published in 1995. (Depending on your definition of "object oriented" you might argue that Ada 83 was an object-oriented language, but most people don't seem to say that.)

    21. Re:Scott Meyers by be-fan · · Score: 1

      Um, there are an entire catagory of languages called "object-functional" that have (surprise!) functional control flow with object-oriented data representation. The two concepts are completely orthogonal. A summary of the major ones:

      Ocaml
      O'Haskell
      Dylan
      Common Lisp (CLOS)
      Scheme (TinyCLOS, GLOS, Bigloo)
      Goo

      And probably a bunch of others I forgot.

      --
      A deep unwavering belief is a sure sign you're missing something...
    22. Re:Scott Meyers by Anonymous+Brave+Guy · · Score: 1
      My understanding of it is that Lisp is neither strongly nor weakly typed, but rather dynamically typed: type is determined at runtime, rather than at compile time (compiling is possible, in most dialects, but optional in all).

      The concepts of weak/strong typing and static/dynamic typing are orthogonal. To condense a whole book into one mostly accurate description, one relates to whether names/objects have a fixed type (static/dynamic) and the other relates to whether names/objects have a type at all, and whether you can break the type system (weak/strong). All four combinations are possible, and IIRC illustrative examples are readily found by Googling on "type system" if you're interested.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    23. Re:Scott Meyers by stonecypher · · Score: 2, Insightful

      Any language that allows for someone making a living pointing out everything one shouldn't do needs more than a face-lift.

      It's not exactly clear to me whether I'm taking a joke on as if it were serious. That said, this is a genuine sentiment with many, so I feel my rebuttal to be germane to them if not nessecarily to you.

      The problem with language is that its domain is inherently difficult. The more expressive a language is, the deeper and more powerful structures it can express. Conversely, because making a language more expressive involves adding new methods of control, the more expressive a language is, the more difficult it is. You need to know how to generate the syntax which wields the new expression mediums, etc.

      The problem as I see it is that the professional field requires a significantly higher degree of skill in expression than the amateur field wants to put forth. At first this seems like a tautology, but think about it: it's fairly rare that an experienced c++ programmer suggests there needs to be a starting-over. Given that few other dominant-in-their-day languages can make that statement, I think it's worth considering that maybe C++ is as horrible as it is by necessity.

      Bjarne suggests that there are more than a dozen languages named D (which is stupid; c++ *is* D, as well as P; don't try to extends jokes you don't understand, folks, kthxbye) and another half dozen named E or P. That some of them are backwards compatible and *still* haven't takjen over should be an indication that C++ is doing at least something right, despite hordes of popular, well supported contenders.

      I too hate a lot of things about C++. But frankly, even though it's not even close to my first language, I can't think of another language I like more for a generic problem domain. Sure, when it's web apps it's PHP; when it's database toys or mostly UI apps it's Delphi; et cetera. Still, when it's difficult, it's c++, every single time.

      Any profession that allows for a whole subprofessions making a living pointing out what one should not do has become satisfyingly deep. Things which one can just jump into and be the best at are shallow. Art, writing, engineering, mathematics, induction, politics, philosophy. Each of these has books, tomes on what you should *not* do in order to be effective. In some fields this study of counterexamples has become so important that it elevates to its own subfield of study (fallacies and converses;) arguably that's happening in CS with AntiPatterns right now.

      What I think you're seeing is a language which is way ahead of the game in community support. ;)

      --
      StoneCypher is Full of BS
    24. Re:Scott Meyers by CyberGarp · · Score: 1

      Object oriented makes no sense in a functional language. If strongly typed, the operations allowed on a type are by definition coupled. The idea of "state" of an object is a based on Simula's original purpose, simulation. The fact that one takes an idea from another area, then adapts it, doesn't mean that it fits into it's original pupose. I.e., Taking the ideas of methods tied to type adding it with state and fitting them into an imperative structure, doesn't mean that one can take the result and fit it back into the strongly typed language. Proving that it doesn't fit back in, doesn't mean that the original conversion didn't happen. Also an imperative language embodies the idea of state at it's core, so pulling stronger data types into an imperative language will automatically add state.

      The concept of a data type {set of values + set of operations on those values}, was derived primarily from research in lambda calculus. The only thing missing is state, i.e. object = {set of values + set of operations + set of state values}. Polymorphism is already allowed for in type theory. Inheritance is a logical expansion of relationships between objects.

      object - data type = {set of state values}

      data typing derives primarily from typed lambda calculus beginning in 1934.

      Therefore, object oriented programming coming later (simula officially began in 1962, but research was really getting started around 1956) than functional programming and owes a certain ideological lineage to it's concepts.

      One could argue that object oriented programming's concepts were discovered independently without any knowledge of data typing from functional research. But that would be a very weak position to defend. The founders of Simula actually mentioned that they were having problems with the weak typing of earlier languages.

      It's all nice and everything to feel that object oriented was a concept that occured in a vacuum and that somehow makes it better, but in reality most ideas are based on previous ideas, which are based on previous ideas, etc, al. My original post was making a joke of the concept hammer being used one too many times.

      Simula also helped research in data typing as well, so functional programming owes a certain debt to object oriented, for some really rough areas in the theory had to be solved for Simula to work. Simula was even more instrumental in the idea of having common libraries.

      P.S. Use what ever language floats your boat. I don't care. I'm not advocating any.

      --

      I used to wonder what was so holy about a silent night, now I have a child.
    25. Re:Scott Meyers by Anonymous+Brave+Guy · · Score: 1
      Okay smartee pants.

      Sorry, couldn't resist. :-)

      I understand your reasoning about LISP, but by your argument pretty much all major programming languages are based on LISP. I've heard the claim that all sufficiently complex programming languages contain as a subset a cut-down, poorly-implemented version of LISP, but only with any sincerity when spoken by somewhat overenthusiastic LISP advocates.

      I think claiming that the concept of object-orientation is based on LISP because it has some traces of lambda calculus and a type system is taking things rather too far. ML or Haskell might be argued to be related to LISP on that basis, but OO has a whole world of models, type systems, programming tools and idioms of its own, and often OO languages don't provide strong support for fundamentals of lambda calculus based languages, such as closures, and functions as first order entities.

      Your claim is a bit like saying that all sufficiently powerful languages are equivalent to BASIC because the Turing test says so: there's an element of truth to it, but that's about as close as it gets.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    26. Re:Scott Meyers by CyberGarp · · Score: 1

      That's not what I said. See other posts.

      --

      I used to wonder what was so holy about a silent night, now I have a child.
    27. Re:Scott Meyers by God!+Awful+2 · · Score: 1


      I too hate a lot of things about C++. But frankly, even though it's not even close to my first language, I can't think of another language I like more for a generic problem domain. Sure, when it's web apps it's PHP; when it's database toys or mostly UI apps it's Delphi; et cetera. Still, when it's difficult, it's c++, every single time.

      I'm with you. I can think of huge flaws with every language I use. I used to use C++ a lot, but now I'm in a job where we have a large codebase that's entirely in C. I see lots of bugs that a good C++ programmer would never make... semaphores that aren't released, memory leaks in strdup, incorrect typecasting. Sure, everyone can see flaws in C++, but I guess the reason why none of the D languages have caught on is that no one can agree on what the specific flaws are.

      -a

    28. Re:Scott Meyers by pyrrho · · Score: 1

      learn to use a pointer you vagrant!

      --

      -pyrrho

    29. Re:Scott Meyers by Anonymous Coward · · Score: 0

      I agree. You can *hate* C++ if you want, but when a job needs to be done it's either C or C++. Sorry, Ruby/Python/Perl/whatever... you are great for classrooms, but nothing else.

    30. Re:Scott Meyers by You're+All+Wrong · · Score: 1

      I'd have said that as soon as things like property lists hit LISP, then it was object-based. There's a fine line between object-based and object oriented. (Some even say that early (<=cfront2) C++ is more properly described as object-based.)
      I have no idea when property lists hit LISP though? They've been in every dialect I've ever encountered, but I've never read any early McCarthy of even MACLISP docs.

      Are you now, or have you ever been, a LISP programmer?
      -- McCarthy

      Or not.

      YAW

      --
      Your head of state is a corrupt weasel, I hope you're happy.
    31. Re:Scott Meyers by You're+All+Wrong · · Score: 1

      Oi!

      _We_ wrote a fair proportion of Sutter's EC++!

      (that is the regulars on comp.lang.c++(.moderated))

      Personally I prefer Sutter, he actually is a 'language lawyer', Myers is more of an amateur (who writes books that needed to be written, so all respect for him for doing that).

      YAW.

      --
      Your head of state is a corrupt weasel, I hope you're happy.
    32. Re:Scott Meyers by You're+All+Wrong · · Score: 2, Interesting

      """
      I swore off C++ almost a year ago (wish I had done it sooner), and in retrospect, getting "the maximum" from C++ felt like getting blood from a turnip.
      """

      Gawd bleshya for your honesty.

      Fess-up time:
      I was a C++ _lecturer_ about a decade ago, and would with a clear conscience recommend it for almost everything(*), but I more often than not (i.e. 90% of the time) recommend _other_ languages than C++ nowadays.

      I've even heard occasional derogatory remarks from those on the national standards committees who ten years ago thought the road to programming heaven was paved with C++.

      YAW.

      (* I even wrote a real-time microkernel in C++ in order to prove to my students that C++ didn't have to be slow. I could task-switch 6000-times a second on a 486/33, for example (but not do anything in the tasks obviously!))

      --
      Your head of state is a corrupt weasel, I hope you're happy.
    33. Re:Scott Meyers by stonecypher · · Score: 1

      I know, as I also frequent usenet, and have my paws in a fair number of GotWs. That said, don't fool yourself: there is a tremendous amount of work involved in just writing that approachably. The authors of math textbooks are no less authors even though the problems are just nubmers and the answers derivable with a calculator; it's the explanation in which the real effort lies.

      Calling Meyers a novice in the face of Sutter is like calling Stroustrup a novice in the face of Knuth. IE: true, *barely*. Watch it: that sort of talk angers the Ghods.

      --
      StoneCypher is Full of BS
    34. Re:Scott Meyers by Paradise+Pete · · Score: 1
      This comment alone summarizes the posters[sic] knowledge of programming languages.

      This comment alone summarizes your knowledge of what [sic] means.

    35. Re:Scott Meyers by Anonymous+Brave+Guy · · Score: 1
      This comment alone summarizes your knowledge of what [sic] means.
      Why?
      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    36. Re:Scott Meyers by Paradise+Pete · · Score: 1

      Sorry, I didn't realize you were quoting someone. I thought you were sic-ing yourself. I wthdraw my smartass remark.

  4. Yes! by kurosawdust · · Score: 3, Funny

    Oh boy! I can't get enough of Bjarne and J-Lo!

    1. Re:Yes! by jollis · · Score: 0

      Gigli++! *Shivers*.

    2. Re:Yes! by Anonymous Coward · · Score: 0

      Could be worse. Could be Gigli#.

    3. Re:Yes! by Anonymous Coward · · Score: 0

      I don't get it.

  5. What about... by Sir+Haxalot · · Score: 1

    Where do you see C++ going as a language?

    --
    I have over 70 freaks, do you?
    1. Re:What about... by Sir+Haxalot · · Score: 2, Interesting

      Where do you see C++ going as a language?
      I think I'll just clarify that. In four or five years, what changes would you like to see happening to the language, and how realistic it is to be able to achieve those goals in that time period?

      --
      I have over 70 freaks, do you?
    2. Re:What about... by Anonymous Coward · · Score: 1, Funny

      C+++

    3. Re:What about... by Anonymous Coward · · Score: 0

      Please moderate the question up to 5. I'd like to see Bjarne answer it.

    4. Re:What about... by hackstraw · · Score: 1

      I think I'll just clarify that. In four or five years, what changes would you like to see happening to the language, and how realistic it is to be able to achieve those goals in that time period?

      Wrong question. Being that there is no (AFAIK) compiler that even conforms to the existing standards, the only change in the language in the next 4 or 5 years would be to make this happen.

      C++ is a neat language to study & learn, but I've found little use for it in the real world. Granted, I'm not a fulltime programmer anymore, and I've never worked on a huge (say the size of mozilla) project, so you can take my suggestions based on my experience with a grain of salt.

      However, when programming in C++, I've found that debugging, even a compile problem at the syntax level to be a pain in the but. I can't tell you how many times I've seen pages and pages of error messages saying that a header that I did'nt know even existed was screwed up, simply because I missed a ';' in my code somewhere. Inheritance, as sexy as it seems, adds a layer of abstraction and complexity, especially if there is a bug somewhere in one of the middle classes. I cannot find a reasonable way to create a reusable class in C++. Because I can do so much with the language with overloaded functions and operators, I don't know when to stop. How many 'new's do we need? What about operators? etc, etc.

      Templates are the best and worst thing about C++. I would never suggest making a typo when using templated classes. The syntax is ugly with templates, but the idea of being able to apply any arbitrary datatpe to predetermined routines is really cool, however, there seems to be a disparity between theory and reality. Templates is another thing that different compilers have problems with.

      I would believe that the best place to use C++, would be on the microsoft platform. M$ has MFC and is relatively stable between platforms and releases. I cannot think of another platform where C++ would be as stable. But this too is changing with .NET and c#, but I do not see any reduction in support for C++ by M$.

      This is my random rambling about C++ for the day. I really like that C++ has pass by reference, and that its a little more anal about prototypes and datatypes than C. Heck, I can use a c++ compiler to compile C code and get this. For portable code, the best thing I've seen is mozillas portable c++ guide, which kinda says, don't use many features of the language.

    5. Re:What about... by stonecypher · · Score: 1

      This paper, c++0x directions, is where he sees c++ going. :D

      --
      StoneCypher is Full of BS
    6. Re:What about... by bovinewasteproduct · · Score: 1

      Wrong question. Being that there is no (AFAIK) compiler that even conforms to the existing standards, the only change in the language in the next 4 or 5 years would be to make this happen.

      Well both gcc 3.X and MS .NET come real close it. In both of them I can take any of the examples in "The C++ Programming Langauge" or from the standard and they just work. They both have bugs, but I would say they are about 95% of the way there. They also cover atleast 95% of the available machines.

      BTW, did you notice the date on the "Portable C++ Guide"?
      It's from back in 1998. (Updated 2 years ago) Over three quarters of the stuff is way out of date.
      e.g. C++ comments are now legal C.
      Who still uses Visual C++ 1.5?
      Who still uses a CFront based compiler? Does any modern OS?

      BWP

    7. Re:What about... by Anonymous Coward · · Score: 0

      hehe. these fucktards are truly clueless.

    8. Re:What about... by Anonymous Coward · · Score: 0

      hehe. these fucktards are truly clueless.
      LOLZ @ YUO. YUO AER TRULY TEH BAD BOY AC TROLLER. WHEN I GROW UP I WANT TO BE YUO.
      Lameness filter encountered. Post aborted! Reason: Don't use so many caps. It's like YELLING.

  6. Probably fake but . . . by Brahmastra · · Score: 4, Funny
    I agree with every word of this probably fake interview

    Interviewer: Well, it's been a few years since you changed the world of software design, how does it feel, looking back?

    Stroustrup: Actually, I was thinking about those days, just before you arrived. Do you remember? Everyone was writing 'C' and, the trouble was, they were pretty damn good at it. Universities got pretty good at teaching it, too. They were turning out competent - I stress the word 'competent' - graduates at a phenomenal rate. That's what caused the problem.

    Interviewer: problem?

    Stroustrup: Yes, problem. Remember when everyone wrote Cobol?

    Interviewer: Of course, I did too

    Stroustrup: Well, in the beginning, these guys were like demi-gods. Their salaries were high, and they were treated like royalty.

    Interviewer: Those were the days, eh?

    Stroustrup: Right. So what happened? IBM got sick of it, and invested millions in training programmers, till they were a dime a dozen.

    Interviewer: That's why I got out. Salaries dropped within a year, to the point where being a journalist actually paid better.

    Stroustrup: Exactly. Well, the same happened with 'C' programmers.

    Interviewer: I see, but what's the point?

    Stroustrup: Well, one day, when I was sitting in my office, I thought of this little scheme, which would redress the balance a little. I thought 'I wonder what would happen, if there were a language so complicated, so difficult to learn, that nobody would ever be able to swamp the market with programmers? Actually, I got some of the ideas from X10, you know, X windows. That was such a bitch of a graphics system, that it only just ran on those Sun 3/60 things. They had all the ingredients for what I wanted. A really ridiculously complex syntax, obscure functions, and pseudo-OO structure. Even now, nobody writes raw X-windows code. Motif is the only way to go if you want to retain your sanity.

    [NJW Comment: That explains everything. Most of my thesis work was in raw X-windows. :)]

    Interviewer: You're kidding...?

    Stroustrup: Not a bit of it. In fact, there was another problem. Unix was written in 'C', which meant that any 'C' programmer could very easily become a systems programmer. Remember what a mainframe systems programmer used to earn?

    Interviewer: You bet I do, that's what I used to do.

    Stroustrup: OK, so this new language had to divorce itself from Unix, by hiding all the system calls that bound the two together so nicely. This would enable guys who only knew about DOS to earn a decent living too.

    Interviewer: I don't believe you said that...

    Stroustrup: Well, it's been long enough, now, and I believe most people have figured out for themselves that C++ is a waste of time but, I must say, it's taken them a lot longer than I thought it would.

    Interviewer: So how exactly did you do it?

    Stroustrup: It was only supposed to be a joke, I never thought people would take the book seriously. Anyone with half a brain can see that object-oriented programming is counter-intuitive, illogical and inefficient.

    Interviewer: What?

    Stroustrup: And as for 're-useable code' - when did you ever hear of a company re-using its code?

    Interviewer: Well, never, actually, but...

    Stroustrup: There you are then. Mind you, a few tried, in the early days. There was this Oregon company - Mentor Graphics, I think they were called - really caught a cold trying to rewrite everything in C++ in about '90 or '91. I felt sorry for them really, but I thought people would learn from their mistakes.

    Interviewer: Obviously, they didn't?

    Stroustrup:

    1. Re:Probably fake but . . . by AKnightCowboy · · Score: 0, Flamebait
      Stroustrup: Well, one day, when I was sitting in my office, I thought of this little scheme, which would redress the balance a little. I thought 'I wonder what would happen, if there were a language so complicated, so difficult to learn, that nobody would ever be able to swamp the market with programmers?

      C++ does seem to be horribly convuluted. Maybe I just have a horrible professor teaching it, but the things that are being demonstrated could've been done just as easily (if not better) using standard C. Object-oriented programming seems to be vastly overrated. Give me C or Perl anyday.

    2. Re:Probably fake but . . . by SoTuA · · Score: 1
      IIRC, it's an april's fools interview. It ranks up there as one of the best ones I've ever seen, along with Linus' April 1st discussion of who should take the role of kernel mantainer.

      Of course, IMBFOS. (I Might Be Full Of Shit)

    3. Re:Probably fake but . . . by GnuVince · · Score: 1

      OO in C++ is horrible. Learn OO with Ruby, Python or Squeak and you shall see the light.

    4. Re:Probably fake but . . . by aurelien · · Score: 1

      Learn OO with CLOS and you shall see the candle that emits the light... (CLOS == Common Lisp Object System)

      --
      aurelien
    5. Re:Probably fake but . . . by Anonymous Coward · · Score: 0

      If you still think member functions are a good idea, you may like the lightweight c++ preprocessor . It adds lightweight c++ features to C.

    6. Re:Probably fake but . . . by Graff · · Score: 1
      OO in C++ is horrible. Learn OO with Ruby, Python or Squeak and you shall see the light.

      Or even move on to Objective-C, which is pretty much parallel to C++ in that it can use plain-vanilla C but Objective-C uses a Smalltalk-type messaging system for object calls. The cool thing is that the latest Objective-C compilers can also use C++ code so that you don't need to re-write old code.

      Basically Objective-C is C with objects, but done in such a way that it doesn't feel like the object-oriented stuff is just bolted on. C++ always felt to me like it was too much of an afterthought, and a clunky implementation at that. With Objective-C everything seems to fit together much more logically. The NextStep/OpenStep/GNUStep/Cocoa libraries are great to work with also.
    7. Re:Probably fake but . . . by Anonymous Coward · · Score: 0

      Link?

    8. Re:Probably fake but . . . by kraut · · Score: 1

      Clearly fake, and nowhere near as funny as his april fools article on the merits of overloading whitespace.

      --
      no taxation without representation!
    9. Re:Probably fake but . . . by johnnyb · · Score: 1

      First, Perl _is_ object_oriented, or at least can be.

      Check out Objective-C for a better Object-Oriented C environment. Unlike C++, Objective-C is fully compatible with standard C.

    10. Re:Probably fake but . . . by Anonymous Coward · · Score: 0

      Overloading whitepace! LMFAO!!!! I never saw that before ... found the link if anyone wants a look , seriously funny shit.

      http://www.research.att.com/~bs/whitespace98.pdf

    11. Re:Probably fake but . . . by BoneFlower · · Score: 1

      Keep in mind that student projects and real world projects are worlds apart. When I wrote my first real PERL program, it was entirely different from any of the example programs in the book.

      Student programs and sample exercises in a book are for demonstrating a language feature- not necesarily the best use for that feature, but the easiest way to explain how to use it.

      Real C++ programmers will write with classes when called for, functions when called for, templates when called for... they will use all the features they need and no more. That was the point of the interview.

    12. Re:Probably fake but . . . by Anonymous Coward · · Score: 0

      That was the funniest thing I've read in some time.

    13. Re:Probably fake but . . . by Anonymous Coward · · Score: 0
    14. Re:Probably fake but . . . by kwerle · · Score: 1

      Object-oriented programming seems to be vastly overrated. Give me C or Perl anyday.

      Yowch! C++ is horrible, convuluted, and vastly overrated. There are any number of languages that aren't. Java isn't great, though it could be.

      Check out Python, Ruby, Objective-C, to name a few.

      Bummer you got marked flamebait - I'm trashing that moderation and just had to follow-up.

    15. Re:Probably fake but . . . by AKnightCowboy · · Score: 1
      Bummer you got marked flamebait - I'm trashing that moderation and just had to follow-up.

      Yea, I don't know what that's about. I was posting a legitimate gripe about the language, or at least the way my professor is teaching it. I'll have to take a look at Python... I've got a coworker that recommends it as well.

    16. Re:Probably fake but . . . by g_goblin · · Score: 0

      Here's the real interview: real

    17. Re:Probably fake but . . . by kwerle · · Score: 1

      Yea, I don't know what that's about. I was posting a legitimate gripe about the language, or at least the way my professor is teaching it. I'll have to take a look at Python.

      Python is neat, but I don't know if I'd recommend it. I do hear that Ruby it bitchin'. If you'd like to check out a clean C extension, maybe take a look at GNUStep, which is Obj-C based:
      http://www.gnustep.org

      Or, if you can drop the $'s, buy a Mac and check out Cocoa development. It's similar to gnustep (they come from the same roots, after all). Careful, though. If you do, you'll never want to go back.

      It may be that I'm biased :-)

    18. Re:Probably fake but . . . by AKnightCowboy · · Score: 1
      Or, if you can drop the $'s, buy a Mac and check out Cocoa development. It's similar to gnustep (they come from the same roots, after all). Careful, though. If you do, you'll never want to go back.

      Already have a Mac. I guess I'll have to fire up Power Builder and check that out.

    19. Re:Probably fake but . . . by kwerle · · Score: 1

      Already have a Mac.

      In which case you [arguably] already have access to the best damn OO development system on the planet. I strongly recommend you go out and buy Aaron Hillegass' book on Cocoa programming and enjoy yourself.

  7. How to improve C++ by Anonymous Coward · · Score: 1, Insightful

    Use Unlambda instead.

    C++ has become a massive boondoggle of poorly-widely-understood and often inconsistently implemented features, in which class reuse is mostly unheard of and different C++ APIs can rarely communicate well with each other natively due to a widespread failure to actually use the standard STL classes (String, Vector, etc).

    It is time to throw out the bathwater. Unlambda combines a strict sense of simplicity with the full power of functional programming, allowing you, once you become familiar with a small set of idioms of the langage, to utilize the same patterns and strategies you used in OO languages such as C++ in a more direct and evocative manner, without the verbose clutter and paperwork OO languages force you into. Have you ever noticed with C++ you spend more time serving the syntax than actually planning your object heirarchies? No more. Unlambda cuts through the crap and lets you write "what you mean" in your code.

    The benefits of Unlambda have been shown in multiple studies. Think: after all the time and energy you have invested in C++, can you really say it has delivered on its promises? Consider using Unlambda for your next enterprise-class project instead.

    1. Re:How to improve C++ by isj · · Score: 1

      Whoever moderated that as "insightful" should probably do some research first :-)

      "Unlamda - Your Functional Programming Language Nightmares Come True"
      http://www.eleves.ens.fr:8080/home/madore/p rograms /unlambda/

    2. Re:How to improve C++ by An+Onerous+Coward · · Score: 1

      I so hate you.

      I thought to myself, "Hmm, sounds like this might have potential." So I asked Google, and it pointed me to a quick tutorial. I clicked immediately on "how to write a loop in Unlambda," and was met with the following example code:

      ```s``sii`ki
      ``s``s`ks
      ``s``s`ks``s`k`s`kr
      ``s`k`si``s`k`s`k
      `d````````````.H.e.l.l.o.,. .w.o.r.l.d.!
      k
      k
      `k``s``s`ksk`k.*

      I never thought I would find a language more intimidating than Intercal, but this may have it beat.

      --

      You want the truthiness? You can't handle the truthiness!

    3. Re:How to improve C++ by Lord+Crc · · Score: 1

      I guess you havent seen brainfuck yet then :)

      Here's (supposedly) the hello world version:
      http://esoteric.sange.fi/brainfuck/bf-source/prog/ HELLOBF.BF

      (I'd post it inline, but it complained about junk characters. Whatever that means...)

    4. Re:How to improve C++ by stonecypher · · Score: 1

      There's a certain subtle beauty to seeing this while it's still marked informative, not funny.

      Besides, intercal > unlambda.

      --
      StoneCypher is Full of BS
  8. maximum by Anonymous Coward · · Score: 0

    The scope of first part is mostly about improving the style of C++ programming and getting maximum from a language.

    Why do you need to interview Stroustrup to learn about getting maximum from C++?

    Just do #include <algorithm>

    Then you can use max() and max_element() on STL objects to your heart's content.

    1. Re:maximum by stonecypher · · Score: 1

      Why do you need to interview Stroustrup to learn about getting maximum from C++?

      Just do #include <algorithm>


      "There are more things in heaven and earth, Horatio, // Than are dreamt of in your philosophy."

      Oh, and there's more to C++ than <algorithm>

      --
      StoneCypher is Full of BS
    2. Re:maximum by eatdave13 · · Score: 1

      *woosh*

      --
      "Verbing weirds language." -- Calvin
  9. Compilers by ultrabot · · Score: 3, Interesting

    Speaking of C++, is there a compiler that complies with the ISO standard already? Does anyone use it?

    --
    Save your wrists today - switch to Dvorak
    1. Re:Compilers by dirtydamo · · Score: 1

      As far as I know, Comeau's compiler is the most standards conformant on the market. It even supports export!

      Only US$50 for per copy.

      The people who use Comeau's compiler are generally concerned with portability, because, as any C++ programmer knows, most compilers completely blow when it comes to standards conformance at the moment.

    2. Re:Compilers by X · · Score: 1

      Actually, all of the most popular C++ compilers are getting pretty close to standards compliance (even g++ ;-). This is largely thanks to the work of The Edison Design Group, who license compiler front ends, and are very focused on standards compliance.

      If you don't want to spend a lot of money, and you don't want to stop using the compiler that you have, I highly recommend The Comeau Compiler. It is a compiler front end derived from the EDG codebase, and only costs you $50. The big downside is that your compile times will be much longer than usual, but at least you can use the export keyword to help with that a bit.

      --
      sigs are a waste of space
    3. Re:Compilers by X · · Score: 4, Interesting
      as any C++ programmer knows, most compilers completely blow when it comes to standards conformance at the moment.
      This is the conventional wisdom. It is (sadly) based on how things used to be. However, there has been a significant amount of progress in the last few years with regards to standards compliance. Aside from the Comeau compiler, you have Microsoft's, Intel's, IBM's, and G++. The last time I used Sun's C++ compiler, the only problems I had were with the antiquated version of the STL that they insist on using for backwards compatilibity purposes. The lastest issue of Dr. Dobbs has actually looked at this based on examples from the C++ standard, and while Borland seems to be making little progress (I don't think their compiler itself has changed in a while), most of the other vendors are rapidly approaching full compliance (although export seems to remain a mystery to everyone besides Comeau).
      --
      sigs are a waste of space
    4. Re:Compilers by BootSpooge · · Score: 1

      The last time I used Sun's C++ compiler, the only problems I had were with the antiquated version of the STL that they insist on using for backwards compatilibity purposes.

      I found that STL Port fixed the problem nicely.

    5. Re:Compilers by Zathrus · · Score: 3, Interesting

      Aside from the Comeau compiler, you have Microsoft's, Intel's, IBM's, and G++.

      I believe that MS VC++ 7.0 (or whatever it's marketed under now) and G++ are the most compliant of the bunch. IBM's compiler may be standard, but their linker is anything but -- thanks to it we can't use dbx or gdb on our code base (both simply core either while loading the core image or when you do a "where"; IBM's dbx occasionally works but never gives proper symbol names and setting break points is impossible). I don't have any experience w/ Intel's compiler so I can't say there. HP's compiler is abysmal.

      One interesting place to look at compatibility is the Boost library -- Boost is a rather large C++ library being developed by some of the big names in C++ that may wind up in the next standard -- and how well it compiles on various platforms and compilers. Check out the compiler status page. It's certainly not a definitive test of what is and is not standard, but it's a data point.

      You're certainly correct in that C++ compilers and their STL libraries have come very far in the past couple of years. One of the worst (Microsoft) is now one of the best -- largely due to them hiring a project lead that's a STL advocate.

    6. Re:Compilers by Hortensia+Patel · · Score: 1

      export seems to remain a mystery to everyone besides Comeau

      More accurately, the only implementation of "export" to date is by the Edison Design Group. Comeau uses the EDG frontend, as do some others (including Intel, I believe, though I'm not sure).

      The EDG members have had some scathing things to say about "export" with the benefit of experience. It was horrendously complicated, and it doesn't (and arguably can't) really achieve any of the goals that motivated its invention in the first place.

      There's an increasing consensus that "export" was a misfeature and should never have made it into the Standard.

    7. Re:Compilers by X · · Score: 1

      I've not experienced those problems with the latest version of the IBM compiler, but it's worth noting that the C++ language itself does not include any standards for link format (although Intel was developed a standard for x86... sort of, as G++ and ecc are both compliant, but still not 100% interoperable ;-). Generally, there is a reason why compiler vendors ship their own debuggers with their product. ;-)

      G++ is, AFAIK, actually the least compliant of the compilers I mentioned in that list, which is in itself a powerful statement of how much progress has been made in standards compliance (G++ made significant progress from the 2.x series to the 3.x series). I believe Metrowerks is also more compliant than G++, but I haven't used it in ages.

      --
      sigs are a waste of space
    8. Re:Compilers by randombit · · Score: 1

      Comeau uses the EDG frontend, as do some others (including Intel, I believe, though I'm not sure).

      I don't think so (but I could be wrong). KAI, a compiler company that Intel bought a few years ago, did use EGD.

    9. Re:Compilers by randombit · · Score: 1

      The people who use Comeau's compiler are generally concerned with portability, because, as any C++ programmer knows, most compilers completely blow when it comes to standards conformance at the moment.

      This makes 0 sense. If someone is worried about C++ portability, they will a) test on multiple compilers, and b) not use super-new features (though AFAIK everything except export is supported by every major compiler). Why would you want a compiler that supported such otherwise-not-supported-by-anyone features if you were worried about portability?

    10. Re:Compilers by be-fan · · Score: 1

      Actually, for awhile, G++ was leading the way in standards compliance. Even today, there is only one EDG-based compiler that can beat it (Comeau) and VS.NET 2003 is just about equal to it.

      --
      A deep unwavering belief is a sure sign you're missing something...
    11. Re:Compilers by be-fan · · Score: 1

      As of 7.x, anyway, ICC does use the EDG front-end. I can verify this because I've got it sitting on my harddrive :)

      --
      A deep unwavering belief is a sure sign you're missing something...
    12. Re:Compilers by stonecypher · · Score: 1

      Comeau is the only 100% compiler; most everyone else hoses export, which is of arguable utility (and which many luminaries want to banish anyway.) For all practical purposes, Borland and Gnu have been ISO compliant for years. Intel's compiler is a monster. VC7 is actually pretty good, though VC6/eVC3 were just a mess. Sun's compiler is pretty strong. The Metaware and Gold Hills toolchains are very strong. ARM's ADS is very compliant (moreso than SDT was.) I don't honestly know the status of IBM's compilers, but I expect the best from them; same goes for SGI since their years as Cray.

      Frankly, the chances that anyone has real use for anything modern compilers regularly get wrong is fairly slim. You must be *powerful* with the force to really scare G++.

      --
      StoneCypher is Full of BS
    13. Re:Compilers by stonecypher · · Score: 2, Interesting

      Sorry, just saying luminaries wanted it banished and then not explaining left a bad taste in my mouth. I should have provided this link to a Herb Sutter article called "Can't Afford Export" (regarding getting rid of the export keyword) in the original post.

      This isn't the only such article, but it's the only one I'm finding on a brief search; IIRC, I think I've also seen similar stances from Meyers and Dewhurst. Not certain, though, 'cause I can't seem to find them (yay 30 second searches.)

      --
      StoneCypher is Full of BS
    14. Re:Compilers by X · · Score: 1

      Measurements of compliance are difficult, but most of the attempts at measurement I've seen have shown that G++ has remained behind at least Comeau, Intel (previously KAI) for basically it's entire existence. Until g++ 3.x came out, g++ was pretty aweful for C++ stuff, such that most of the common Windows compilers (Microsoft, Borland, IBM) were well ahead of it, along with most of the Unix vendor's compilers. 3.x was definitely a huge step forward, but so were compilers released from the above vendors around the same time (with the exception of Borland). If g++ was leading the way, I'd suggest it was merely because g++ got it's release out ahead of the others. ;-)

      I cannot agree with your statement about VS.NET 2003 being "just about equal to it". By my own experiences, and by any assessment I've seen, VS.NET 2003 is actually head and shoulders ahead of g++ in terms of language compliance (g++ 3.4 may correct this).

      --
      sigs are a waste of space
    15. Re:Compilers by be-fan · · Score: 1

      I was talking about the performance since the 3.x series started, when its primary competition was VC++ 6.x and VS.NET 2002. Intel's compiler wasn't as good as the 3.x series until around 7.0 or 7.1. This assesment is from personal experience using all of these compilers. Note, that my primary experience with GCC and ICC are on Linux, while my experience with VS is (of course) on Windows. Lastly, I'm using both VS.NET 2003 and GCC on a C++ project (written in "modern" style with Boost and STL) and I haven't encountered problems with either.

      --
      A deep unwavering belief is a sure sign you're missing something...
    16. Re:Compilers by Anonymous Coward · · Score: 0

      Who gives a darn now how standards-compliant C++ is? Though not quite dead, others have become the primary force in S/W.

      C++ took soooo long to achieve any kind of standard, that left the door wide open for Java (remarkably standard API across platforms) and for M$ to introduce C# and their other crap.

      The only people that will care about C++ standardization will be the software archeologists.

    17. Re:Compilers by Lord+Omlette · · Score: 1

      This month's DDJ and last month's issue run C++ compilers through a bunch of benchmarks. Basically Visual C++.NET 2003 produces the smallest code and is only slightly less compliant than gcc 3.3.

      --
      [o]_O
    18. Re:Compilers by HuguesT · · Score: 1

      > VS.NET 2003 is actually head and shoulders ahead
      > of g++ in terms of language compliance (g++ 3.4
      > may correct this).

      Are you sure about this? According to the latest Dr Dobbs Journal review of C++ compilers for Windows, g++ 3.3 has the best compliance. Do you have a specific feature in mind?

    19. Re:Compilers by X · · Score: 1

      Hmm... as I said before, these kinds of measurements are kind of arbitrary, so I'll concede that in general it is a subjective matter. My experience though is that VC++ rejects a lot more non-standards compliant code than g++, an observation that has been backed up by every test I've seen, including the current one in Dr. Doobs.

      Dr. Dobbs did indeed just do a review of various compilers, by using the examples found in the language standard. If you check out the November 2003 issue, on pages 58 & 60 they have the results for the various compilers tested. You will find that VC++ 7.1 gets a 98.22 rating, while gcc 3.3 gets a 96.14. If you don't give VC++ any "strict conformance" flags, it drops to 96.59, which is pretty close to g++'s score, but still above it.

      Now, that mechanism for measuring conformance is not particularly good, but then again neither are any of the others. ;-) Certainly all of the "serious" compilers out there are getting close enough to standards compliance that the right kind of metric will show one of them to be the leader. My experience has mostly been from writing code in g++, trying to be portable, and then finding out that when I ported it to VC++ 7.1 it finds all these errors that are indeed illegal C++ constructs. YMMV.

      --
      sigs are a waste of space
    20. Re:Compilers by 4of12 · · Score: 1

      worried about C++ portability, they will a) test on multiple compilers

      Yes.

      The interesting thing is how the intersection of supported features has changed a lot over the past decade.

      There used to be some C++ coding standard guidelines used by the Netscape/Mozilla team that were quite restrictive because of the need for Windows/Mac/Unix cross platform use.

      I imagine a lot of those restrictions have dissolved as new compilers have become more standards compliant.

      The really nice thing about standards, though, is that developers can extrapolate forward a little in the direction of standards. Not too much, mind you, but for a project that is under development for many years, as many C++ projects are, this can help reduce crufty anachronisms introduced soley so that code will compile on 8 year old compilers.

      --
      "Provided by the management for your protection."
    21. Re:Compilers by HuguesT · · Score: 1

      > My experience though is that VC++ rejects a lot
      > more non-standards compliant code than g++,

      In that sense then yes I agree. I always think of a compiler not accepting standard constructs as being more of a problem.

      Did DDJ run g++ with `-ansi -pedantic' ? usually that helps a bit for the `type 2' errors that you are mentioning.

    22. Re:Compilers by X · · Score: 1

      Did DDJ run g++ with '-ansi -pedantic'?

      Yeah, as I said, they ran it with the various strict conformance flags, and for the code bits they pulled from the standards documents, they saw no improvement for g++ (VC++ demonstrated a measurable improvement). This is partially an indication of how the measurements were arbitrary. Of course, you have to wonder why compiler writers wouldn't focus on getting the examples in the language standard working first when doing their work.

      --
      sigs are a waste of space
  10. Why did they need to interview bjarne about that? by blake8087 · · Score: 0

    All he did was complain about over and under object-orienting c++ code. Not sure why that's useful... My Computer Science professors do that all the time.

    --

    --Slashdot readers delight in generalizing the behavior of other Slashdot readers.
  11. Confusion (not a Slashdot interview!) by wackysootroom · · Score: 2, Informative

    I see that a lot of people here are confused and posting questions for Bjarne Stroustrup. This is not a slashdot interview where people post questions for the guru and the editors pick the top 5 for the interviewee to answer. This is an interview that was done by an external website and not interviews.slashdot.org.

    1. Re:Confusion (not a Slashdot interview!) by Anonymous Coward · · Score: 0

      i would say to people looking for interviews to try /.'s Interview section. Except that the link that appears on the right hand side of the /. homepage looks borked

    2. Re:Confusion (not a Slashdot interview!) by dirtydamo · · Score: 1

      This is not a slashdot interview where people post questions for the guru and the editors pick the top 5 for the interviewee to answer.

      Boy, and I thought people didn't RTFA. Why don't they even RTFS (summary), or how about RTFT (title)?

  12. Re:Who is Bjarne Stroustrup? by TheLevelHeadedOne · · Score: 1

    Ever had a real programming language class?

    --

    Twin or more? ITA
    Apache/Spring/La
  13. Re:+1 didn't read the article by Sir+Haxalot · · Score: 1

    This and this made me thought that the questions were being asked now, d'oh! Oh well, Bjarne if you're reading this... :)

    --
    I have over 70 freaks, do you?
  14. Re:Who is Bjarne Stroustrup? by dreamchaser · · Score: 1, Insightful

    Since you only got smart ass replies, here you go: Bjarne Stroustrup was the creator of C++.

  15. You cannot organize this by jetkust · · Score: 1, Insightful

    Seriously, you can't seriously improve a language by telling people how to program with it. You also don't know if these so-called style improvements help anyone at all. This is just like Hungarian notation, where people stupidly decided they wanted to know the type of a variable by looking at its name. The C++ language is what it is. Whatever you can do with it is what it is. You can't make C++ into Java by telling people what they can't do. This is why C++ is not Java. The "problems" in its design are part of the language.

    1. Re:You cannot organize this by cK-Gunslinger · · Score: 1

      Are you saying that "_f_m_computedAreaOfCircle" is not a good name for the private member floating point variable that holds the computed area of the containing circle object? =)

    2. Re:You cannot organize this by deputydink · · Score: 1

      Seriously, you can't seriously improve a language by telling people how to program with it.

      So true... if it wasn't we'd all be programming Visual Basic for a living.

    3. Re:You cannot organize this by ozzee · · Score: 1
      Seriously, you can't seriously improve a language by telling people how to program with it.

      You can write bad code in any language. I don't see how your statement and the prvious sentence can both be true unless you equate it to some individuals are capable of programming and some are not, but, at some point in time, we had to be "told" how to write programs which kind of invalidates your statement.

      The other point is, there are a number of rules that you can use that if abided by will have fewer chances of error.

      Maybe I missed your point.

    4. Re:You cannot organize this by jetkust · · Score: 1

      You can write bad code in any language. I don't see how your statement and the prvious sentence can both be true unless you equate it to some individuals are capable of programming and some are not, but, at some point in time, we had to be "told" how to write programs which kind of invalidates your statement.

      Not exactly sure what you are saying here. But by when I say how to program, I am speaking of style. Which is what the interview is about.

      The other point is, there are a number of rules that you can use that if abided by will have fewer chances of error.

      Yes. My point is that by telling everyone to use this same rule doesn't improve or change the language. And that it is perfectly fine to not use this rule since the rule is not part of the language.

    5. Re:You cannot organize this by X · · Score: 1
      This is just like Hungarian notation, where people stupidly decided they wanted to know the type of a variable by looking at its name
      Sadly, the original idea behind Hungarian notation seems to have been lost to the ages. The idea behind it was that the C language's weak typing made it quite easy to accidently use the wrong type, particularly when doing parameter passing. The idea was to encode the type into parameters and variables, such that it would become blantantly obvious when one was making such a mistake (i.e. the parameter list calls for lpuiSize and you're passing iSize). This was particularly problematic in the Win16 days when you had near and far pointers. While it is definitely a hack, and I'd much rather see the language standard fixed in this regard, and the notation itself is very Windows-centric, it is nonetheless not a stupid idea.
      --
      sigs are a waste of space
    6. Re:You cannot organize this by 2short · · Score: 1


      I would write it "m_fContainingCircleArea".
      I do like knowing at a glance that an identifier is a member variable, and I've never heard a good reason why people don't like reasonable use of Hungarian.
      I had one coworker who hated it. So, for example, when declaring an integer, he would absolutely refuse to stick a lowercase "i" or "n" on the front. 8 times out of 10 the variable name would include "Num", "Number", "Count", etc. anyway, but not in a consistant place, and not all the time. An "n" would have been shorter, easier to find, and would have become a habit.
      Really, what is the problem people have with Hungarian, assuming it is used reasonably? (By which I mean, my prefix strings are almost exclusively single-charachters, and only about 6 different ones.)

    7. Re:You cannot organize this by happyfrogcow · · Score: 1

      Not exactly sure what you are saying here. But by when I say how to program, I am speaking of style. Which is what the interview is about.


      However, how much programming style was absorbed by the community with K&R's C book?

      The problem is that people who learn C++ probably never read "The C++ Programming Language." They might have read K&R, then picked up some "C++ in 21 Days" book.

      you said, "telling everyone to use this same rule doesn't improve or change the language", but it does. The problem here is that hardly anyone bothered to listen to those who were telling us how to do things. C++ is poorly taught in universities, atleast at mine it was. Now that Bjarne and other have recognized how poorly C++ has been taught over the years, they are trying to do something about it.

    8. Re:You cannot organize this by PainKilleR-CE · · Score: 1

      However, how much programming style was absorbed by the community with K&R's C book?

      The problem is that people who learn C++ probably never read "The C++ Programming Language." They might have read K&R, then picked up some "C++ in 21 Days" book.


      Exactly. This is almost the way it was taught when I was in college (not quite C++ in 21 Days, but still basically use C and this, this, and that).

      In fact, I found the K&R book so good for a straight C reference that I bought the 2nd edition (I was forced to sell the one I had in college back to the book store when I was in dire need of a book for my English course) at the same time that I finally picked up "The C++ Programming Language". If there's one thing the newer editions of the latter title do well, it's point out that C++ is not C, and shouldn't be treated as such.

      I had one teacher that almost got it right, but probably made the mistake mentioned in the interview of treating everything as an object, when it's not really needed.

      --
      -PainKilleR-[CE]
    9. Re:You cannot organize this by gfody · · Score: 1

      how about just AreaOfCircle.. your ide should tell you that its private and that its a float, and "computed" is sort've implied by it being a variable in the first place. In the case this is a class property where the class is the circle well then it should just be Area because circle is implied.

      I'm really picky about variable names.. in the end if you can stay consistent and make good decisions on variable names it ultimately makes the biggest difference as to the readability of your code

      --

      bite my glorious golden ass.
    10. Re:You cannot organize this by Dionysus · · Score: 1

      Check Windows function that takes DWORD, but because the original function had WORD in the function variables, the variable itself has the wrong name.

      Something like
      VOID Foo( DWORD wbar );

      Lots examples like this if you look around. I just think it's really bad idea to encode the tpye into the variable name.

      --
      Je ne parle pas francais.
    11. Re:You cannot organize this by cK-Gunslinger · · Score: 1

      Not to be too negative, but the idea of relying on an IDE for code maintenance and documentation is crazy. Not everyone using/supporting your code will even use an IDE, much less the same one you do. There is some sound reasoning behind self-documenting code, just as long as it's taken with a grain of salt, much like everything else in the world.

    12. Re:You cannot organize this by jetkust · · Score: 1

      Not to be too negative, but the idea of relying on an IDE for code maintenance and documentation is crazy. Not everyone using/supporting your code will even use an IDE, much less the same one you do. There is some sound reasoning behind self-documenting code, just as long as it's taken with a grain of salt, much like everything else in the world.

      Actually, most likely they WILL all be using the same IDE. Plus, you can't write everything to be backwards compatible to some hungarian notation geek who insists on coding everything in notepad. I agree with parent post 100%.

    13. Re:You cannot organize this by 2short · · Score: 1


      So why wasn't the name changed when the type was?

      I can show you lots of examples where someone changed some code, but didn't change the comment describing that code, so now the comment is just wrong. That's a lot worse than a wrong hungarian. Should I stop commenting altogether to avoid this?

      FWIW, I described my notation system in another branch of this thread; I wouldn't use "w" in this context, nor whatever you'd use for DWORD. Don't know what I would use because what the hells a WORD/DWORD? (sure, I could guess, and if I actually needed to know I guess I'd look it up, but suffice it to say it doesn't come up in my code much.

      Hmm, is DWORD the type windows process stuff uses for proc handles? I think it might be. See in that case, I'd use some descriptive var name prefixed with "handle". I don't care that it might be (guessing) a 64 bit unsigned integer, that's irrelevant to it's use. The fact that it's a handle is relevant.

      I hate to see a variable named "total" if it's used more than a dozen lines away from its declaration. "nTotal", "fTotal" or "sTotal" tells me what I'm dealing with. And I'm definitely going to want the extra info if it's "m_psTotal".

    14. Re:You cannot organize this by Haeleth · · Score: 1

      > Are you saying that "_f_m_computedAreaOfCircle" is not a good name for the private member floating point variable that holds the computed area of the containing circle object? =)

      Correct. The proper name for that variable would be "circ_a".

    15. Re:You cannot organize this by __past__ · · Score: 1
      Most IDEs include a compiler or interpreter of some kind, that will parse your code and barf on type errors. If yours doesn't because the language is too weakly typed to provide meaningful error messages, the right thing to do is using one that has a useful type system, like any language in common use except assembly, C, C++, Basic, Perl or PHP.

      Encoding types in variable names helps exactly as much as calling a C string "name_that_will_never_be_longer_than_128_chars" and omitting bounds checking.

  16. Not worth reading by Anonymous Coward · · Score: 1

    Please don't waste your time reading that interview. The interviewer is asking very irrelevant questions and doesn't seem to have a clue about what the other is answering. His answers are garbage anyways, the whole discussion is about invariants. It looks long because there's 4 pages, but if they'd use a normal font, it'd fit easily on a single page... Elementary school level interview if you ask me.

  17. Re:OOP IS FOR PUSSIES by ultrabot · · Score: 1, Insightful

    Real men code in assembler.

    For very contorted definition of real men. OOP requires higher degree of abstract thought than assembler, and obviously not everyone can hack it. Assembler, Fortran and Visual Basic are for people whose brain can't handle abstraction, but rather just want to get their hands dirty doing stuff. People who would rather do than think what they are doing. Others take delight in creating abstract architectures and systems that Last.

    Obviously many self-proclaimed C++ programmers belong in the assembler group, rather than the OOP group (where Python/Java/Smalltalk people dwell).

    --
    Save your wrists today - switch to Dvorak
  18. it's getting slow by Anonymous Coward · · Score: 0

    The C++ Style Sweet Spot
    A Conversation with Bjarne Stroustrup, Part I
    by Bill Venners
    October 13, 2003

    Summary
    Bjarne Stroustrup talks with Bill Venners about the perils of staying too low level and venturing too object-oriented in C++ programming style.
    Bjarne Stroustrup is the designer and original implementer of C++. He is the author of numerous papers and several books, including The C++ Programming Language (Addison-Wesley, 1985-2000) and The Design and Evolution of C++ (Addison-Wesley, 1994). He took an active role in the creation of the ANSI/ISO standard for C++ and continues to work on the maintenance and revision of that standard. He is currently the College of Engineering Chair in Computer Science Professor at Texas A&M University.

    On September 22, 2003, Bill Venners met with Bjarne Stroustrup at the JAOO conference in Aarhus, Denmark. In this interview, which will be published in multiple installments on Artima.com, Stroustrup gives insights into C++ best practice. In this first installment, Stroustrup describes how C++ programmers can reconsider their style of C++ use to gain maximum benefit from the language.

    Climbing above C-level
    Bill Venners: In an interview, you said, "The C++ community has yet to internalize the facilities offered by standard C++. By reconsidering the style of C++ use, major improvements in ease of writing, correctness, maintainability, and efficiency can be obtained." How should C++ programmers reconsider their style of C++ use?

    Bjarne Stroustrup: It's always easier to say what not to do, rather than what to do, so I'll start that way. A lot of people see C++ as C with a few bits and pieces added. They write code with a lot of arrays and pointers. They tend to use new the way they used malloc. Basically, the abstraction level is low. Writing C-style code is one way to get into C++, but it's not using C++ really well.

    I think a better way of approaching C++ is to use some of the standard library facilities. For example, use a vector rather than an array. A vector knows its size. An array does not. You can extend a vector's size implicitly or explicitly. To get an array of a different size, you must explicity deal with memory using realloc, malloc, memcpy, etc. Also, use inline functions rather than macros, so you don't get into the macro problems. Use a C++ string class rather than manipulating C strings directly. And if you've got a lot of casts in the code, there's something wrong. You have dropped from the level of types, a high level of abstraction, down to a level of bits and bytes. You shouldn't do that very often.

    To get out of writing low level code, you needn't start writing a lot of classes. Instead, start using facilities provided in libraries. The standard library os the first and most obvious source, but there are also good libraries for things like math or systems programming. You don't have to do threading at the C level. You can use a C++ threading library. There are quite a few of them. If you want callbacks, don't use just plain C functions. Get libc++, and you'll have a proper library that deals with callbacks--callback classes, slots and signals, that kind of stuff. It's available. It's conceptually closer to what you're thinking about anyway. And you don't have to mess with error prone details.

    Most of these techniques are criticized unfairly for being inefficient. The assumption is that if it is elegant, if it is higher level, it must be slow. It could be slow in a few cases, so deal with those few cases at the lower level, but start at a higher level. In some cases, you simply don't have the overhead. For example, vectors really are as fast as arrays.

    Object-Orientaphilia
    The other way people get into trouble is exactly the opposite. They believe that C++ should be an extremely high level language, and everything should be object-oriented. They believe that you should do everything by creating a class as part of a class hierarchy with lots of virtual functions. This is the ki

  19. Another Interesting Interview by pararox · · Score: 1

    Here's another very interesting interview with the C++ creator. You'll be shocked, I promise ;)

    Regards,

    -pararox-

    1. Re:Another Interesting Interview by Anonymous Coward · · Score: 0

      Yeah, I would be shocked. Except that my 500 millionth exposure to this "interview" occurred earlier in this very slashdot discussion.
      It's not even very good. The one with K&R claiming C was an april fools joke and they both use Pascal was much cleverer.

  20. From the article by Apreche · · Score: 3, Insightful

    Quote Bjarne Stroustrup: Yes. If every data can have any value, then it doesn't make much sense to have a class. Take a single data structure that has a name and an address. Any string is a good name, and any string is a good address. If that's what it is, it's a structure. Just call it a struct. Don't have anything private. Don't do anything silly like having a hidden name and address field with get_name and set_address and get_name and set_name functions. Or even worse, make a virtual base class with virtual get_name and set_name functions, and override it with the one and only representation. That's just elaboration. It's not necessary.

    Thank You! This is the number one java peeve. Every time I just want to make a structure I've got to make a whole class. That's a whole file. That's a whole lot of extra code. In C/C++ I can make an equivalent struct in a few lines.

    This is why I like python so much. I can do all the object-orientedness I want and all the proceduralness I want and they work together perfect. And everything pops out into super efficient C code and then into executable with my gcc. And if I want it cross platform I can just use jython and get workin .class files.

    --
    The GeekNights podcast is going strong. Listen!
    1. Re:From the article by volsung · · Score: 1

      How are you getting super efficient C code from your python programs?

    2. Re:From the article by criquet · · Score: 1

      In java, you can include private classes in the same .java file as a public class and you can also create nested classes. If you make all the data/fields in the class public and have no methods, then what you have a struct.

    3. Re:From the article by Eryq · · Score: 1
      This is the number one java peeve. Every time I just want to make a structure I've got to make a whole class. That's a whole file. That's a whole lot of extra code. In C/C++ I can make an equivalent struct in a few lines.

      You can do this in Java too. You can declare a tiny helper class -- without methods or explicit constructors if you like -- inside another class. No need to put it in its own file.

      They're called "inner classes", and you can declare them static (so they act like a regular class) or non-static (in which case every instance of the inner "member" class has an invisible reference to the creating instance of the outer class.

      You can even declare one inside a method (useful for one-shot implementations of interfaces) -- those are called "anonymous inner classes".

      Very powerful, and very flexible.

      I find that nearly everyone who criticizes Java is either using an ancient implementation (e.g., JDK 1.1.7, for applets), or they simply haven't explored the language fully.

      --
      I'm a bloodsucking fiend! Look at my outfit!
    4. Re:From the article by the+uNF+cola · · Score: 1

      Wha? You can create an inner class. If you make it static, you can share it publically (new X().Y() or new X.Y()). If you make all it's attributes public, you get what is the equiv of a struct.

      public class X{ public int a; public int b } ...

      X z = new X();
      z.a = 1;
      z.b = 1;

      is it really THAT much different from

      typedef struct { int a; int b; } X

      X *z = ( *X ) malloc( sizeof( *X ) );
      z->a = 1;
      z->b = 2;

      Complaining that you can't do the equiv of struct{ ... } a,b,c is really petty. 3 (java) new statements won't kill you. :P

      --

      --
      "I'm not bright. Big words confuse me. But Wanda loves me and that should be enough for you." - Cosmo

    5. Re:From the article by X · · Score: 3, Insightful
      You need to bone up on your Java, and perhaps your C++.
      1. In C++, in terms of writing effort, a class and a struct are the same
      2. In Java, you can have multiple classes in a single file. Indeed, the compiler could care less, just like in C++.
      3. You can compile Java code to binary, indeed you can do so with gcc.
      4. Try benchmarking Java vs. Python some day. You'll discover that aside from start up time, Java outperforms Python in the majority of cases.
      This is the C++ code for a class:
      class Foo {
      public:
      int bar;
      int baz;
      };
      This is the C++ code for the equivalent struct:
      struct Foo {
      int bar;
      int baz;
      };
      This is the Java code for the equivalent class:
      class Foo {
      public int bar;
      public int baz;
      }
      Not a lot of difference is there?
      --
      sigs are a waste of space
    6. Re:From the article by Anonymous Coward · · Score: 2, Informative

      I suppose he could be talking about Psyco, the Python JIT module. I haven't used it yet, but I hear good things.

    7. Re:From the article by MoP030 · · Score: 1

      i suggest you want to malloc(sizeof(X)). though it might work if you have 64bit pointers and 32bit ints.

      --
      the most sexp i get is my paren-mode.
    8. Re:From the article by ct.smith · · Score: 1

      I think you've missed the point here. It's not about counting lines of code or how many files are needed; it's about using the most appropriate representation without extra overhead. The point is that Java forces OO where it's not always needed.

      First, the better bit of C++ code to compare against is:

      struct X {int a, b;} z;
      z.a = 1;
      z.b = 2;

      Note that this does not require a class, dynamic allocation, nor the horrible style of C-syntax that you chose. But really that is all beside the point.

      I'll repeat, the point is that java forces you into OO when it's not always needed.

      --
      ** Sig-a-licious **
    9. Re:From the article by joss · · Score: 1

      He has a point though... if you want this structure [ie class only containing public data members] to be available to two classes you do need to create a whole file for it in java. This happens quite while in C++ one could add a strut to a .h file or even better just return pair or whatever

      --
      http://rareformnewmedia.com/
    10. Re:From the article by Angst+Badger · · Score: 4, Insightful

      I find that nearly everyone who criticizes [INSERT LANGUAGE HERE] is either using an ancient implementation ... or they simply haven't explored the language fully.

      This is an excellent template for recognizing language bigotry. Try this as a template for recognizing language agnosticism:

      "I can enumerate dozens of less-than-perfect features in my favorite language."

      Until you understand the weaknesses as well as the strengths of your favorite language, you either haven't explored it fully or you don't know enough languages well enough to have a basis for comparison. (C|C++|Java|Perl|AWK|Python|COBOL|RPG|Fortran|BASI C|PHP|Forth|6502 Assembly|Forth) all suck if you're only looking at their flaws, and they all rock if you're only looking at their strengths. If you're not looking at both, you're not getting it.

      --
      Proud member of the Weirdo-American community.
    11. Re:From the article by the+uNF+cola · · Score: 1

      The diff between an object and a struct is the type of data you associate with it. Hell, you can accomplish w/ a struct, the same stuff as an object. You are also assuming that the JVM isnt' smart enough to figure, hey, "this isn't using polymorphism, don't check". The only diff between OOP and functional programming is that in oop, you can associate data with a library, but then again, java's math lib is like that. you don't instanciate it, you jsut pass it params... so while you are more likely to use Java in an OO fashion, you don't have to.

      --

      --
      "I'm not bright. Big words confuse me. But Wanda loves me and that should be enough for you." - Cosmo

    12. Re:From the article by nado · · Score: 1

      That's why people get better tools, such as Eclipse.

    13. Re:From the article by imbaczek · · Score: 1

      Try benchmarking Java vs. Python some day. You'll discover that aside from start up time, Java outperforms Python in the majority of cases.

      So what? It still is slower than C, so that's what you use for time-critical parts. Then use some Python glue and voila. Alternatively, you can get some near-Java (or even near-C! though rarely) performance out of pure Python with Psyco.

      Besides, Python is so much more programmer friendly, so why not use it?

    14. Re:From the article by jhunsake · · Score: 1

      You forgot your transitive closure. :)

    15. Re:From the article by jhunsake · · Score: 1

      I'm supposing you meant imperative programming, not functional programming, but anyways OOP is orthogonal to both:

      Functional, OOP: OCaml
      Functional, not OOP: ML
      Imperative, OOP: Java
      Imperative, not OOP: C

      Not that you can't simulate OOP in any language....

    16. Re:From the article by jcbphi · · Score: 2, Informative

      These are some of the many reasons why Python is my language-of-choice, and why I don't program much in Java (my first programming language!). However, I should point out that what pops out is not super efficient C, but rather reasonably efficient compiled byte-code. Its nice, but python is rarely as fast as I'd sometimes like it to be.

      But that's a story for another day...

      Cheers,
      J

    17. Re:From the article by ashultz · · Score: 1


      You could just make an inner class with only data members. It would probably take you two more lines than it would to make a struct. You can make it private or make it public and use it in other classes.

      But really, making a whole file isn't that hard either - you copy some other file and then change the innards. Done. You don't have to write get/set, you can just have accessible data members.

      -andy

    18. Re:From the article by Anonymous Coward · · Score: 0

      > If you make all the data/ fields in the class public and have no methods, then what you have a struct.

      Nope; what you have is a class derived from Object that has public data and no declared methods. Check out the javadoc for java.lang.Object to see all the ones you've just inheirited by default.

      This is very different from a C/C++ struct that has only the data members you've declared, and none other.

    19. Re:From the article by jilles · · Score: 1

      This whole debate is based on the assumption that the way Java does things is bad because it does things the OO way. In truth, if you treat a class like a struct, a good JVM will do so as well (i.e. there is no real performance penalty when the runtime optimization kicks in).

      The whole point of Java (and similar programming languages) is that you let the runtime environment figure out how to optimize and write clean code instead. Then once you find that you have performance problems, you locate the problems (e.g. using a profiler or a debugger) and solve them. That's a different way of working than in C or C++. But different is not necessarily bad IMHO.

      Basically when a Java programmer writes a class it is because the added level of abstraction is somehow convenient for him. Structs do not provide much added convenience (over inner-classes), so Java does not have them.

      --

      Jilles
    20. Re:From the article by Bodrius · · Score: 1

      Funny. Although I too would like to use a structure every once in a while in Java, I fail to see the lot of extra code or the outstanding convenience of C++.

      I very often encapsulate the data variables I'm dealing with, if they are complex and interrelated, into a custom data structure in Java... This takes all the effort of:

      final class SillyClassThatIsReallyAStruct {
      public type var1;
      public type var2; .... etc...
      }

      The only reason I would like a struct in Java is to avoid the constructor invocation and implying garbage collection when using those data structures. But really, there is no extra work here, unless a couple extra characters per keyword bother you immensely.

      Since they are normally data structures of use only for my package, I can put them all in a single file or, even better, inside the only class that uses it.

      If the data structure is so useful and important that it should be made public and shared with the rest of the world, then by all means give it its own .java file.

      I agree wholeheartedly with Stroustrup's advice. But that's not a Java/C++ issue, that's a programmer issue:

      The only kind of idiot who's going to implement getters/setters for a data structure with no behavior IF there is no need, is the same kind of idiot who will do it in either Java or C++.

      On the other hand, good Java developers often tend to be very careful about making sure there is really no behavior in this data structure (and therefore is not an object). And specially about imposing such assumptions on the rest of the world that uses the data structure (which is I am skeptic about making any such structs public).

      --
      Freedom is the freedom to say 2+2=4, everything else follows...
    21. Re:From the article by Anonymous Coward · · Score: 0

      > This is very different from a C/C++ struct that has only the data members you've declared, and none other.

      I agree that it is different. Whether it is very different or not depends on whether you are talking about C or C++ (there's no such language as C/C++). In C++ the entity that is introduced by the struct keyword is in fact a class. It has constructors, destructors and (at least one) assignment operator. It might or might not have additional member functions (virtual or otherwise) that you write. It doesn't automatically derived from Object (or anything) but it can in fact derive from another class if you decide to do that. The only difference (compared with the class keyword) is the default access control of the (member or base class) subobjects.

      Getting back to the interview, I thought this section was a bit confused. First he starts out defending the use of structs by giving an example. Then he goes on to show that as things get more complex you start to discover a deeper abstraction with some invariants that need to be enforced. So, you end up with a class in the end. So, where is the supposed "abuse" of OO?

      The point is in the (or at least my perception of the) real world you get this all the time.

      Python was mentioned elsewhere. I agree that one of the fun things about Python is that you can go out and create a big procedural mess and go back later, find the abstractions and clean things up. But I think that's just because I haven't graduated to the level where I see the abstractions right off the bat. And I always put a "# This is a procedural mess..." comment at the top.

      Just some thoughts...

    22. Re:From the article by Anonymous+Brave+Guy · · Score: 1
      How are you getting super efficient C code from your python programs?

      Maybe he's writing the performance-critical parts in C, writing the main part of the code in the higher level language, and linking the two? This is a fairly standard approach to the performance problem, and works well enough provided you have the resource to use two languages and there's a decent interface available between them (which, when one of them is C, is almost always the case).

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    23. Re:From the article by Eryq · · Score: 1

      No, you don't need another file.

      Just declare the inner class "public" and "static", and any other class will be able to use it exactly as if it were in its own file.

      For class "Inner" inside of class "com.xyz.Outer", the full class name is "com.xyz.Outer.Inner" - just as if it were in its own package.

      Easy as C++... easier, in fact, since you don't need the separate .h file.

      --
      I'm a bloodsucking fiend! Look at my outfit!
    24. Re:From the article by Brandybuck · · Score: 1

      Oooooh! You dissed Java. Uuuugh! You mean person you! Rrrrrh it makes me so angry! I just want to slap you for that. Never ever ever ever say anything bad about Java. You nincompoop. Java is pristine, perfect, epiphanal. Java is my religion, my life, the air I breath. Nnnngrh. Only a toadnosed neanderthal would ever say anything bad about Java. Weaselhead, ratmouth, ignorant philistine stoat! Aaarghnnggrh...

      [...loud messy explosion as one more javaboy messily ceases to be...]

      --
      Don't blame me, I didn't vote for either of them!
    25. Re:From the article by stonecypher · · Score: 1

      You fool, 6502 assembly has no weaknesses!

      --
      StoneCypher is Full of BS
    26. Re:From the article by Anonymous Coward · · Score: 0

      Thank You! This is the number one java peeve. Every time I just want to make a structure I've got to make a whole class. That's a whole file. That's a whole lot of extra code.

      Foo.java:
      class Bar { public int quux; }
      public class Foo { blabla }

    27. Re:From the article by angel'o'sphere · · Score: 1
      This is wrong.

      In several ways even.

      In C++:
      struct Flat {
      int size;
      float d;
      };
      and in Java:
      class Flat {
      int size;
      float d;
      }
      I admit, the semantics is not "exact" the same, but close enough.
      Nearly everywhere where you can write a struct in C/C++, you can write that Java class as well.
      You can do it in the same file, in a seperate file, inside of a class nested ...

      Of course, to be EXACTLY equivialent you would need to use your own file and to write this:
      <i>public</i> class Flat {
      <i>public</i> int size;
      <i>public</i> float d;
      }
      The difference between Java and Python is only syntax and the libraries .... well, generators probably are a noteable difference.

      I would say: if you have trouble to write Java as you like to write C++, you either don't know Java well or C++ or even both.

      angel'o'sphere
      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    28. Re:From the article by nagora · · Score: 1
      You fool, 6502 assembly has no weaknesses!

      Yeah, who needs registers? Z80 rules!

      TWW

      --
      "Encyclopedia" is to "Wikipedia" what "Library" is to "Some people at a bus stop"
    29. Re:From the article by pyrrho · · Score: 1

      >(there's no such language as C/C++)

      Yes there is. The C paradigm is totally legal in C++.

      When you see a hello world benchmark and the code uses the stream classes, that C++.

      When you see a hello world benchmark and the C++ sample used printf(..), that's C/C++.

      --

      -pyrrho

    30. Re:From the article by AlXtreme · · Score: 1
      When that deadline is just 24 hours off, it all comes down to either having good (ie. working, fast and neatly written) code or having a pile of rubbish in need of a serious rewrite. A customer / your users couldn't care less if you use C# or COBOL. You're perfectly right in that to get there, you need to exploit the strengths and make up for the weaknesses of your programming language. Only then do you have a chance in getting some sleep in the next 24 hours.

      Don't count on it though

      --
      This sig is intentionally left blank
    31. Re:From the article by 2short · · Score: 1

      "In C++ the entity that is introduced by the struct keyword is in fact a class."

      Yes. Technically class and struct differ only by default access type. Traditionally, they are used somewhat differently, but everyone has slightly different (though similar) rules about which to use. (Mine: structs have naught but public data members, classes are everything else, but the presence of any public data members in a class is discouraged)

      "It has constructors, destructors and (at least one) assignment operator."

      No. Unless you're saying "int" has a constructor and a destructor because it allocates memory when declared and frees it when it goes out of scope. But that's not the typical sense of constructor/destructor.

      struct Foo { int Bar; };
      no more has a constructor/destructor than "int" does. And it doesn't have an assignment operator at all, while "int" has a pile of them.

      "Getting back to the interview, I thought this section was a bit confused. First he starts out defending the use of structs by giving an example. Then he goes on to show that as things get more complex you start to discover a deeper abstraction with some invariants that need to be enforced. So, you end up with a class in the end. So, where is the supposed 'abuse' of OO?"

      The abuse of OO is using a class right off the bat every time. You might well go to a class (and should) when things become more complex, but a lot of the time, things don't get any more complex. One key to good C++ (or OOP in general) is to keep the simple stuff simple. You can throw 10 levels of abstraction onto HelloWord if you want, but you shouldn't. You should save it for when it's needed.

    32. Re:From the article by 2short · · Score: 1

      "Easy as C++... easier, in fact, since you don't need the separate .h file"

      Who needs a seperate .h file? In C++, I can put whatever I want in whatever files I want.

      So let's imagine I have three classes, two of which are unrelated except that they both use the third. In Java, what are my choices for how many files to put them in, assuming some particular division makes the most sense to me? (This isn't rhetorical, I really don't know) In C++ the answer would be "1 or more files".

    33. Re:From the article by 2short · · Score: 1

      "But really, there is no extra work here, unless a couple extra characters per keyword bother you immensely."

      Not at all, but the aforementioned "constructor invocation and implying garbage collection" bug the hell out of me. I realise and agree that in the vast majority of applications, it's not a big deal. But I deal with at least a few situations where it is a big deal. And in that vast majority of situations where it just doesn't make enough difference to remotely matter... It still bugs the hell out of me :)

    34. Re:From the article by sohp · · Score: 1
      Every time I just want to make a structure I've got to make a whole class.
      Translation: Every time I just want to hack some old thing out based on my limited understanding, I'm forced to think about what I'm doing and learn something new, which I stubbornly refuse to do.
    35. Re:From the article by tpv · · Score: 1

      But does Forth suck twice as much as the others?

      --
      Read more of this story at Slashdot.Read more of this story at Slashdot.Read more of this story at Slashdot.
    36. Re:From the article by Usquebaugh · · Score: 1

      Trying simulating with ANSI-74 COBOL.

    37. Re:From the article by jhunsake · · Score: 1

      I did that, last night.

    38. Re:From the article by criquet · · Score: 1

      I somehow deleted a few key words from my conclusions which should have stated:

      "then what you have is basically a struct."

      Meaning that this class in Java can be used just as a struct is used in C++.

      My point was primarily targeting the quote from the original parent "I've got to make a whole class". Yes, you have to define a whole class, but that class is no more complicated to define than a struct in C++. That is, all you define are the fields. You don't define any methods. This class and struct are used in the same way as well.

      So if they are defined similarly and used the same they are basically the same. Certainly if you want to get into the semantic differences of the languages they're certainly different but then that's why C++ and Java are different languages isn't it.

    39. Re:From the article by DrVxD · · Score: 1

      struct Foo { int Bar; };
      no more has a constructor/destructor than "int" does. And it doesn't have an assignment operator at all, while "int" has a pile of them


      Sure Foo has an assignment operator. It's perfectly fine to write:


      Foo a = { 1 }; // this isn't a ctor, it's aggregate initialisation
      Foo b;
      b = a; // assignment - b.Bar now = 1

      That's the way it works in C, too (which is at least part of the reason that C++ gives you the default memberwise assigment operator "for free")

      It even has a copy constructor ...


      Foo a = { 2 };
      Foo b( a ); // copy construct - b.Bar now = 2


      The fact that you didn't write these operations don't mean they don't exist.

      Technically, Foo also has a default implicitly declared default constructor - see ISO/IEC 14882:2003 section 12.1 for details. It just doesn't do much (which is why it's called a trivial constructor). The same applies to the destrictor (section 12.4 of the same document)

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
  21. Re:Who is Bjarne Stroustrup? by Worminater · · Score: 1

    Real programming class?

    MOV AX, @DATA
    LEA BX, DSARY
    INC BX, 02
    MOV AX, BNDMP
    MOV CX, 10
    BRD:
    MOV [BX],AX
    MOV AX, BNDMP
    INC BX, 02
    LOOP BRD


    and your talkign about a REAL programming language?

    Hardy har har...

    I prefer
    for(int x = 0, x=11, x++)
    {
    dsarray[x] = bndmp;
    }

    myself...

  22. Re:Why did they need to interview bjarne about tha by deadlinegrunt · · Score: 2, Insightful

    All he did was complain about over and under object-orienting c++ code. Not sure why that's useful... My Computer Science professors do that all the time.

    Being that there is a large codebase out there that breaks either one of these rules I would venture a guess that is why he commented on it. He does not believe that there is a sliver bullet to solving software problems nor does he believe that C++ is one either. It is just a language he designed to solve problems he encountered while programming.

    C++ is not object oriented. It has OOP support but does not mandate it. The other extreme is that it is not C. If you find yourself falling to one of these extremes in *EVERY* coding probem then there is a high probability you just might have missed his point.

    --
    BSD is designed. Linux is grown. C++ libs
  23. say what? by mschoolbus · · Score: 1

    ...and getting maximum from a language.

    Like English?

  24. Re:OOP IS FOR PUSSIES by BurKaZoiD · · Score: 2, Funny

    Real men code in assembler

    Since when did Steve Gibson start posting here as an Anonymous Coward?

    Some people use a screwdriver, others use a butter knife. That's the beauty of programming; there are numerous tools and technologies at your disposal that will all achieve the effect (or at the very least, a semblance of the effect) you desire. Business users typically don't know the difference anyway, so it's really a matter of programmer's preference. Pick those you feel most appropriate to your project, and leave the rest.

    Most people I know don't get the beauty of something like C++. It's a massively complex language. So complex, as a matter of fact, that you can create OTHER languages with it (via templates). But, like any other, tool or technology, take what you want from C++, and leave the rest behind.

  25. How OOP helps reusability. by Rimbo · · Score: 1

    Probably the main reason OOP exists is that it provides a mechanism by which new code can be added to old code, without having to dig into the old code to find just the right spot to make the function call to the new code.

    See, in your assembly language, if you want to add new code, you have to not only write the new code, you have to dig through your Asm to find the little tiny spot where you JSR (or whatever your opcode may be) to the new code.

    In my C++/Java, I just subclass that puppy when I write the new code, and my code gets called automagically. (Well, actually via a dynamic function call table, but you knew that.)

    It doesn't help so much on a small, one-man project. But once you have more than one person and more than a thousand or so lines of code, suddenly OOP gets really, really useful.

    1. Re:How OOP helps reusability. by Anonymous Coward · · Score: 0

      How do you think that dynamic function call table works? That 'automagic' happens to simply be a jump table. A common assembly language technique developed long, long before oop was a catch phrase.

    2. Re:How OOP helps reusability. by Rimbo · · Score: 1
      How do you think that dynamic function call table works? That 'automagic' happens to simply be a jump table. A common assembly language technique developed long, long before oop was a catch phrase.


      I know how it works. The point is that Smalltalk/C++/Java/etc provide language-level support for it, so that you don't have to reinvent the wheel every single time you want to do dynamic function calling. It also implements protection mechanisms so that if someone does something that would otherwise violate an invariant, the compiler lets him know right away. One such invariant would be calling function_table[7]() when there are only 4 functions in the table. An assembler can't check for this sort of error.
  26. Weird guy by the+uNF+cola · · Score: 2, Informative

    I went to one of this guy's conferences on C++. I thought it'd be more in depth, but it was merely introduction to the features of C++. It does this, it does that. Neat libs like boost and the stl. Also has ACE libs for cross compatability

    Well, as one may expect, someone asked about java. He got very biligerant and brief about it. "C++ is supported on N many more platforms than java." (Can't remember N). It was also the last question too, which left that "weird" sense in my mind's eye.

    --

    --
    "I'm not bright. Big words confuse me. But Wanda loves me and that should be enough for you." - Cosmo

    1. Re:Weird guy by kraut · · Score: 2, Insightful

      Funnily enough, I've met him a few times at accu (http://www.accu.org/) conferences and had really interesting discussions with him.

      He's certainly no weirder than most other programmers I know, if you make allowances for him being Danish ;) And you have to make some allowances for being annoyed about Java: He developed a systems programming language that allows you to use OO; then everyone jumped onto the bandwagon and wrote crap programs in it (think monkeys with powertools), and then someone comes up with an application level programming language that's much safer for monkeys to handle (i.e. Java), and everyone asks "didn't you really want to design Java?".

      Duh. He may be mild mannered, but that must get irritating after a couple of years.

      --
      no taxation without representation!
    2. Re:Weird guy by the+uNF+cola · · Score: 1

      But at a conference? I get my name mispronounced by everyone, which is by far, more personal, but I don't get snippy when it gets misprounced. I get happy when people pronounce it right :) Can't he be happy people do use it? He's prolly gotten further than most program language developers ever have.

      --

      --
      "I'm not bright. Big words confuse me. But Wanda loves me and that should be enough for you." - Cosmo

    3. Re:Weird guy by kraut · · Score: 1

      I feel your pain - I'm German, living first in the US, then the UK. When do you think I last heard someone proncounce my name correctly?

      At least he has a sense of humour about that:

      http://www.research.att.com/~bs/bs_faq.html#pron ou nce
      How do you pronounce "Bjarne Stroustrup?" ... The best suggestion I have heard yet was "start by saying it a few times in Norwegian, then stuff a potato down your throat and do it again :-)"

      --
      no taxation without representation!
  27. the article, page 1 of 4 by asdfghjklqwertyuiop · · Score: 0, Redundant
    Climbing above C-level


    Bill Venners: In an interview, you said, "The C++ community has yet to
    internalize the facilities offered by standard C++. By reconsidering the style of C++ use,
    major improvements in ease of writing, correctness, maintainability, and efficiency can
    be obtained." How should C++ programmers reconsider their style of C++ use?


    Bjarne Stroustrup: It's always easier to say what not to do, rather than what to
    do, so I'll start that way. A lot of people see C++ as C with a few bits and pieces added.
    They write code with a lot of arrays and pointers. They tend to use new
    the way they used malloc. Basically, the abstraction level is low. Writing
    C-style code is one way to get into C++, but it's not using C++ really well.


    I think a better way of approaching C++ is to use some of the standard library facilities.
    For example, use a vector rather than an array. A vector knows its size. An array does
    not. You can extend a vector's size implicitly or explicitly.
    To get an array of a different size, you must explicity deal with
    memory using realloc, malloc, memcpy, etc.
    Also, use inline
    functions rather than macros, so you don't get into the macro problems. Use a C++ string

    class rather than manipulating C strings directly. And if you've got a lot of casts in the
    code, there's something wrong. You have dropped from the level of types, a high level of
    abstraction, down to a level of bits and bytes. You shouldn't do that very often.


    To get out of writing low level code, you needn't start writing a lot of classes. Instead,
    start using facilities provided in libraries. The standard library os the first and most
    obvious source, but there are also good libraries for things like math or systems
    programming. You don't have to do threading at the C level. You can use a C++
    threading library. There are quite a few of them. If you want callbacks, don't use just
    plain C functions. Get libc++, and you'll have a proper library that deals with
    callbackscallback classes, slots and signals, that kind of stuff. It's available.
    It's conceptually closer to what you're thinking about anyway. And you don't have to mess
    with error prone details.


    Most of these techniques are criticized unfairly for being inefficient. The assumption is
    that if it is elegant, if it is higher level, it must be slow. It could be slow in a few cases, so
    deal with those few cases at the lower level, but start at a higher level. In some cases, you
    simply don't have the overhead. For example, vectors really are as fast as arrays.

  28. Invariants and Design by Contract by LeonardShelby · · Score: 1


    He's discussing class invariants, and how they help one design interfaces, and how they must be maintained. But he's refused to put that into C++! For years he'd been asked about adding some form of contracting to the language, but he'd always come back with how that's not needed. (I always thought part of it was due to his hatred of Bertrand Meyer (of Eiffel fame)).

    Has he now seen the error of his ways? Is contracting (in any form other than assert) going to get added to C++?

    --
    remember Sammy Jankis
    1. Re:Invariants and Design by Contract by X · · Score: 1
      Has he now seen the error of his ways? Is contracting (in any form other than an assert) going to get added to C++?
      No, the kind of invariants he's talking about are already there. The STL is built around a whole host of invariants. All that C++ lacked was a user friendly way of expressing these invariants. Some of the work the Boost folk have done has provided standard libraries for expressing this stuff more clearly, using the language as-is. Nothing wrong with his ways, and nothing need be added.
      --
      sigs are a waste of space
    2. Re:Invariants and Design by Contract by Hugh+George+Asm · · Score: 1
      He's discussing class invariants, and how they help one design interfaces, and how they must be maintained. But he's refused to put that into C++!

      He doesn't refuse. (He isn't the whole committee anyway.) He does oppose adding features that will have overhead on classes that don't use them, and is against changing the core language in ways that could break backwards compatibility.

      If you want invariants, I don't see your proposal before the committee. Why not? Rather than just ask vaguely for a feature, specify it. How would you go about this, meeting the above requirements? People are working on this and I have seen some proposals... but most are flawed in some way.

      If you can implement it in g++ as a reference implementation, that will give your proposal more weight as well. Is it really that important to you? If so then get to work.

    3. Re:Invariants and Design by Contract by LeonardShelby · · Score: 1


      He may not refuse, but he's been adamant that DbC isn't needed. That's where he's missing the point of DbC.

      And why isn't my proposal there? Because I don't like C++, I just use it at my work. I'm an Eiffel guy, which is where my outlook on DbC comes from. Once you go DbC, you don't like having to go back.

      It's worse on my current project at work, where it's obvious they've never heard of anything like placing the specification into the interface, and people are breaking class rules left and right because they're not sure what's what.

      Anyway, I'm just ranting.

      --
      remember Sammy Jankis
  29. the article, page 2 of 4 by asdfghjklqwertyuiop · · Score: 0, Redundant
    Object-Orientaphilia


    The other way people get into trouble is exactly the opposite. They believe that C++
    should be an extremely high level language, and everything should be object-oriented.
    They believe that you should do everything by creating a class as part of a class hierarchy
    with lots of virtual functions. This is the kind of thinking that's reflected in a language
    like Java for instance, but a lot of things don't fit into class hierarchies. An integer
    shouldn't be part of a class hierarchy. It doesn't need to. It costs you to put it there. And
    it's very hard to do elegantly.


    You can program with a lot of free-standing classes. If I want a complex number, I write
    a complex number. It doesn't have any virtual functions. It's not meant for derivation.
    You should use inheritance only when a class hierarchy makes sense from the point of
    view of your application, from your requirements. For a lot of graphics classes it makes
    perfect sense. The oldest example in the book is the shape example, which I borrowed
    from Simula. It makes sense to have a hierarchy of shapes or a hierarchy of windows,
    things like that. But for many other things you shouldn't plan for a hierarchy, because
    you're not going to need one.


    So you can start with much simpler abstractions. Again the standard library can provide
    some examples: vector, string, complex number. Don't go to hierarchies until you need
    them. Again, one indication that you've gone too far with class hierarchies is you have to
    write casts all the time, casting from base classes to derived classes. In really old C++,
    you would do it with a C style cast, which is unsafe. In more modern C++, you use a
    dynamic cast, which at least is safe. But still better design usually leads you to use casting
    only when you get objects in from outside your program. If you get an object through
    input, you may not know what it is until a bit later, and then you have to cast it to the
    right type.


    Bill Venners: What is the cost of going down either of those two paths, being to
    low-level or too enamored with object-orientation? What's the problem?


    Bjarne Stroustrup: The problem with the C way is that if you write code C-style,
    you get C-style problems. You will get buffer overflows. You will get pointer problems.
    And you will get hard to maintain code, because you're working at a very low level. So
    the cost is in development time and maintenance time.


    Going to the big class hierarchy is again, you write more code than you need to, and you
    get too much connection between different parts. I particularly dislike classes with a lot
    of get and set functions. That is often an indication that it shouldn't have been a class
    in the first place. It's just a data structure. And if it really is a data structure,
    make it a data structure.

  30. Borland!! by Seekerofknowledge · · Score: 1

    Borland C++ Builder 5.0 has an ANSI compliant compiler, including STL support. I'm sure 6.0 also does.

    I remember that it was such a big deal that it was advertised on the box. Check it out.

    1. Re:Borland!! by yamla · · Score: 1

      The page you list interested me when I first saw it. I emailed Borland and asked if they were fully compliant with the latest ANSI C++ standards. They replied back stating they were not. They were in the high-90 percents but were not at 100%. Note that the web page does not state their compiler is fully ANSI-compliant, either.

      --

      Oceania has always been at war with Eastasia.
  31. Re:OOP IS FOR PUSSIES by Viol8 · · Score: 1

    Even though the original post was a troll , as someone who has coded in assmbler all the way up to C++ and other assorted languages (OO and functional)
    I'm afraid that assembler IS for real programmers. Why? Because to do anything complex in it is DAMN hard and not only do you have to understand what data structures you require
    (the abstraction) but you have to understand how to map them down efficiently in a way the computer architecture can handle. I'm sorry , but writing even complex C++ is like a walk in the park compared to writing a complex assembler program , especially if its on a RISC CPU or god forbid a parallel architecture such as a Transputer (ok , they're long defunct but you get the point).

  32. Vector not checked for overflow? yes and no by dmh20002 · · Score: 1

    well, you do have to know what you are doing, but the standard says:
    vector::at
    const_reference at(size_type off) const;
    reference at(size_type off);
    The member function returns a reference to the element of the controlled sequence at position off. If that position is invalid, the function throws an object of class out_of_range. That is just like Java. the code will look the same.
    BUT
    the if you use the '[]' operator with an out of range index, then the behavior is undefined. so it becomes an implementation dependent thing in this case. So its best to avoid depending on [] for portability sake.

  33. Re:Who is Bjarne Stroustrup? by Anonymous Coward · · Score: 0

    He's also the inventor of the "Jump to Conclusions" mat that was widely advertised on TV during the 1980s.

  34. Invariant/struct discussions and binary compatibil by tjansen · · Score: 2, Interesting

    Stroustrup and the interviewer miss one important point in the class vs. struct and invariant discussion: binary compatibility. The reason why you should not access variables in structs/classes directly is not always that their representation may change. More often it happens that you need to add a member, but this is not possible without breaking binary compatibility (at least on the usual Linux/Unix compilers). So you need to use the private class/d-ptr pattern to hide at least future members from the public class. This does not break apps that use the class members of earlier version, but it would make the API inconsistent, as the newer version would need to offer a different way of accessing the members. And the easiest one is to have get/set methods. So if you don't want to fall into the inconsistent API trap later, you should use get/set methods from the beginning. It's the only chance to have a consistent API over several evolving but still binary compatible versions.

  35. class exists iff there are invariants by Anonymous Coward · · Score: 0

    one thing which I thought was interesting was the assertion: "you should have a real class with an interface and a hidden representation if and only if you can consider an invariant for the class."

    That's very clear and succinct.

  36. Lean classes and supporting library by tjansen · · Score: 1

    >>Instead, if you build a relatively simple interface to a Date class, you might have five or ten member functions that are there because they are logically necessary. [..] Then you get these five or ten operations, and you can build the other 50 in a supporting library.

    I would disagree with that statement. While I can understand the concern (less dependence on data structures in the 50 methods), this creates an API that sucks. As a developer you want to have all helper functions for a data type at a single place. As the user of an IDE you want to see all available functions when you enter a variable with a given type. By spreading them into two or more places you increase the risk that somebody does not find them and reimplements them.

    1. Re:Lean classes and supporting library by X · · Score: 1

      Most C++ IDE's do a pretty good job of showing you the functions you can invoke on a type.

      Also keep in mind that nothing says that your Date functions have to be "spread all over the place". Indeed, it is quite logical to have calendar-type manipulations in one place, standard temporal operations in another, and formatting stuff idealling in a third place. Amazingly, this is actually what happens in the case of Java, despite the fact that it uses classes for all this stuff.

      --
      sigs are a waste of space
    2. Re:Lean classes and supporting library by William+Tanksley · · Score: 1

      this creates an API that sucks

      Ugh, no. The fewer functions in each class, the better the API looks and works cognitively.

      You can still keep all your API functions in one place -- a namespace, or a header file that includes the original class -- but if you cram them in the original class you're making it certain that 90% of the class will be useless to every programmer that uses it, and will therefore be a waste of cognitive effort. The wasted effort means that people will be reluctant to learn your API, and therefore it won't be used as much, thereby causing the EXACT problem you're trying to avoid.

      This is only the start of the problems. Next come the purely technical problems, like inheriting from gargantuan classes, or designing extensions which fit into the spirit of the class (C++'s own STL has at least one class that contains over 50 methods, many of them with oddly contradictory calling patterns). I won't go on ...

      -Billy

    3. Re:Lean classes and supporting library by pclminion · · Score: 1
      As a developer you want to have all helper functions for a data type at a single place.

      This is known as a "header file." Try opening one up in the editor sometime. You'll find that it contains a list of functions, along with their parameter types. These "header files" are usually fairly organized, with one file (or a set of closely related files) corresponding to a single API. Imagine that.

      As the user of an IDE you want to see all available functions when you enter a variable with a given type.

      You think it's a good idea to let the IDE drive the way you structure the code? "Yeah, I wrote the code this way because it causes the IDE to pop up a little yellow tooltip box when I type the name of this variable! Isn't that cute?!"

    4. Re:Lean classes and supporting library by tjansen · · Score: 1

      IMHO Java's Date classes went from simple and easy to use in Java 1.1 to completely horrible in >=1.2, with the introduction of Calendar, DateFormat and whatever those 10 classes are called. It's the prime example of bad API design in the sake of flexibility and correctness.
      Before the change you could learn in 1 minute how to create a daten given the (gregorian) year, month, and date. Just look on the Date JavaDocs, it was was obvious how to use it. After the change the time to learn went up to at least 10 minutes and complete confusion of most newbies.

    5. Re:Lean classes and supporting library by X · · Score: 1

      I don't disagree that things are more confusing in JDK 1.2, but I'd argue they came from a need to be backwards compatible with JDK 1.1. ;-)

      Seriously, even the name for the class "Date" is wrong in my opinion, as Date does imply a Calendar context, and formatting rules. The fact that Calendar's getTime() (not getDate()) returns an object of type Date is just crazy.

      These problems though are not related to the design decision. The fact that I could explain the design in one sentence is a pretty definitive example that the design itself is actually quite simple.

      --
      sigs are a waste of space
  37. Re:Highschool was... interesting with him. by Anonymous Coward · · Score: 0

    Yea those bitches were ruthless... and still are!!

  38. Re:Who is Bjarne Stroustrup? by Anonymous Coward · · Score: 0

    maybe ...

    for ( int x = 0; x != 11, x++ )

    ???

  39. I really don't like C++ by Anonymous Coward · · Score: 0

    I don't know a hell of a lot about C++, but from what I've seen, I hate it.

    There are multiple books written which may as well all be titled "How not to shoot yourself in the foot with C++", more books of this type than I have seen for any other language. The language brings some tools to help the programmer, but it brings far far more ways for the programmer to screw up.

    And ever tried reading someone else's C++ code? The language makes so many things implicit that understading the code can be pretty challenging compared to understanding an equivalent C program.

    If you're _writing_ a C++ program, and you've been doing it awhile, I'm sure all that implictness that comes with inheritance, etc. is a good thing, but when you're trying to _read_ the code, it makes for trouble. It is often very hard to understand just a piece of a C++ program. You have to understand a whole class hierarchy and all sorts of interrelationships in the code before you can begin to make more than the most trivial of changes. Most C programs I've seen, perhaps because they are less "tightly" designed, are more amenable to being modified sensibly by someone who doesn't have a complete understanding of the entire million lines of code in question.

    Just my experience, C++ is a good thing for initial code writability, but it is a bad thing for code maintenance purposes. You're mileage may vary.

    1. Re:I really don't like C++ by elflord · · Score: 1
      I don't know a hell of a lot about C++, but from what I've seen, I hate it.

      Then shut up until you do know something about it.

      There are multiple books written which may as well all be titled "How not to shoot yourself in the foot with C++", more books of this type than I have seen for any other language.

      C++ is a big language. There are a lot of books. Perhaps you should read some of them.

      And ever tried reading someone else's C++ code?

      Yep.

      The language makes so many things implicit that understading the code can be pretty challenging compared to understanding an equivalent C program

      Especially if you don't know C++. Likewise, Chinese is worse than English because I can't read Chinese.

      but when you're trying to _read_ the code, it makes for trouble

      Only if you don't understand the language.

      Just my experience,

      Which, by your own admission, is minimal.

  40. MOD UP by Anonymous Coward · · Score: 0

    You can't improve a language by telling people how to program with it.

    This koan is worthy of a "Programming Pearl" entry. If only it had come to Bjarne rather than some random Slashdot user, the C++ programming world would be a much better place in which to live and work today.

  41. C++ Programming Language by happyfrogcow · · Score: 2, Funny

    I've always liked C++. After reading about half (still working on the rest of it) of "The C++ Programming Language" by Bjarne, I've learned so much about what good C++ programming is about. During University, the C++ class I took covered so little. It was basically a C course except we implemented yet another string class. This book is great. Bjarne comes across as a really smart and logical person. The last few chapters about design are great. I skipped up to them after reading the first 2 sections or so. I love reading interviews of him and things he's written. Everytime I work on a personal project I try to add another idea he presents to my own work.

    I seriously enjoy programming in C++.

    1. Re:C++ Programming Language by Anonymous Coward · · Score: 0
      last few chapters about design are great.

      If you ever meet him ask about how well cfront is going. The rewrite was real swell.

  42. Great, modern advice. by Anonymous Coward · · Score: 0

    Bjarne: "You oughta use vectors rather than arrays."

    Thanks for the tip dude. Now I will finally take advantage of this cutting edge technology that C++ provides.

    1. Re:Great, modern advice. by thanuk · · Score: 1

      If more people took this advice there'd be a lot less buffer overruns in this world

  43. Inheritance abuse by e-Motion · · Score: 1

    I've been preaching this song for the better part of 20 years. But people got very keen on putting everything in classes and hierarchies. I've seen the Date problem solved by having a base class Date with some operations on it and the data protected, with utility functions provided by deriving a new class and adding the utility functions. You get really messy systems like that, and there's no reason for having the utility functions in derived classes. You want the utility functions to the side so you can combine them freely. How else to I get your utility functions and my utility functions also? The utility functions you wrote are independent from the ones I wrote, and so they should be independent in the code. If I derive from class Date, and you derive from class Date, a third person won't be able to easily use both of our utility functions, because we have built dependencies in that didn't need to be there. So you can overdo this class hierarchy stuff.

    Bjarne talks about this problem a little in his book (TC++PL), but I'm glad that he mentioned it here. Putting utility functions in derived classes is a mistake that is made far too often. How many times have you seen someone write something like this:

    class MyString : public std::string {
    public:
    size_type find_no_case(const char *subStr) const; // ...
    };

    Stop it! That should be a free-standing function. There is absolutely no benefit to using inheritance in the above code. The only thing it yields is a warm fuzzy feeling from using member functions instead of free-standing functions. Some coders just enjoy writing

    MyString s("foobar");
    i = s.find_no_case("foo");

    instead of

    std::string s("foobar");
    i = find_no_case(s,"foo");

    because it "feels right", even though it limits the reusability of the function. C++ programmers, please take note. It is a mistake that even book authors like Steve Heller make (Link)

    1. Re:Inheritance abuse by elflord · · Score: 1
      It is a mistake that even book authors like Steve Heller make (Link)

      I thought Heller's "mistake" was defensible even if you don't agree with it. Heller's goal was to provide a string class that would be usable and not too confusing for beginners. I don't think there is any perfect solution to the problem he was trying to solve.

    2. Re:Inheritance abuse by e-Motion · · Score: 1

      I thought Heller's "mistake" was defensible even if you don't agree with it. Heller's goal was to provide a string class that would be usable and not too confusing for beginners. I don't think there is any perfect solution to the problem he was trying to solve.

      I didn't get the impression that he realized that his class was a poor design decision. If he realized this, then that's good. Even so, I don't see how a beginner could be confused by string utility functions. Functions are (arguably) simpler than classes.

  44. Just use an inner class by Baki · · Score: 1
    If you want to save an extra file:

    class X { // "real class" using // some datastructure Y

    static class Y {
    type1 field1;
    type2 field2;
    }
    }

  45. Mandatory Dialectizer Link by Anonymous Coward · · Score: 0

    A little background information would be useful. For all I know, he could be the Swedish Chef on the Muppets.

    Bjarne Stroustroup in "Swedish."

    Since the site is Slashdotted, here's a quote from the translated interview:

    Zee prublem veet zee C vey is thet iff yuoo vreete-a cude-a C-style-a, yuoo get C-style-a prublems. Um gesh dee bork, bork! Yuoo veell get booffffer ooferffloos. Yuoo veell get pueenter prublems. Und yuoo veell get herd tu meeentein cude-a, becoose-a yuoo're-a vurkeeng et a fery loo lefel. Su zee cust is in defelupment teeme-a und meeentenunce-a teeme-a.
  46. Re:OOP IS FOR PUSSIES by Anonymous Coward · · Score: 0

    You can fake OOP - you just get a bad design...it'll still work, it'll just be crappy. If you attempt to fake assembler, the machines goes down.

    VB supports OOP, BTW.

    > Obviously many self-proclaimed C++ programmers
    > belong in the assembler group

    I think it's more "90% of Java developers belong in the crappy OOP group," which is way worse in my opinion.

  47. The real trouble with C++ by Animats · · Score: 3, Insightful
    C++ suffers from the same problem that killed Pascal - its creator thinks everything is just fine, yet people are deserting it because it has some major problems that the creator refuses to fix and everybody has to work around.

    We went through this with Wirth. Wirth devised Pascal, which had reasonable data structures, although not objects, terrible I/O, and strings that only worked if they were short. He then insisted that it shouldn't change. From this came a whole range of incompatible Pascal dialects (Turbo Pascal, Object Pascal, Clascal...), and some successor languages (Modula I, II, III). Modula III was actually rather good, but nobody except some researchers at DEC SRL (now an empty building in Palo Alto) used it. Two decades later, few use Pascal or its derivatives, and Wirth is a forgotten and bitter man in Switzerland.

    This cycle is being repeated with C++. The first version of C++, before templates and the STL, was terrible. Without templates, horrible schemes involving huge defines were used to make generic objects. Strostrup used to have great hostility to run-time type information, which led to unchecked downcasts all over the place.

    Round 2 of C++ came late, and it took a long time before the compilers did templates. Then came the STL, which is wierd and unsafe, although useful.

    C has little abstraction and little safety. Java has both abstraction and safety. C++ has abstraction without safety, a terrible combination. The basic problem with both C and C++ is that the language requires the programmer to obsess on storage allocation and release, yet gives no assistance in this. Attempts to encapsulate storage allocation in C++ fail miserably (look at the history of auto_ptr). Attempts have been made to fix the language by adding another layer of rote ritual ("patterns") on top of it, but compilers can't check that, so it doesn't reduce bugs.

    Another area of trouble comes from the history of C++ as a preprocessor for C. Bell Labs had a tradition that "you can't change the linker". (This is probably because the original UNIX linker was written in assembler and had few comments.) Because of this, some tasks that should be deferred to link time (such as building vtables) are done at compile time.

    The price paid for not changing the linker is substantial. Private function members appear in header files so that vtables can be built at compile time. That's the real reason, despite what you read. If it weren't for that, you could have much stronger separation between declaration and implementation. And you wouldn't be recompiling class users just because the class implementation changed. Ada and Modula got this right, but C++ got it wrong. And Strostrup refuses to fix it.

    Yes, there are "patterns" for working around this. But they're workarounds. The programmer is doing the compiler's job. This imposes a cost on every programmer and distorts C++ programs.

    Strostrup still insists there's nothing really wrong with his language. Read what he's written about the C++200x standards revision cycle. Meanwhile, C++ is being abandoned for Java, C#, C, and scripting languages.

    1. Re:The real trouble with C++ by occamboy · · Score: 1

      I agree with everything you say about C++. On the the Pascal side, however, I believe that fixing the language was necessary but not sufficient; witness Borland's Delphi, which features Object Pascal, a superb dialect of Pascal. For something like six years Delphi/Object Pascal was unmatched by anything in the Windows arena - nothing was even close - but it did not take over the world. Now that Delphi is essentially matched by C#/VB.NET, I suspect that Delphi's days are, sadly, numbered.

      I guess the point is that most users are unable to determine what's good and what's not.

    2. Re:The real trouble with C++ by Animats · · Score: 1
      For something like six years Delphi/Object Pascal was unmatched by anything in the Windows arena - nothing was even close - but it did not take over the world.

      That's more of a Borland problem than a language problem. No single-vendor language has ever gone very far. Even Java and C# are open enough that others can write compilers for them.

    3. Re:The real trouble with C++ by iggymanz · · Score: 1

      the programmer is doing the compiler's job

      yes, that's the core problem. But Java also has such problems (not as many, of course), which is why there are some people use template preprocessors (for compile time polymorphism and strong typing) and proposed solutions to problems of containers having to deal with basic types and objects.

    4. Re:The real trouble with C++ by Ed+Avis · · Score: 1

      What makes you so sure that 'Stroustrup refuses to fix X'? C++ has been through a lot of changes since its beginning, most of them initiated by Stroustrup. What makes you think that he'd want to fix the language in stone now when he's shown no sign of doing so in the past?

      More likely is that the standards committee is waiting for compilers to catch up to the _current_ standard before making new ones :-(.

      'Read what he's written about the C++200x standards revision cycle.' OK, fair enough, you do have evidence. Got a link?

      'Meanwhile, C++ is being abandoned for...' - hmm, I can't help feeling I have heard this on Slashdot before. I don't think C++ will be Dying any time soon. Some places (I speak from experience) are migrating away from Java towards C++.

      --
      -- Ed Avis ed@membled.com
    5. Re:The real trouble with C++ by AtrN · · Score: 1

      By the time BS was doing C with Classes ld was in C (had been since v6). So he can't use that as an excuse :) But you're right, C++ would be quite different if he'd written a linker.

    6. Re:The real trouble with C++ by ChaosDiscord · · Score: 1
      The first version of C++, before templates and the STL, was terrible.

      It was so terrible that it had an amazingly fast adaptation rate and today has largely replaced it predecessor, C.

      The early versions of C++ had many faults, but it was largely backward compatible with C (a key element in convincing people to switch) while adding many features that were clear improvements to C (notably classes). It may suck (all languages suck), but it definately moving forward. Heck, if you all you get from C++ is basically C With Classes, life is still significantly better.

      Strostrup used to have great hostility to run-time type information, which led to unchecked downcasts all over the place.

      First, things changed. Now C++ has RTTI. It's old news. In fact, a number of your complaints are old news. It's odd to complain that Stroustrup is ignoring problems that have largely been solved for years.

      Second, if you're relying on RTTI "all over the place," you need to step back and seriously reconsider your design. Use of RTTI is one of those "Occasionally you really need it, but it probably means you have a design flaw" features.

      Attempts have been made to fix the language by adding another layer of rote ritual ("patterns") on top of it...

      The hell? Patterns aren't an attempt to magically fix C++. Heck, the definitative design patterns book points out that many of the patterns were originally found or codified in a variety of languages. Patterns are just a useful way of discussing common design elements, to provide a useful way of thinking about problems. Design patterns are useful for any object oriented work, regardless of language.

      Private function members appear in header files so that vtables can be built at compile time. ... And Strostrup refuses to fix it.

      Regardless of reasoning, ultimately this is an issue for compilers to sort out. You're welcome to implement a compiler that handles it different, Stroustrup isn't going to stop you.

      Meanwhile, C++ is being abandoned for Java, C#, C, and scripting languages.

      Abandoning C++ for C? On which planet? One of the nice things about C++ is you can basically code C and get all of the benefits, then just use little smatterings of C++ where they really pay off.

      As for people moving to higher level languages like Java, C#, and various scripting languages, it might just be time to move on. We're continually moving to higher and higher level languages. Trying to move C++ into that realm will be like trying to make assembly language competitive with C. All you'll do is drive off your core users, the ones who really need the low level power, while failing to successfully complete with other languages designed from scratch to serve at a higher level. We'll be seeing C++ for a long time.

    7. Re:The real trouble with C++ by Brandybuck · · Score: 1

      The programmer is doing the compiler's job.

      Thanks, I needed a good laugh today, it being a Monday and all.

      The job of the compiler is to accurately translate the programmer's explicit instructions into machine code (or another language). No more, no less. It should rightly complain about syntactical and semantic problems, and if it's a polite compiler, should issue a warning for an obvious logical error. But it should NEVER presume to add to what the programmer has requested, or ignore anything he commands.

      --
      Don't blame me, I didn't vote for either of them!
    8. Re:The real trouble with C++ by Anonymous Coward · · Score: 0

      Hey, I know Wirth personally. Yes, he's in Switzerland, but no, he isn't bitter. Pascal's successors (Oberon and others) are in active use at my university. Pretty neat system.

    9. Re:The real trouble with C++ by renoX · · Score: 1

      >Pascal's successors (Oberon and others) are in active use at my university.

      And universities are pretty much the only places where Pascal's successors are used: quite a failure when you realise that at a time Pascal was a big competitor of the C language.

      The exception is Delphi, but it's not that big either compared to C,C++,Java(?)..

    10. Re:The real trouble with C++ by Anonymous Coward · · Score: 0

      Abandoning C++ for C? On which planet?

      On planet gnu, as far as I recall the gnu coding standards recommends any project be written in C.

    11. Re:The real trouble with C++ by null+geist · · Score: 1


      "Meanwhile, C++ is being abandoned for Java, C#, C, and scripting languages."

      ya'know, this is my problem with people trying to bash c++. what they don't realize is, people do abandon c++ not because it's a bad language but because it does not have a feature-rich standard library. with java, you get so many apis out of the box, it's overwhelming. but once you master them, then the tool is pretty powerful because you can write certain apps in just a small number of lines, whereas c++ would require you to buy 3rd party libraries ( which are, obviously, not 'standard' ) or develop thousands of lines of code

      the thing is, there is *NO* single language on this world that's good for everything. if you need to rapidly develop stuff, go and use java, c# or, say, perl. that's what i do. when i need to write a backend that needs to link two software communicating via text files, i don't grab c++, i grab perl. when i need to write a cross-platform gui where the slickness of gui is not important, i grab java; just like when doing network-related stuff. c# is good if you are aiming only windows boxes, etc.

      people do switch to other languages because they don't need the power of c++, a power that comes with its own troubles. this is just like driving a bmw versus a f1 car. if you need to go somewhere without having too much trouble, buy the freaking bmw. it has everything you need in it, out of the box. yet, if you need to go there fast, you have to spend time training yourself how to handle a f1 car, live without a/c or soda holder but you'll go there faster

      i have seen people trying to write elaborate guis and network applications using c++. what a poor choice! even if you have tons of 3rd party tools ( my standard set includes boost, wxwindows and ace ), it's still far more easier to use a rad. but, i have also seen crunching software that's written in java. that's even worse

      the moral of the story: know your language and use it properly. there are things c++ can do, while other languages will just watch silently from far and there are things other languages can do, which will take 10 times more lines of code in c++

      -- null

    12. Re:The real trouble with C++ by elflord · · Score: 1
      Abandoning C++ for C? On which planet?
      On planet gnu, as far as I recall the gnu coding standards recommends any project be written in C

      The word abandoning implies they're moving away from C++. My argument would be that they never moved towards it. In fact, with the rise of the KDE project, if anything, C++ has become more popular with free software authors over the last 10 years.

    13. Re:The real trouble with C++ by Anonymous Coward · · Score: 0

      I think you are overlooking the obvious....

  48. Re:Who is Bjarne Stroustrup? by SchroedingersCat · · Score: 1

    He is not Swedish, he is Danish.

  49. Not awake yet- by IWantMoreSpamPlease · · Score: 2, Funny

    I mis-read the title. Thought it said "interview with a mousetrap"

    oooops...

    --
    So rise up, all ye lost ones, as one, we'll claw the clouds.
  50. Hungarian notation by Anonymous+Brave+Guy · · Score: 1
    Really, what is the problem people have with Hungarian, assuming it is used reasonably?

    It depends what you consider "real" Hungarian used "reasonably".

    The idea of annotating variables to show certain fundamental properties has merit. For example, using "m_" or something similar to distinguish member variables can be useful to avoid name-clashes or developers resorting to not-quite-pseudonyms. Using "n" as a prefix consistently to indicate that the variable is a count of something can be useful.

    Notice, however, that neither of these is explicitly embedding type information in the variable name. Using "m_fValue" for a member value of type float is foolish, because if you ever change the value to be of type double, or LibraryExtendedPrecisionDouble, your name is now worse than useless, it's misleading. This is why MicrosoftHungarianNotation(TM) sucks.

    The only exception to the latter that I make with any regularity is prefixing pointers with p+ (that's a regular expression :-)) to indicate the level of indirection can be useful. It's rare for that property of a variable to change, and saves looking up whether you defined something to be a pointer or a reference later. Of course, then you have to worry about how to represent iterators, smart pointers, names of arrays, etc.

    The best one I ever saw was someone who insisted on prefixing all variables of reference types with "r", e.g., "rValue" instead of "value". That demonstrates a spectacular misunderstanding of both the value of warts and the implications of using a reference, all with one letter. :-)

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    1. Re:Hungarian notation by cK-Gunslinger · · Score: 1

      Agreed. The absolute worse is when someone takes a reasonably good idea, gets a small or misguided grasp of the concept (but not the reasoning behind it), and tries to enforce it as a strict policy.

      As an ugly example, I worked on a C++ project where someone ran across the idea to use a 3-letter prefix for all classes/files to indicate what package/subsystem they belonged in and decided to enforce in on our project. It was reasonable at first, but after we had the usual package-explosion (before refactoring), we ran short of *meaningful* prefixes, and were reduced to using a large spreadsheet to keep track of them all and what they represented. For example "gbl_" was global (ok), but "xrf" was slow-rate tracker (srt_ was already taken.) It became a nightmare. But the whole build system was built around the concept, it couldn't be dropped or even modified to allow more letters, etc.

    2. Re:Hungarian notation by Anonymous+Brave+Guy · · Score: 1

      I've always wondered about how the physical organisation of a project would go using that idiom. Lakos recommends it, IIRC, but it struck me as dubious even back then, on the basis that it wasn't amenable to easy maintenance.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    3. Re:Hungarian notation by 2short · · Score: 1

      "It depends what you consider 'real' Hungarian used 'reasonably'."

      I use:
      "m_" for private members (in my code, typically, all the data members of a class will be private; structs will be nothing but public data members)

      Then, in apropriate order:

      "a" for arrays (in the generic sense; i.e. STL containers too)

      "p" for pointers (again generically, could be a "Whatever *", could be a SmartPointer<Whatever>

      "r" for a non-const reference

      Finally type:
      "n", "f", and "s" to indicate generic integers, floating points, and strings. I'll use "u", "i", "l", and "d" if the specific flavor of integer or floating point matters particularly.

      I also use a small salad of other things, e.g "it" for iterator (though I think of that as an abreviation, not a notation.)

      "Using 'm_fValue' for a member value of type float is foolish, because if you ever change the value to be of type double, or LibraryExtendedPrecisionDouble, your name is now worse than useless, it's misleading."

      The same argument can be made against commenting your code. If you change the code and not the comment, the comment will be misleading. Should one then never comment code? If you change the type of the variable, you're right there at the declaration, so change the name too. Now the compiler will quickly show you all the places the old name was used. You were going to check all those places to make sure your change wasn't a problem, right? Of course you were. So while you're at it you can update the name to indicate that you've checked it.

      So I'll frequently have an "f" on a double. The important thing is that it's a floating point. You may have noticed I have no way to indicate a float that definitely isn't a double. I've never had a problem with that. Nor can I imagine well written code using a float theat couldn't use a double.

      "The best one I ever saw was someone who insisted on prefixing all variables of reference types with "r", e.g., "rValue" instead of "value". That demonstrates a spectacular misunderstanding of both the value of warts and the implications of using a reference, all with one letter. :-)"

      Well, I wouldn't put an "r" in front function argument that's a const reference; that's just an optimization, it doesn't matter for your use of the var. For a non-const reference though, I'd put that "r" tied with "m_" for most useful hungarian element. Using a non-const reference has important imlications. I want to know that's what it is every time I use the variable.

    4. Re:Hungarian notation by Anonymous+Brave+Guy · · Score: 1
      Using 'm_fValue' for a member value of type float is foolish, because if you ever change the value to be of type double, or LibraryExtendedPrecisionDouble, your name is now worse than useless, it's misleading.
      The same argument can be made against commenting your code.

      Indeed it can. That is precisely why banner comments like this:

      /*
      some_function_name: Does some function

      Parameters:
      int firstThing -- the first thing it uses
      char secondThing -- the other thing it uses */

      are a very bad idea. Comments should describe what your code is doing, but not repeat information in the code itself. And yes, comments are overused; self-documenting code (with judicious use of tools like typedef in C++, and named temporary variables to make complex manipulations explicit) would make much of what gets written in comments redundant.

      As for changing the type, yes, of course you should check everywhere that might be affected, but people don't. That's the problem. And yes, float vs. double can make a difference; mixing them up leads to hideous numerical analysis issues if you're not careful. It's good idea to use a double for everything anyway, unless you've got a compelling reason not to, but misleading names that might suggest two values, one a double and the other a float, are of the same accuracy, is just asking for trouble.

      I take your point about labelling references in a class type. I was thinking more of the aliases used for convenience in functions.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    5. Re:Hungarian notation by 2short · · Score: 1

      Well, we're pretty close to the same page.

      I agree entirely that most comments are lame, and more clearly written code would eliminate the need for them. I just think judicious use of hungarian is part of clearly written code. I have a much easier time keeping track of which variables are which if they're broken down into broad categories by their prefix. Anyway, there are certainly some cases where comments are definitely waranted. Like when it says: /*
      These next two lines may seem wrong, and while it's counterintuitive, doing it this way produces a significant performance gain because....
      */

      "It's good idea to use a double for everything anyway, unless you've got a compelling reason not to"
      Perhaps this is part of why using "f" for generic floating points isn't a problem with me. I can't recall the last time I used an actual "float".

      "I take your point about labelling references in a class type. I was thinking more of the aliases used for convenience in functions."

      I think the same argument holds there. If I write:
      string &rsName = m_aVariableMap["Name"];
      so that I can use a shorter (and perhaps clearer) identifier, then later on if I'm looking at the code, it's important to me to know that rsName is a reference, not a simple local variable. If I change its value, that difference will be significant. But I don't do that all that much. The realy classic example is the function argument passed by non-const reference. There the "r" helps the function writer, but also alerts the function user that this argument may be changed by the function (and presumably will).

  51. So... by Xaoswolf · · Score: 1
    Just how do you pronounce your name?

    Looking through, I can't believe I didn't see someone else asking it...

    1. Re:So... by Anonymous Coward · · Score: 0

      Here is how you pronounce his name http://www.research.att.com/~bs/bs_faq.html#pronou nce

    2. Re:So... by amstrad · · Score: 1

      It's in his FAQ

  52. Christ, this hasn't died yet? by devphil · · Score: 1


    It's not "probably" fake. It's complete crap. He debunked this in his FAQ a couple days after the first troll posted it.

    --
    You cannot apply a technological solution to a sociological problem. (Edwards' Law)
    1. Re:Christ, this hasn't died yet? by Anonymous Coward · · Score: 0

      I disagree that it's "complete crap". It lives on and gets passed around by people with wry smirks and chuckles not just because it's funny but because there's some truth to it. Think about what Linux would be like if the kernel were written in C++.

  53. Re:OOP IS FOR PUSSIES by imbaczek · · Score: 1

    Most people I know don't get the beauty of something like C++. It's a massively complex language. So complex, as a matter of fact, that you can create OTHER languages with it (via templates).

    How funny it is that I consider Lisp a quite simple language (at least syntactically) and it still can do all this OOP, language-in-language stuff, etc., despite being ~20 years older...

    Anyway, go Python :P

  54. Re:OOP IS FOR PUSSIES by Ellen+Ripley · · Score: 1
    Even though the original post was a troll...

    How do you know that? How do you know the intent of the poster?

    The language was certainly colorful, and implies a certain degree of immaturity or personal involvment in the issue. It wasn't a detached and cool assesment. The implied criticism of zealots in such a passionate post is mildly amusing. However, there is a point of sorts. Here's the original post:
    Object Oriented Porgramming is for control freak fucks who can't keep their heads on straight. They want to categorize and classify every damn thing under the sun. Kind of like the programmer and the engineer who were asked to build a toaster by the king. The king had the programmer ass (who was n OOP zealot) put to death.
    Suppose the poster had written this instead:
    C++ is, from the point of view of many C programmers, somewhat covoluted and over-elaborated. It's not optimized for thinking about small, simple, precisely-targeted code. Creating elaborate structures of objects is too much work for most programming tasks.
    (I'm not sure that's exactly the posters intent, due to the style, but it will serve as an example.)

    If the poster had used more moderate language, would you still have called the post a troll? Doesn't the language the poster used also support an alternative interpretation, in which not only are they not trolling (posting with intent to "attract predictable responses or flames"), but in which these are their genuine feelings? In fact, doesn't the language used support the idea that this person genuinely, if somewhat un-thoughtfully, despises OOP?

    There's a Slashdotter who sometimes signs just his name, and sometimes signs with "Esq." after. He says his ratings of "Troll" and "Flamebait" rise dramatically when he uses "Esq.". All of this implies that moderators are rating not the content, but the style.

    Personally, I'd like to see the likes of "Troll" and "Flamebait" replaced by something along the lines of "Imprecise" or "Emotional". Maybe "Offtopic" could be replaced by "Tangential". :-)
  55. Why separation is a good thing by Anonymous+Brave+Guy · · Score: 1
    As a developer you want to have all helper functions for a data type at a single place.

    Why? Adding all the supporting functions into the type itself just clutters the interface and makes it hard to find the "heart" of what the class does. As mentioned in the interview, it also removes much of the benefit of abstraction and encapsulation.

    As the user of an IDE you want to see all available functions when you enter a variable with a given type.

    That argument doesn't generalise, though. How do you find functions that work with two user-defined types? (Cue deep and meaningful discussion of double-dispatching implications. :-))

    The correct answer to this problem is to put all your related types, supporting functions, enumerations, typedefs, templates and other gear into well-organised modules. C++ doesn't have a great module system, but it does provide namespaces, which could be used for this purpose if you chose to do so.

    The fact that you want an IDE to give you a display of all the functions you might want is a sign of weakness in your IDE (for not taking full advantage of the abstraction mechanisms offered by the language), your documentation system (which should be what tells you which functions to use when) and, depending on what exactly you meant, possibly yourself (since you shouldn't be calling any function when you don't know what it does anyway).

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  56. Re:what kind of name is bjorn by Anonymous Coward · · Score: 0

    I like bjs. As long as it's not from "uncle" eddie.

  57. Re:OOP IS FOR PUSSIES by Anonymous Coward · · Score: 0

    if an oop guy can do oop, he can do it in any language- assembly, basic...it doesn't matter. the language merely presents the oop approach the language designer (stroustrup) thought out.

    assembly language does not really have any support for oop. you are free to implement oop however you see fit. assembly is probably the most flexible oop language in existance.

    although some find assembly to be a difficult language, it's hard to disagree that the native language is not the best approach for programming. not only for the sake of the processor but for the programmer as well.

    why add layers to the cake? why all the flash and glitz? just get down to what your going to do anyways and avoid the middle man...it's a tough concept, and mostly rejected.

    there's a shitload of people that can't program. they will continue to try. people will continue to make languages, paradigms, methods, etc so the people that can't program can basically hide the fact that they can't program (so they can get a job to buy an suv...) this will never change. most programmers arent innovators, they're followers and imitators. nothing is wrong with this. it's just kind of boring.

    i wish programming could be like live performance music. it would be perfectly clear who could program. the turkeys would get weeded out almost instantly.

  58. Re:Who is Bjarne Stroustrup? by Anonymous Coward · · Score: 0

    The MOV AX, BNDMP within the loop is not necessary. Additionally, IIRC it's faster to decrement cx and branch vs using loop on the 8086 (and definitely faster on more recent processors).

  59. C++ in the long term. by Godeke · · Score: 2, Interesting

    I programmed in C for years, mostly due to the performance of the early machines I used. Today, I wouldn't consider going back to C unless it was for time critical functions. Everything I do these days is in an environment that protects me from the gory details of memory management and pointers of doom. If I really need performance, I am going to profile my code and find the parts that really need the boost, and then recode the classes as C++ COM or more recently C++ assemblies for .NET. It is the same procedure I used to use when C was my primary language: find the performance hot spots and drop to assembly if needed.

    The discussion of class design has nearly nothing to do with C++. I can use Java to build overly complex towers of inheritance. I can also use it to build poorly defined libraries. One think I *can't* easily do is blow myself (and the underlying OS) up do to a memory allocation problems.

    I see C++ remaining for many years to build those "cycle critical" components, which are going to be consumed by languages with a guard over the chainsaw blade. Programmer efficency should always trump speed concerns until you have exhausted *algorithmic* improvement. I don't know how many times I see programmers saying "I'm using C++ for performance" while simultaniously writing something that is going to run in o(n^2) time, when a o(log(n)) algorithm is available. Yes, your C code will run your inefficent algorithm quicker than I would in a protected environment, but if my protected environment allowed me to see the abstraction that runs the fastest algorithm, my code will still be faster for large data sets.

    --
    Sig under construction since 1998.
    1. Re:C++ in the long term. by jjohnson · · Score: 1

      I can't easily blow myself, either, but it's worth the effort.

      --
      Anyone who loves or hates any language, platform, or manufacturer, doesn't know what they're talking about.
  60. If you were so clever.... by turgid · · Score: 1

    ... Mr Mensa, you'd realise that this isn't a slashdot interview. :-)

  61. This confirms it for me... by Anonymous Coward · · Score: 0

    I started OO programming in 1987 with Smalltalk and continued with Objective-C in 1988. In 1989, I started using C++ and continued using it for about 7 years.

    The one thing I noticed when I was programming C++ (when compared to Smalltalk or Objective-C) was that it is damn near impossible to implement a real OO design in C++. One is always having to struggle with the language and the result is pretty much always hacking the code to simply make it work.

    I have always believed that BJ simply doesn't understand OO and this interview has really confirmed it for me.

    Here are a couple of quotes which make me believe that:

    Again, one indication that you've gone too far with class hierarchies is you have to write casts all the time, casting from base classes to derived classes.

    What he describes above is not a problem with Object-Orientation (ie. this problem just doesn't happen in languages like Smalltalk or Objective-C), this is a problem with the hideously poor implementation of the C++ language. His comment here really shows that what he *thinks* is OO is really Class-Orientation. Pretty much all of the C++ code I've seen is Class-oriented and not Object-Oriented.

    The differences may appear to be subtle, but the impact is profound. In OO programming, the complexity of the system is managed by a dynamic structure (the object model). In Class-oriented programming, there is no object model to speak of (except as it is derived from the class model) and the complexity has to be maintained within a static structure (the class model). The result is a whole lot of extra code to write because the class structure is more complex than it needs to be.

    They believe that you should do everything by creating a class as part of a class hierarchy with lots of virtual functions. This is the kind of thinking that's reflected in a language like Java for instance, but a lot of things don't fit into class hierarchies. An integer shouldn't be part of a class hierarchy. It doesn't need to. It costs you to put it there. And it's very hard to do elegantly.

    "A lot" of things don't fit into a class hierarchy? If he really believes this, he simply doesn't know what object-oriented is. The majority of things fit well into an object framework... it is only a few things which don't and the only reason they don't is because of optimization.

    C++ programmers are absolutely rabid about optimization; even when it is completely unnecessary. It has become a religious area for them and they are completely unaware that they derive no benefit from it whatsoever 99.999% of the time.

    Going to the big class hierarchy is again, you write more code than you need to, and you get too much connection between different parts.

    This is a symptom of class-oriented programming NOT object-oriented programming. Again, this point is completely moot because these problems just don't occur in languages like Smalltalk or Objective-C. If you write Java like C++, then you get those problems, but if you write Java in a true OO manner, then you don't.

    Again, BJ really seems to think that Class-Oriented programming and Object-Oriented programming are the same thing. They are VASTLY different.

    1. Re:This confirms it for me... by GolfBoy · · Score: 1

      Interesting post, a lot of which I agree with.

      There is however one thing I don't understand. I am assuming that the distinction you draw between object-oriented and class-oriented designs / languages is the one about the desirability of run-time binding a la Smalltalk, Python etc. versus compile time al la C++. However, you then say 'if you write Java in a true OO manner' you don't get those types of problems. But Java hasn't got run-time binding, so what am I missing?

  62. Re:Who is Bjarne Stroustrup? by Anonymous Coward · · Score: 0

    But what kind of Danish? Apple?

  63. Re:Invariant/struct discussions and binary compati by TheSunborn · · Score: 1

    That is true but nobody should pass a struct to anything which can be considered third party.

    If you use your struct to pass data between methods widthin your program there is no problem with binary compability.

  64. Re:OOP IS FOR PUSSIES by dtfinch · · Score: 1

    I was programming in assembly about the same time that I was programming in qbasic back in middle school. I started moving away from assembly my freshman year of high school when I took a Pascal class, followed by C the next year, and C++ and Java my senior year. Now I mostly just use assembly when I want to get to special instructions, and I expect to use it in a compilers class I'm taking this term. Aside from that the benefits aren't worth the extra typing.

    VB isn't too bad, if you're writing something cheap that you expect to throw away next year, and seriously hate gui programming in other languages.

    Real programmers use whatever's best for the task at hand. Just ask Steve Gibson of Gibson Research.

  65. You're kind of a chump. by Chromodromic · · Score: 1, Insightful
    Java has both abtraction and safety.

    Java has freakin' wrappers for ints, an abysmally slow start-up, and is just getting generics. I could go on for hours on how Java is a brilliant marketing effort but a miserable, byzantine morass of hierarchies, but I'll stick responding to your comments.

    C++ ... requires the programmer to obsess on storage allocation and release, yet gives no assistance in this ...

    Aaannnggghhh! Wrong. Please refer to the header in the STL, to use only when the many various STL containers somehow are insufficient for your job.

    Strostrup still insists there's nothing really wrong with his language.

    Uhh, okay, but Sun is all too willing to discuss flaws with Java? And God knows, Microsoft is always willing to discuss anything the user is concerned about.

    Wirth is a forgotten and bitter man in Switzerland.

    Is Wirth really bitter? I wouldn't know, but he's hardly forgotten. There's a whole school of programmers that advocate Delphi which, last I checked, was still being sold to this day. If you don't know what Delphi is, then hit borland.com and educate yourself.

    Ada and Modula got this right, but C++ got it wrong. And Strostrup refuses to fix it.

    I'm skeptical that Ada has gotten much right, but speaking to the illusion that Stroustrup is Lord God King -- Stroustrup is only one member of a rather large team that actively develops C++ and the STL. It's a committee now, and it ain't solely up to him.

    Meanwhile, C++ is being abandoned for Java, C#, C, and scripting languages.

    Uh, not for systems, games, or high-performance rapid development it isn't, and you can take that to church, buddy. Also, C is still in widespread use, but Java and C# are suffering the same competition, where there is competition in certain applications, from scripting languages that every non-scripting language suffers. Also, Java and C# are platforms, not simply languages, they're proprietary, and they're proponents depend heavily on making the development community believe that everyone(!) is jumping C++'s ship. Well, everyone isn't. Some developers, especially those that need to, see through the marketing spooge and use what's best for the job, not what Sun and Microsoft tell them to use. Jesus, if we all did what Microsoft wanted us to, we'd all be using VB.NET.

    C has little abstraction and little safety. Java has both abstraction and safety. C++ has abstraction without safety, a terrible combination.

    This is just a doofy sentence. C has "little" safety but C++ is "without" safety? Dude, learn a language before you start spouting marketing crap. If you don't know why your sentence is completely wrong, then you're not qualified to comment.

    --
    Chr0m0Dr0m!C
  66. Standards compliance by Anonymous+Brave+Guy · · Score: 1
    I believe that MS VC++ 7.0 (or whatever it's marketed under now) and G++ are the most compliant of the bunch.

    Nope, I believe EDG's kit (as used in Comeau compilers, for example) is currently the best on paper. It does support things like export, detailed template mechanics and so on.

    Visual C++ .Net 2003 (i.e., the second .Net version sometimes referred to as VC++ 7.1) is also pretty good, but does have acknowledged limitations.

    g++ has a long way to go. It was never great, though when the 3.x series first arrived it was better than many. It's a relatively long way off the pace of the serious players now, though, both in standards compliance and in performance. I guess that's the price you pay for keeping the back-end code so widely portable.

    One interesting place to look at compatibility is the Boost library [...] It's certainly not a definitive test of what is and is not standard, but it's a data point.

    However, please note that Boost (or at least its test suite) is a data point the maintainers specifically ask you not to use as a gauge for things like standards compatibility. See various recent threads in comp.lang.c++.moderated or comp.std.c++ for details.

    You're certainly correct in that C++ compilers and their STL libraries have come very far in the past couple of years. One of the worst (Microsoft) is now one of the best -- largely due to them hiring a project lead that's a STL advocate.

    Play fair... :-)

    Hiring two big names in the C++ world in recent months probably did a lot of good. However, the killer with Microsoft was that until last year, their most up-to-date compiler (VC++ 6) was around five years out of date, as was its standard library implementation. It's unsurprising that, in comparison, the standards compliance of other tools was better, given that VC++ 6 actually predates the standard. That said, they had a pretty good idea of what was going to be in it and did a fairly decent job, considering.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    1. Re:Standards compliance by be-fan · · Score: 1

      g++ has a long way to go. It was never great, though when the 3.x series first arrived it was better than many. It's a relatively long way off the pace of the serious players now, though, both in standards compliance and in performance. I guess that's the price you pay for keeping the back-end code so widely portable.
      >>>>>>>>
      Whoa. What tests have you been reading? Your analysis is years out of date. GCC's complience is absolutely competitive with VS.NET, and in the most recent benchmarks (see CoyoteGulch's) show it to be very competitive with Intel C++.

      --
      A deep unwavering belief is a sure sign you're missing something...
    2. Re:Standards compliance by You're+All+Wrong · · Score: 1

      Didn't HS himself say that making MSVC++ standards compliant extremely low on the MS priority list?

      YAW.

      --
      Your head of state is a corrupt weasel, I hope you're happy.
    3. Re:Standards compliance by Anonymous+Brave+Guy · · Score: 1

      I don't recall that. Most of the early hype generated on his arrival at Microsoft seemed to be trying to convince the "serious C++" crowd that Visual C++ was a "serious compiler", with respect for standards and the buzzword libraries like Boost and Loki, as well as Windows-based frameworks like MFC.

      Where did you see/hear Herb's comments on standard compliance being a low priority? It seems pretty far out of character, and a significant change of tune from MS.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    4. Re:Standards compliance by You're+All+Wrong · · Score: 1

      Probably c.l.c.m.
      Maybe it wasn't HS, but it was definitely an official MS spokesperson. Probably over a year ago.
      I'm googling now, but all the terms yield a million hits...

      --
      Your head of state is a corrupt weasel, I hope you're happy.
    5. Re:Standards compliance by You're+All+Wrong · · Score: 1

      Hmmm, I can see HS saying teh exact opposite.
      Maybe it was pre-HS then, and that could be why HS was dragged on board in order to repair their reputation.

      Still googling...

      --
      Your head of state is a corrupt weasel, I hope you're happy.
    6. Re:Standards compliance by Anonymous Coward · · Score: 0

      No way. Herb is on-record as saying the exact opposite in fact:

      http://www.gotw.ca/microsoft/index.htm

      Got a lot of respect for HS's work, it's great to see him taking a hand in keeping MS inline (excuse the bad pun)...

  67. Re:Invariant/struct discussions and binary compati by Bodrius · · Score: 1

    Structs should be disjoint from the API.

    If you're publicizing an API, then you should be dealing with classes, not structs, for those reasons and more.

    If you're using a struct, you're making some very strong assumptions about your data structure. You're also making an optimization in the process, whose validity depends on those assumptions.

    You're assuming it has no behavior. You're assuming it will NEVER have behavior. You're assuming it's simple enough that you don't need to check for value constraints, or anything like that.

    As a result, you should not let anyone, including yourself, extend that struct, either to add data members or behavior. If you have to, your assumptions were wrong... if you even imagine you might have to, your assumptions are wrong. Don't use a struct.

    If the rules changed for you in the middle of the game and you need to replace the struct, you are then forced to communicate to everyone else that the assumptions have changed by changing the type. I would consider this a good thing.

    Obviously, you should think carefully before sharing structs with others. But this applies to any data type that implies very strong assumptions which might not be shared with others... you have to wonder if your users need that, and if they do you have to enforce and document those assumptions before they break your application.

    --
    Freedom is the freedom to say 2+2=4, everything else follows...
  68. Linker problems by spitzak · · Score: 1

    Though I agree with some of your stuff, I think C++ could be improved even if you don't improve the linkers.

    Your explanation that the vtable must be built from the public headers is wrong. All the modern compilers build it only in one source file (the rules vary but typically the one containing the first virtual function). It should be possible to add syntax to allow this to be more supported.

    My proposal:

    1. You should be able to define a new private member function at any time. Just write "int Foo::bar() {...}" and you will have a private method called bar(), whether or not it is defined in the header. This does not break any object-orientedness, as only other private members can call this. But it does get rid of a lot of annoyance in implementing classes, where you have to debate whether to change the header files or instead duplicate code or use pointers in order to get the implementation you want. Also private static data, and private static methods (probably by putting "static" before them).

    2. Allow the token "..." to be at the end of a class definition. This is an indication that there are more items afterwards. This means the sizeof() and entire vtable is not yet determined. However a lot of inline functions can be declared. C++ already supports this as saying "class Foo;" is the same as saying "class Foo {...};" in this new syntax. You can also declare the rest of a class by declaring it again with "..." at the start, if the compiler sees this it knows that the vtable can be defined now.

    While we are at it, I would really like to see a phony type called "0" which can be used as an argument class. "0" is unique in that it is the only type that can be automatically cast to a pointer or a number. A function declared as "int foo(0)" would be called in preference to "int foo(int)" when the argument is a literal zero. This would allow classes to match pointers better, and allow the compiler to compile around the "if" that is normally needed in the common case where initializing to a null or zero value is significanlty different that initializing to anything else.

    1. Re:Linker problems by captaineo · · Score: 1

      I would definitely love the ability to define a new non-virtual member function anywhere...

      I would also like virtual data members. e.g. class Foo { virtual int a = 1; }; class Bar : public Foo { virtual int a = 3; }. This should be easy to implement - just put them into the vtable along with the function pointers. And it would eliminate the need for zillions of tiny functions like virtual int Foo::get_a() { return 1; }

    2. Re:Linker problems by Anonymous Coward · · Score: 0
      You should be able to define a new private member function at any time.

      Exactly.

      Because C++ lacks this, functions tend to grow too large. Breaking out code into a new private function means altering the header files, recompiling other stuff, and in some shops, obtaining managerial permission to change key include files. So programmers tend to bloat existing functions instead.

      Yes, you can work around this. You shouldn't have to.

      Note that adding this feature doesn't break existing programs.

  69. INTERCAL by John+Bayko · · Score: 1
    Worst programming language in the histroy.
    You've obviously never seen INTERCAL (Compiler Language With No Pronounceable Acronym), or a number of other similarly mentally handicapped languages.
    1. Re:INTERCAL by Anonymous Coward · · Score: 0

      Donald Knuth seems to like INTERCAL.
      Mentioned on his Recent News page (towards the middle of the page).
      He implemented an algorithm in it here.
      The same algorithm implemented in various other languages is here.

  70. It's an education issue by Anonymous+Brave+Guy · · Score: 3, Insightful
    Seriously, you can't seriously improve a language by telling people how to program with it.

    However, you very much can improve how a language is used by telling people how to program with it. The single biggest problem C++ has isn't dangerous pointers, or ugly template syntax, or lack of a garbage collector, it's lack of good programmer education. C++ is a power tool, and requires skill to use. When most of the C++ textbooks in the world are teaching decade-old crap themselves, and most of the university professors don't know their own subject, it's not too surprising.

    I can sympathise a lot with Stroustrup here. His tool is unjustly battered by the ignorant more than perhaps any other mainstream language today, and it creates a self-fulfilling prophecy: most people who learn C++ learn it badly, and write code with buffer overflows and other kindergarten mistakes. Others pick up on this, and learn from people who themselves learned badly, and write more code with kindergarten mistakes. It's about time the C++ programming industry reached High School, but few ever seem to, and when they do, they aren't valued as much as they should be.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    1. Re:It's an education issue by varjag · · Score: 1

      His tool is unjustly battered by the ignorant more than perhaps any other mainstream language today, and it creates a self-fulfilling prophecy: most people who learn C++ learn it badly, and write code with buffer overflows and other kindergarten mistakes.

      Buffer overflows are not kindergarten mistakes. It is a pattern that occurs constantly in code written both by rookie and seasoned C/C++ programmers, hence it highlights a problem with the tool, not with a skill.

      If some design requires infallible humans to work properly, it's better to be reconsidered.

      --
      Lisp is the Tengwar of programming languages.
    2. Re:It's an education issue by Anonymous+Brave+Guy · · Score: 1
      Buffer overflows are not kindergarten mistakes.

      Yes, they really are. Buffer overflows are trivially avoided in the vast majority of cases, by simply using an appropriate higher level tool, such as a container class, instead of a primitive array.

      It is a pattern that occurs constantly in code written both by rookie and seasoned C/C++ programmers, hence it highlights a problem with the tool, not with a skill.

      "Seasoned" != "Good" in C++. That's my point.

      If some design requires infallible humans to work properly, it's better to be reconsidered.

      It doesn't require anything of the sort. It requires them to have read one chapter of one good book, or to have had a term of lectures from a competent tutor. The fact that most people using C++ have never read a good C++ book (mainly because most of the books on C++ are so bad) and most lecturers on C++ don't know their subject, is the root cause of all these problems. That's kinda my point.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    3. Re:It's an education issue by shadowpuppy · · Score: 1

      Yes and No. Buffer overflows are a symptom of the ANSI C library. Which I wouldn't consider part of the language but others may debate that point. In my experience, strcpy is much easier to use than many of the safer approaches. This means that many programmers will use strcpy and there will be a fair amount of insecure code.

      My approach has been to write my own string class thats does what I want easily. It takes a little investment but it seems to recoup the lost time overall. Yeah I know it's non standard but the results are more appealling to me than the ugly STL string class.

    4. Re:It's an education issue by Anonymous Coward · · Score: 0

      Buffer overflows are not kindergarten mistakes.

      Yes, in general, they are. Using classes like std::vector and std::string and techniques like RAII remove most of the 'common' causes of buffer overflows and memory leaks.

      Software Engineering requires skill. Deal with it.

    5. Re:It's an education issue by varjag · · Score: 1

      Buffer overflows are trivially avoided in the vast majority of cases, by simply using an appropriate higher level tool, such as a container class, instead of a primitive array.

      I'd say C++ culture discourages the use of higher-level containers. Partly because they aren't within the core language, and partly because of the vast array of libraries that require supplied buffers to be 'primitive arrays'.

      --
      Lisp is the Tengwar of programming languages.
    6. Re:It's an education issue by varjag · · Score: 1

      Using classes like std::vector and std::string and techniques like RAII remove most of the 'common' causes of buffer overflows and memory leaks.

      Yeah, go pass your std::string as a destination buffer to a WinAPI function.

      Software Engineering requires skill.

      Software Engineering is a myth.

      --
      Lisp is the Tengwar of programming languages.
    7. Re:It's an education issue by sw155kn1f3 · · Score: 1

      you should use vector for it, not string

      --
      - Arwen, I'm your father, Agent Smith.
      - Well, you're just Smith, but my father is Aerosmith!
    8. Re:It's an education issue by Anonymous+Brave+Guy · · Score: 1
      I'd say C++ culture discourages the use of higher-level containers.

      Culture is certainly a problem, it's true. The idea that the containers somehow aren't a core part of the language is a prime example; they are in the standard library, and available on all recent implementations. To view them as being somehow a disjoint part of C++ is to create an artificial barrier where none exists.

      The issue of libraries that use pointers, C-style strings and primitive arrays is a serious one. In fairness, however, it is easy to work with container classes most of the time, and convert the data to or from a lower-level format only at the point where you interface with an external library. Some libraries -- notably the major UI ones -- tend to provide their own container and string classes, and if you want to use those instead of the standard ones, there's nothing to say you can't. Either way, within your own code -- where you might inadvertently introduce memory leaks, buffer over-runs or any other nasties -- you are always protected by using a suitably robust high level tool. IMHO, the problem isn't that people can't do this, it's just that they don't.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    9. Re:It's an education issue by varjag · · Score: 1

      That wouldn't work either. If you use an object that implements a container, you can't pass it as a destination buffer to a function expecting raw memory pointer.

      --
      Lisp is the Tengwar of programming languages.
    10. Re:It's an education issue by varjag · · Score: 1

      The idea that the containers somehow aren't a core part of the language is a prime example; they are in the standard library, and available on all recent implementations. To view them as being somehow a disjoint part of C++ is to create an artificial barrier where none exists.

      This is both historical and (as you have mentioned before) education issue. I've yet to see a single book on C++ that starts using container classes right from the introduction chapters. Usually one gets exposed to C types for the most part, and only later container classes are introduced, often in pile with the rest of STL and other functionality.

      On the other side of spectrum there are early C++ adopters and people converted from C. Old habits die hard.

      Either way, within your own code -- where you might inadvertently introduce memory leaks, buffer over-runs or any other nasties -- you are always protected by using a suitably robust high level tool.

      Once you declare a buffer, there is a great temptation to reuse it. Also, if your code is API-intensive, the bolierplate for converting containers back and forth gets pretty irritating.

      IMHO, the problem isn't that people can't do this, it's just that they don't.

      People can do all sorts of amazing things :) It is however much easier to work when the tool doesn't let you shoot yourself in a foot, since (with rare exceptions) you really don't need it.

      --
      Lisp is the Tengwar of programming languages.
    11. Re:It's an education issue by sw155kn1f3 · · Score: 1

      not true :) vector is just a continous chunk of memory and you can safely get the pointer to the first element - it's well documented

      --
      - Arwen, I'm your father, Agent Smith.
      - Well, you're just Smith, but my father is Aerosmith!
    12. Re:It's an education issue by Anonymous+Brave+Guy · · Score: 1
      I've yet to see a single book on C++ that starts using container classes right from the introduction chapters.

      The only one I know about is "Accelerated C++", by Koenig and Moo. It has been widely acclaimed in the C++ community precisely because it does that.

      Once you declare a buffer, there is a great temptation to reuse it. Also, if your code is API-intensive, the bolierplate for converting containers back and forth gets pretty irritating.

      Well, reusing variables for multiple purposes is rarely a good idea, for buffers or anything else. At least if you're using a decent container class, you won't be able to inadvertently overrun whatever size you used last time.

      Regarding API-intensive code, I've noted that most C++-based APIs that rely on complex data structures also provide their own container classes if they don't work with C++'s own standard ones. I've never found excessive boilerplate code to be a problem; in fact, I rarely find I need any non-trival boilerplate code to convert between datatypes at all.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    13. Re:It's an education issue by varjag · · Score: 1

      not true :) vector is just a continous chunk of memory and you can safely get the pointer to the first element - it's well documented

      Wrong.

      Vector can be an arbitrary structure containing more than just the memory chunk. Hence, most vector classes have conversion methods to obtain a C-style object. When they do, the objects they return are usually immutable ('const') and are a copy of actual container data (witness STL).

      Besides, a vector instance don't have to occupy a contiguous memory area: consider growable vectors.

      --
      Lisp is the Tengwar of programming languages.
    14. Re:It's an education issue by sw155kn1f3 · · Score: 1

      oh... better do some reasearch before tagging anything wrong at a glance
      check this out
      or just google for "getting a pointer to the first element in a STL vector"
      nice try boy, i almost belived i was wrong and my C++ programs are buggy shit due to that

      --
      - Arwen, I'm your father, Agent Smith.
      - Well, you're just Smith, but my father is Aerosmith!
    15. Re:It's an education issue by varjag · · Score: 1

      OK, I have to admit that I was unaware about the constraint on vector layout imposed by STL. My main exposure to C++ was with MFC, where the favored CArray's operator [] was documented to copy.

      Also, the very article you refer to points out that it's still impossible to pass std::string as a mutable buffer, and that a proxy storage must be used. This is hardly obvious, convenient or effective, so no wonder that it remains an esoteric hack.

      i almost belived i was wrong and my C++ programs are buggy shit due to that

      Sorry. I hope you understand that I wasn't trying to 'trick' you into something.

      --
      Lisp is the Tengwar of programming languages.
    16. Re:It's an education issue by sw155kn1f3 · · Score: 1

      yep, first of all sorry for my attempt to insult at the end of the message :)

      yep.. it's mostly a hack, STL should have "buffer" class which will allow to get the address in more straightforward way - actually there's a bunch of libraries, ie boost.org which has those classes as long fixed-size arrays with bound checking in debug mode etc
      it's just a matter of time before they will become a standard c++, but technology lags of course b/c c++ design committee approves new libraries very slowly and what been approved really sucks (iostream fame)
      so the only option now for C++ programmer is to get some public domain/lgpl/whatever toolset and stick to it
      i'm very conservative in that b/c you know - "staryi drug luche novyx dvux - yep i'm kinda living in ex-ussr too" but boost.org and ACE are good candidates... somewhat bloated unfortunately
      i won't suggest to touch MFC once again with 100 feet pole - if you do UI there's a better alternatives (ATL/WTL, wxWindows); if you do mainly logic work - you shouln't use MFC at all - to link with monstrous library to get CArray class ? huh? (i have to admit that 4 years ago i was being doing exactly that)

      ok.. anyway - nice talk, thanks

      --
      - Arwen, I'm your father, Agent Smith.
      - Well, you're just Smith, but my father is Aerosmith!
  71. Thanks for all the help, Bjarne by mvonballmo · · Score: 1
    "Classes should enforce invariants"
    I'm sure I speak for all C++ programmers when I say thanks for leaving this incredibly crucial rule entirely out of the language and entirely up to individual programmers to enforce with design guidelines.

    As Bjarne notes, class invariants are incredibly important, as are routine pre- and post-conditions -- the tenets of Design-by-contract, but they are mysteriously never considered as actual language features in C++. Want a language that actually does help with class and code correctness (allowing developers to specify usage rules)?

    Use Eiffel.
    1. Re:Thanks for all the help, Bjarne by Anonymous Coward · · Score: 0

      Or try out D (www.digitalmars.com) instead!

      Some of D's features:
      * Garbage collection
      * Dynamic closures
      * Resizable arrays
      * Built-in strings
      * Strong typedefs
      * Templates done right
      * Properties
      * Operator overloading
      * Design by contract
      * RAII
      * Inline assembler

      And it has a real compiler, producing efficient native code for Linux & Windows.

  72. Chill by Robb · · Score: 2, Insightful
    C has little abstraction and little safety. Java has both abstraction and safety. C++ has abstraction without safety, a terrible combination.

    This is just a doofy sentence. C has "little" safety but C++ is "without" safety? dude, learn a language before you start spouting marketing crap. If you don't know why your sentence is completely wrong, then you're not qualified to comment.

    Fully encapsulating the complexity of an abstract data type without just giving up and making many of the important decisions in the language itself is an extremely difficult problem in language design. I find the first poster's sentence, while obviously an exageration, to be rather insightful.

    C++ has high aspirations in terms of giving the programmer complete control but ultimately fails due to the emergent complexity that results from the inability to fully encapsulate all of the design decisions.

    1. Re:Chill by Anonymous+Brave+Guy · · Score: 1

      I'm sorry, but I don't see how any sentence that compares abstraction and safety as if they're black and white can be insightful. C++ offers vastly more powerful tools for abstraction than Java (templates and deterministic destruction come immediately to mind) in exchange for modestly reduced safety (Java has a garbage collector, but it's a one trick pony). Saying that Java has both but C++ has only one in some absolute sense is just meaningless.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:Chill by Robb · · Score: 1
      First off, let me state I am not a big Java fan. Basically the designers of Java took a look at the state of the art in the mid 1990's and then took a couple steps back. In my opinion there is nothing Java does that isn't done better in some other language. That said, Java is more than adequate for a very large number of tasks.

      Java and C++ have similar abstraction capabilities but the difference --and this goes to the very philosophy of the two languages-- is that C++ places a lot of value in giving the programmer control while Java focuses on keeping the programmer safe. Java accomplishes this by trading some of the control programmers have over how things are accomplished for safety.

      The interesting question is what is the nature of this tradeoff. Is this opposition between safety and control implicit in the problem itself, i.e. it occurs in every language the best any language designer can do is decide how much control they are willing to sacrifice for safety, or is this opposition merely an artifact of current language designs.

      The point I seized on from the original poster is that a lack of safety undermines some of the gains made by better abstraction facilities. In some sense this is a contradiction in the design of C++ and is the key insight from the sentence I quoted. Clearly the orignal poster overstated several points but that does not make them wholey without merit.

    3. Re:Chill by Anonymous+Brave+Guy · · Score: 1

      I agree 100% that there's an inevitable trade-off between power (in the sense of low level control) and safety (in the sense of never being able to do something stupid). The two goals are indeed contradictory, and C++ and Java certainly aim for, and achieve, a difference balance between them.

      My objection was not to that comparison, but to the idea that either safety or abstraction was some sort of "on/off switch", rather than a continuous scale. That's not to say that I disagree with you when you say that reduced safety can undermine some of the benefits of better abstraction.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  73. Why C++ standard spec is not free??? by Anonymous Coward · · Score: 0

    Why?
    I know only two computer languages which require money to get full spec: C++ and Eiffel (and I've met ("learnt" would be too big word) really many comp languages, it is my hobby)

    To get *full* Eiffel spec, you must buy B. Meyer's book.
    To get *full* C++ spec, you must buy Stroustrup's book, or pay fee to ANSI or ISO.

    I bought Stroustrup's book years ago (printed in 1993), so it doesn't cover latest language features. Am I supposed to by his book each time C++ standard advances ?

    Consider these facts:
    1. overwhelming popularity of C++ worldwide
    2. numerous incompatiblities between C++ compilers
    3. enormous level of complication in syntax and semantic rules C++
    (2. and 3. are often very subtle, but it does not help at all)

    In this context, unavailablity of spec is outrageous, harmful and shameful, IMO.

    1. Re:Why C++ standard spec is not free??? by jdennett · · Score: 1

      Answered in the comp.std.c++ FAQ.

      http://www.jamesd.demon.co.uk/csc/faq.html

    2. Re:Why C++ standard spec is not free??? by elflord · · Score: 1
      I bought Stroustrup's book years ago (printed in 1993), so it doesn't cover latest language features. Am I supposed to by his book each time C++ standard advances ?

      The ARM was not the standard, and is not. That book was published before the standard became available.

      The PDF of the spec is available for As for "every time the standard advances" ... it has only "advanced" once -- in 1998 when the first standard came out. I think there will probably be a new standard within 10 years of 1998, and you will probably have to spend a whopping $20 or so on that too.

  74. Confirmed: C++'s not very object-oriented by dpbsmith · · Score: 4, Insightful

    I'm not saying that's necessarily a bad thing.

    The interview is interesting in that it confirms the impression I've had from using and/or struggling to use C++. When I try to do anything object-oriented, specifically anything involving polymorphism, it seems to be fighting me all the way. After some struggling I usually emerge triumphant, but it's almost always a battle.

    What Stoustrup seems to be saying is that classes should be treated as a special big deal, and shouldn't be used unless you're sure they're necessary. He seems to be recommending that there be, um, a class of elite programmers who put in the intense work to develop good, usable, well-debugged classes, and that the rank and file should, by all means use those classes but should not aspire to write new ones.

    And this is not unreasonable, given the effort of writing classes and getting the storage management right and so forth.

    The thing is, it's not a big deal to use classes in a truly object-oriented language. I'm not just talking about Smalltalk. Heck, they're trivial to use in REALbasic.

    Well, is that good? It certainly leads to overuse of OOP. To a man with a hammer everything is a nail, and every programming language tends to encourage overuse of the things that it facilitates. Every programming language has a tendency to induce brain-warp.

    C++, for better or for worse, does not induce object-oriented brain-warp.

    People who try to use OOP in C++ because it's cool or because of some article they read (or some instructor they had) find that C++ punishes such behavior. And Stoustrup is right: when you are programming in C++, OOP should be used sparingly and only when it's needed.

    Again, I'm not saying whether that's bad or good. That will depend on the degree to which you think OOP ought to be encouraged. If you think OOP should be just as much a part of a programmer's mental toolbox as iteration, or recursion, then it's not good. If you think OOP was the overhyped IT fad of the nineties, then it's not bad.

    What I'm saying is that it has always seemed to me that C++ is not a very object-oriented language, and Stoustrup's remarks seem to me to confirm the objective validity of that observation.

    1. Re:Confirmed: C++'s not very object-oriented by taradfong · · Score: 1

      Agreed. The fact that you have to go outside the language proper to do something as basic as a 'vector' indicates dysfunctionality. It sounds more like a crutch or excuse than the way things should be.

      --
      Does it hurt to hear them lying? Was this the only world you had?
    2. Re:Confirmed: C++'s not very object-oriented by be-fan · · Score: 1

      Actually, its a sign of elegance. If something as seemingly basic as a vector can easily be defined on top of existing primtives, then its not so basic, and doesn't belong in the language proper.

      --
      A deep unwavering belief is a sure sign you're missing something...
    3. Re:Confirmed: C++'s not very object-oriented by sorbits · · Score: 1
      When I try to do anything object-oriented, specifically anything involving polymorphism, it seems to be fighting me all the way.

      I am curious, what is it that you try to do?

      I have done OOP in many different languages, and although I do miss a few features, like extending classes without sub classing or real message passing, i.e. where a message can be sent to any object which implement it, then it certainly does support polymorphism, and neither of these features are present in Java, and unlike C++, Java does not support operator overloading or implicit type conversions (which make it really ugly to introduce your own types like a vector or matrix) nor are the native types objects, which again makes it ugly when these are to go in a standard container or similar, not to mention all the typecasts which are generally required due to all the implicit upcasting -- so I definitely do not hope that it is Java which is your frame of reference.

  75. Which ADTs? by Chromodromic · · Score: 2, Interesting
    C++ has high aspirations in terms of giving the programmer complete control but ultimately fails due to the emergent complexity that results from the inability to fully encapsulate all of the design decisions.

    Come on. If you're talking about vectors, lists, sets, queues, stacks, hash_maps, etc., then I think the STL does, via templates, quite a stunning job of encapsulation. Stroustrup's comment in the article concerns wider adoption of the STL as a starting point for more developers, and I challenge straightforward applications developers to disagree with that. In reviewing others' code, I'm frequently surprised to see arrays being used where vectors or lists would suit as well and be safer, and frequently disappointed to see many functions implemented without templates where they could be effectively abstracted and made much more reusable (and refactorable, if that's a word) by using templates. Please tell me where vectors, as an example, fall short in the encapsulation goal.

    Where have other languages succeeded? Java provides a base int type and an Integer wrapper, and this is a fundamental data type. Is this success? I just think it's confusing. And what about operator overloading in Java? Yes for Strings but no for user types? I think operator overloading, in a dedicated OOP language of all things, is very important to encapsulation, but Java says "too dangerous"!

    Rubbish. And I'm not really meaning to pick on Java. My overall point is that on an application level there is a pie-in-the-sky goal that might be feasible in terms of encapsulation and that's what I believe we should strive for. But on a library or language level, saying C++ is at fault for not ensuring "perfect" encapsulation (and I'm not sure what that is) throughout the libraries is a little naive. Please point out the language that gets anything fully correct without sacrificing something else. I mean, isn't this why we have different languages for different things?

    Finally, I don't find that sentence insightful. Saying C++ is "without" safety is only illustrating a complete lack of familiarity with the STL. The programmer does have to keep track of things at times, but nothing even approaches real difficulty until you start creating your own ADTs. Mainstream types of the "Shape" or "Person" or "Animal" ilk are fine and dandy and really no more difficult or "dangerous" than Java or C#. It's not until you get into the implementation of things like "vertex_queue" or "parallel_list" that you, admittedly, start to get into much slower going territory. But there's also a lot of power there, too, power that's taken away in other languages, such as Java, because it's too "dangerous".

    --
    Chr0m0Dr0m!C
    1. Re:Which ADTs? by taradfong · · Score: 2, Insightful

      The fact that the average user can do nothing safely useful in C++ w/o STL further indicates to me that C++ is a wizard's tool. Fine. And it's a great tool for wizards who invested the time needed to truly use C++ properly.

      What I don't buy is propaganda stating that C++ can be a productive tool for non-experts if only you avoid pointers and use the STL. That's the Microsoft mentality: everything's ok if you stay on the beaten path.

      --
      Does it hurt to hear them lying? Was this the only world you had?
    2. Re:Which ADTs? by elflord · · Score: 2, Insightful
      What I don't buy is propaganda stating that C++ can be a productive tool for non-experts if only you avoid pointers and use the STL.

      What propoganda ? Who is saying this ? I haven't heard AT&T saying this, or Bjarne, or anyone else. You're fighting a straw man. If you want a productive tool for non-experts, forget C++, forget java, forget C, forget any compiled language. Non-experts will do much better with an interpreted language, and even if it's 200 times as slow, it will be worth it for the programmer time it saves.

    3. Re:Which ADTs? by Haeleth · · Score: 1

      > If you want a productive tool for non-experts, ... forget any compiled language. Non-experts will do much better with an interpreted language.

      Um, what?

      You're saying that if I implemented a native compiler for (say) Python, then suddenly Python would only be suitable for experts, and productivity would plummet?

      I'm not sure what you're smoking.

      By the way, Java is primarily an interpreted language.

    4. Re:Which ADTs? by elflord · · Score: 1
      You're saying that if I implemented a native compiler for (say) Python, then suddenly Python would only be suitable for experts, and productivity would plummet?

      Well, no, for two reasons:

      1. Because they would still have the option of using the interpreter and the IPython shell for rapid development/prototyping, without the compile cycle, and
      2. You can slap a compiler on the language, but it would still retain the characteristics enjoyed by most interpreted languages, the most important one being dynamic typing. Actually, everything is conveniently dynamic in a language like python -- you can generate code at runtime and execute it, you can define functions on the fly, etc.

      You can talk about java being "primarily interpreted", and you're right in that it has a virtual machine, you'd even be right to claim that it is more dynamic than C++, but it still doesn't have an interactive shell interpreter, it is a strongly typed language like C++, and it comes with a lot of the syntactic overhead that comes with a strongly typed language, and you need to go through the compilation cycle, like you do with compiled languages.

    5. Re:Which ADTs? by Anonymous+Brave+Guy · · Score: 1
      The fact that the average user can do nothing safely useful in C++ w/o STL further indicates to me that C++ is a wizard's tool.

      I don't see how that makes any sense. It's like saying that the vast library in Java makes it a wizard's tool, yet without its extensive library, Java has precious little to recommend it over many other languages. It's like claiming that Perl would be just as useful a tool without CPAN.

      C++ provides tools for low-level control (pointers, raw arrays, etc.) when you need them, but for most tasks, you don't. C++ also provides higher level tools (container classes, standard algorithms, exceptions, etc.) that should be used in that majority of cases. It doesn't take a rocket scientist to understand when to use which. It just takes reading a few pages of a good book. Trying to separate the tools out, as if one is somehow a legitimate part of C++ and the other is not, just doesn't make sense.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  76. Death of Pascal by solprovider · · Score: 1

    I always thought Pascal was another MS-related casualty.

    In the 80s, everybody was talking about Pascal being the next great language. There were already descendants like Modula2 and ADA that were gaining market share. (This upset me because I learned Pascal, then C, and C looked more logical, so I hoped it would win.)

    Then MS introduced QuickBasic, which turned into VisualBasic. (I have a book published by IBM stating "VisualBasic is a trademark of IBM.") Around 1992, you could probably translate programs from Pascal to VB or v.v. by substituting the keywords. The structure and the syntax was almost identical.

    VB became the language of choice for beginners. It filled the same ecological niche as Pascal, so Pascal withered.

    ---
    The difference between Pascal-based languages and C-based languages:

    Pascal-based languages allow "procedures". Procedures can define multiple inputs and multiple return values. VB and the Windows API follow this syntax. It is easier for beginners to understand, but maintenance is difficult because the programmer needs to remember which variables can be changed safely and which will be returned.

    C-based languages insist everything is a function. Functions have 0 or 1 return value.

    When the C algorithm for returning multiple values by passing a pointer to a struct became difficult for maintenance, they invented classes, which allowed the multiple values to be retrieved. That was C++, but most early tutorials explained it as an addition to C, rather than a move to OOP. This is still evident in the ease of mixing C and C++ code in the same program.

    Then Java added easier memory management and notification of errors (and reintroduced the virtual machine for sandboxing.) It follows the C++ model, but prefers OOP design.

    --
    I spend my life entertaining my brain.
  77. What is OOP? by exp(pi*sqrt(163)) · · Score: 2, Interesting

    If I write something like:

    class F {
    float a;
    public:
    F(float a0) : a(a0) { }
    template<class X> X operator()(X x) const { return X(a)+x; }
    }

    is it OOP? It looks like OOP: it has a member variable, a method, a constructor and so on. But actually I'm defining a function closure. In Haskell you coud write an F(a) object as (a+).

    My point is this: for many programmers today objects are often a(n awkward) vehicle for computing with closures. This has many payoffs: it gives the ease of functional programming but also potentially provides many performance benefits. I code like this all the time as do hundreds of others. This is how you need to code if you actually want to do anything non-trivial with the STL.

    So in some sense I'm an OOP programmer. But in another sense I'm not. I'm not writing my code this way because I want to work with objects - I do it because this is the only way I know to treat a polymorphic function as a first class object in C++. Really I'm a functional programmer forced to use C++. It seems to me that many of Bjarne's remarks are way off the mark for programmers like me. We have to define classes for every damn little thing!

    --
    Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    1. Re:What is OOP? by Anonymous Coward · · Score: 0

      That is a compile error. Templates are not allowed in classes.

    2. Re:What is OOP? by Anonymous Coward · · Score: 0

      Where do people get this stuff? Of course classes can have member templates. std::basic_string has a constructor template, and even MSVC6 (hardly a paragon of conformance) supports that.

    3. Re:What is OOP? by exp(pi*sqrt(163)) · · Score: 1
      This is symptomatic of a larger problem. It's still the case that many C++ textbooks relegate the template section to a short subsection of the final 'miscellaneous' chapter. Templates are often misunderstood and perceived as arcane. It's a pity because (1) they provide incredible power and (2) the things you can do with them are really quite mundane if you step outside the tiny domain of the workhorse languages many of us use to earn our living and compare to languages like Haskell.

      Plus template support is now pretty reliable in many compilers, even Visual C++ 7.1 (gasp!) so there's no excuse any more.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    4. Re:What is OOP? by Oswald · · Score: 1
      I'm fascinated by what you've done here. I'm currently learning to program in Lisp/Scheme, but I feel pretty sure that at some point I'll want to branch out into the C family (because that's where so much of the action is). I can't even fully understand the member function in your class, but it still raises very interesting questions.

      For instance, what is your experience with performance using your techniques? Do you notice any difference between the speed of your code and well-constructed code using more conventional techniques?

      Also, do you feel that this way of programming might allow one to write a large program without giving yet another demonstration of Greenspun's Tenth Rule of Programming (I'm sure you've read it: Greenspun's Tenth Rule of Programming: any sufficiently complicated C or Fortran program contains an ad hoc informally-specified bug-ridden slow implementation of half of Common Lisp)? Granted, you're using C++, not C, but it's still an interesting point to ponder.

    5. Re:What is OOP? by elflord · · Score: 1
      So in some sense I'm an OOP programmer. But in another sense I'm not. I'm not writing my code this way because I want to work with objects - I do it because this is the only way I know to treat a polymorphic function as a first class object in C++. Really I'm a functional programmer forced to use C++. It seems to me that many of Bjarne's remarks are way off the mark for programmers like me. We have to define classes for every damn little thing!

      The class does have an invariant: the member datum a remains constant throughout the object lifetime. On the other hand, if a could be changed arbitrarily, you may as well make it a struct, and indeed, a lot of the small classes used in functional programming idioms don't have invariants, and hence you can implement them as structs, not classes. Also, this sort of class is a good example of a "free standing class" -- that is, you're probably not going to derive anything from it. I think your example is not only consistent with what he's talking about, but the more generic style of programming is a direction that is widely recognised in the C++ community as being appropriate/valid.

    6. Re:What is OOP? by exp(pi*sqrt(163)) · · Score: 3, Interesting
      It's just a partially evaluated polymorphic function. Construct one of these things thusly: F(2) and it can now be applied like a function to other objects so F(2)(4) returns 6. The fact that it's polymorphic is very useful because that same object can be applied to a quite different type, say an interval arithmetic type, so F(2)(Interval(1,3)) might return Interval(3,5).

      Why is this useful? I do a lot of numerical/engineering work. Say I have a root finding algorithm that throws a bunch of methods at a function in an attempt to find roots. It might first try doing some interval arithmetic to bound the roots and then when it's close enough go in for the kill with a newton solver. So I need to be able to write a polymorphic function that can be evaluated on the types appropriate to these methods (first intervals and then maybe doubles) but also be able to hand it in as an argument to a solver routine (which in this case would be rank-2 polymorphic though people will tell you C++ can't do that!). The above is the only way I know, And the cool thing is that It can also be a partially evaluated function (ie. in the simple example I gave I'm passing in the two argument function + but partially evaluating it by giving one of the arguments 'a'). This is all routine stuff in the functional world and is beginning to be routine in C++, but not yet. It's kinda object oriented but the object oriented frame of mind really is the wrong way to look at it.

      Greenspun's rule. Yes, someone said that about some code of mine recently. But I have a response. For one thing the primary function of Greenspun's rule is to provide strokes for Lisp programmers' egos but these are the wrong people! C++ is a typed language and Lisp isn't. This makes a big difference. These methods push C++ more towards typed functional languages like ML or Haskell. Secondly: The example I gave is of a closure, written as (a+) in Haskell. But look where the work is happening: I haven't written any kind of interpreter, the compiler's doing the work. In fact if you take this stuff to its logical conclusion you're not implementing a Lisp interpreter but instead twisting the C++ compiler into a Haskell compiler. And if you don't believe me, here is that logical conclusion. If you look closely very little of that code is executed at run time (the lazy lists are), instead that minor mountain of code is directives to the compiler telling it how to behave like a Haskell compiler.

      As for performance penalties: yup, they exist. It's the so-called abstraction penalty. I don't really understand why it exists because it takes only simple rewriting rules to eliminate the overhead but compiler writers don't use them. Luckily people like Veldhuizen are writing papers showing the compiler writers how they should be doing their job.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    7. Re:What is OOP? by Anonymous Coward · · Score: 0

      Unfortunately, this forces the compiler to inline the code for ever invocation. OUCH.

  78. Re:Invariant/struct discussions and binary compati by apankrat · · Score: 1

    More often it happens that you need to add a member, but this is not possible without breaking binary compatibility (at least on the usual Linux/Unix compilers).

    By adding a member you are modifying an interface. What binary compatibility do you expect here ? If you need to extend a class-based interface, derive new class, add your new member there and publish it. If you are merely adding public data to your interface, you should simply add new access method(s). What Mr.Straustroup says is that in this case your data does not belong to the class, but a struct and your API should not be class-based. Feel the difference.

    Invariant-based criteria for choosing between the struct and the class is the guideline for designing clean and elegant C++ code.

    --
    3.243F6A8885A308D313
  79. Re:what kind of name is bjorn by Anonymous Coward · · Score: 0

    You fairy, you company man.

  80. Quick summary by Bazouel · · Score: 1

    Functions that change the data should be instance members. Functions that only read the data should be static members.

    And use struct instead of class when you don't have to maintain an invariant (consistency amongst the class's data).

    It's pretty common sense, but I agree with him that many people don't have it.

    --
    Intelligence shared is intelligence squared.
    1. Re:Quick summary by Burb · · Score: 1
      Functions that only read the data should be static members
      This makes no sense. How can you read the data without a "this" pointer value?
      --

    2. Re:Quick summary by Bazouel · · Score: 1

      Read the interview, you will understand.

      An example :

      If you have a Date class, you should define GetWeekDay() as a static member, not instance member.

      This is very basic, but the same applies to not so obvious cases.

      --
      Intelligence shared is intelligence squared.
    3. Re:Quick summary by Burb · · Score: 1
      I have read the article, and still don't understand why calling an instance member function d.GetWeekDay() is somehow to be deprecated in favour of GetWeekDay(d). Making "set" methods instance but "get" methods static introduces an asymmetry in design which is surely confusing? And there is no difference in efficiency, I would guess.

      I agree with part of the interview - i.e. overuse of O-O can be a bad mistake - but I'm lost on this one.

      --

    4. Re:Quick summary by Bazouel · · Score: 1

      If you have a GetWeekDay() and SetWeekDay(n), your thinking would make sense, but I have yet to see a set method for this. Maybe other examples ?

      Date.GetDaysInMonth(int)
      Date.IsLeapYear(Date)
      Date.Parse(string)

      Sometimes, those methods are available both as static and instance members, but in that cases, instance members are just wrappers around the static ones.

      --
      Intelligence shared is intelligence squared.
  81. Garbage collection and embedded Java by John+Bayko · · Score: 1
    Well, your "magic" is my "serious overhead that makes real-time programming esentially impossible".
    There are ways to reduce the overhead, but first you should realise that garbage collection is not as expensive as it might seem, and it allows runtime optimisations that static allocate and free don't.

    First, although it's not normally as efficient as explicit allocate and free, it is more efficient on average than something like reference counting. Even ignoring the fact that reference counting can allow mutually referenced objects to linger (ex. "a.next = b; b.next = a" will never reach a count of 0, and will never be freed), there is an overhead because every assignment to a pointer requires the compiler to insert extra reference counting code (or call a subroutine). That's a cost spread through the entire program.

    Typically, a garbage collection system will traverse all live objects - and only the live ones. That means that it will take the same amount of time no matter how much garbage there is - only live objects are checked.

    Most of the time only recently allocated objects are discarded, while older ones stick around a lot longer. The current Java system uses generational garbage collection, in that only recent objects are even looked at most of the time - objects that survive collection for several times are moved to a middle aged generation, and are looked at only incrementally (a fraction each cycle, not the complete group). The total number of live objects checked each time then becomes a very small number - in a long running program, probably less than 1% of the new objects, and maybe 0.1% of all objects.

    Middle aged objects that survive enough incremental passes are moved to an old age generation - these are only checked rarely, when a decision needs to be made about expanding the heap.

    The young generation garbage collection uses a copying method - this is important because it compacts the gaps between objects, defragmenting memory. A language like C or C++, which allocates using pointers, can't do this, otherwise the pointers will point to the wrong places. When there are gaps in memory (especially small ones), memory slows down because these gaps need to be checked each time, but are never large enough so the time is always wasted.

    I wrote a program once which did a bunch of allocation and freeing for initialization, then a bunch of bigger allocations and frees for processing. After profiling it, it turned out that the program ran about 20% faster by just allocating the initialization objects, and leaving them there as garbage - they were too small to be allocated for the main program, so freeing them just created gaps which malloc() had to check each and every time. Good garbage collection eliminates this problem entirely as a side-effect.

    In a Java program, you can give hints that it should do garbage collection at convenient times by calling the system/runtime garbage collection method gc() when it wouldn't be a problem. And there are products that give you better control over memory management (such as managing memory explicitly, as you would in C++).

    In summary, garbage collection isn't nearly as expensive or scary as many people think, and can even improve performance significantly.

    1. Re:Garbage collection and embedded Java by AKAImBatman · · Score: 1

      > In summary, garbage collection isn't nearly as expensive
      > or scary as many people think, and can even improve
      > performance significantly.

      Exactly. My only wish now is that all OSes would stop using Virtual Memory unless absolutely necessary. Overuse of vm results in an excessive amount of swapping in true OO systems like Java. For Windows, this is even true when the machine is far from using all available physical memory.

  82. Data abstraction considered harmful? by harmonica · · Score: 1

    Bjarne Stroustrup: Yes. If every data can have any value, then it doesn't make much sense to have a class. Take a single data structure that has a name and an address. Any string is a good name, and any string is a good address. If that's what it is, it's a structure. Just call it a struct. Don't have anything private. Don't do anything silly like having a hidden name and address field with get_name and set_address and get_name and set_name functions. Or even worse, make a virtual base class with virtual get_name and set_name functions, and override it with the one and only representation. That's just elaboration. It's not necessary.

    No! No! No! If you don't like the tedious task of writing the getters and setters, use an IDE which does this for you. But no structs that get used everywhere else. The other code has to know the struct's fields, and _if_ you have to change something (and there is always something), the struct approach requires numerous adjustments everywhere else. No good!

    If you have a perfect architecture, all designed and documented, and no code will ever have to be reused, structs may look like a good idea. But in the real world that doesn't happen. With modern IDEs, there's no reason to avoid getters and setters.

    1. Re:Data abstraction considered harmful? by be-fan · · Score: 1

      I think dylan's solution to this is ideal. In Dylan, get()/set() routines are automatically generated. This isn't a one-off hack, but a consequence of the object model. In Dylan, everything is a function call, so the only way to allow access to object attributes is through get()/set() methods.

      --
      A deep unwavering belief is a sure sign you're missing something...
  83. It's not even the first C-like OO language. by dpbsmith · · Score: 1

    Java wasn't even the first C-like language that was "object-oriented from the ground up." Java can't to be said to have begun until 1995. Objective-C definitely antedates it.

    And for the same reason, I'm not sure that you could call C++ was the first C-like OO language.

    C++ and Objective-C began at very nearly the same point in time. I wouldn't want to swear in a court of law which came first, but both were "in the air" circa 1990 or '91. They were perceived as being in competition, and the outcome was perceived to be in doubt.

    Objective-C indeed attempted to be truly object-oriented. At the expense of adding new syntax and breaking compatibility with C.

    C++ tried to be an improved C, adding various features including OOP while retaining full backward compatibility with C.

    1. Re:It's not even the first C-like OO language. by BoneFlower · · Score: 1

      Stroustrup started kicking aroudn the idea of C With Classes around 1979. It was in use by 1980. It had gotten out of Bell Labs in 1983, when it was first termed C++. Draft ISO standard in 1995, standard finalized in 1998.

      Wherease Objective C was begun in 1983, when C++ was already starting to see widespread use.

      References:
      The C++ Programming Language 3rd Edition
      http://www.cs.rit.edu/~ats/plc-2002-2/rep orts/objc /history.html

    2. Re:It's not even the first C-like OO language. by kwerle · · Score: 1

      Objective-C indeed attempted to be truly object-oriented. At the expense of adding new syntax and breaking compatibility with C.

      C++ tried to be an improved C, adding various features including OOP while retaining full backward compatibility with C.


      WOAH - 100% incorrect!

      Obj-C is a true superset of C, unlike C++. Any C code will compile with a correct Obj-C compiler. It added a few keywords to implement Objects, etc.

      C++ compilers, I understand, will not compile all C code (PLEASE correct me if I'm wrong).

      I don't know how old Obj-C is, but I know that it was the basis for NeXT's first dev environment, which first shipped in ... 1988?

    3. Re:It's not even the first C-like OO language. by __past__ · · Score: 1
      Java wasn't even the first C-like language that was "object-oriented from the ground up."
      No surprise, given that Java isn't "object-oriented from the ground up". It just forces anybody not employed by Sun Microsystems to not use any abstraction mechanism but classes and objects, just like it forbids operator overloading for anybody not employed by Sun Microsystems. Once you get a job at Suns design team, Java is a much more flexible language.
    4. Re:It's not even the first C-like OO language. by arkanes · · Score: 1
      If it added keywords, then it's not 100% backwards compatible. So there you go.

      I'm not aware of any C (not C99) code that a standard compliant C++ compiler won't compile, with the exception of one that uses C++ keywords. There may be some syntaxes that aren't legal in C++ anymore, but I'm not 100% sure.

    5. Re:It's not even the first C-like OO language. by kwerle · · Score: 1

      If it added keywords, then it's not 100% backwards compatible. So there you go.

      If it were 100% backward compatible, it couldn't add features, could it? I do believe that it is 100% FORWARD compatible, however. The keywords added were not valid C syntax (I'm pretty sure this is entirely true) - they are words like @class, @interface, @implementation, and the method calls are
      [someinstance doSomething:param1 with:param2] .
      Which can never be confused with valid C syntax, unlike C++, right?

      Aren't there problems with some unions and structs that are valid in C, but not in C++?

      I'm not aware of any C (not C99) code that a standard compliant C++ compiler won't compile, with the exception of one that uses C++ keywords. There may be some syntaxes that aren't legal in C++ anymore, but I'm not 100% sure.

      Isn't that why C++ has to wrap some #include statements with the weird extern call?

    6. Re:It's not even the first C-like OO language. by arkanes · · Score: 1

      The extern stuff is because of name decoration - it's a linker issue, not a language issue per se. I suppose it does make for a class of incompatability, though.

  84. The D Programming Language by Anonymous Coward · · Score: 0

    The D Programming Language is the evolutionary successor to C++ and does have class invariants, preconditions, postconditions, and Design by Contract built in to the core language.

  85. Do you know what you're talking about? by Anonymous Coward · · Score: 1, Insightful
    The job of the compiler is to accurately translate the programmer's explicit instructions into machine code (or another language). No more, no less...it should NEVER presume to add to what the programmer has requested, or ignore anything he commands.

    Oh, please. Do you realize how many optimizations your compiler is doing so that you don't have to write really frigging difficult to understand code? Do you *really* want to perform manual loop unrolling (which is easy, but looks ugly)? Find out every function that can be inlined and specify them as such? Array Value Propagation? Array Blocking?

    At least in the form of optimizations, if the programmer had to take care of things like these he'd have to make a choice between good, easily readable and maintained code, and fast code. And if you work in the real world, you know that you're not the only one actively maintaining your code. If the 10 other people working on it have to work hard to understand it, this wastes time, thus companies would be leaning towards the slow, but readable code. However, since the compiler recognizes that when you have your nice little loop performing matrix multiplication, you can actually get better performance by using blocking (performing operations on a small sub-matrix instead of going through rows and columns operations and thus reducing cache misses), you get the best of both worlds.

    1. Re:Do you know what you're talking about? by Brandybuck · · Score: 1

      I'm not talking about optimization. That's a given. It's what I explicity instructed the compiler to do since I used teh -O3 switch.

      I'm talking about the compiler guessing what the programmer really meant. That's not its job. Its job is to do what the programmer told it to do. The original post bemoaned the fact that programmers are using patterns of abstractions instead of relying on the compiler to do it for them. Well maybe, just maybe, I want a pattern of abstraction that's different than what his proposed compiler would give me.

      --
      Don't blame me, I didn't vote for either of them!
  86. Read Stroustrup's Design and Evolution of C++ by ChaosDiscord · · Score: 3, Interesting

    If you hate C++, it's unfair to suggest you read a book on it. But if you have any fondess for C++, or use C++ (even if you dislike it), Design and Evolution of C++ is probably worth your time. You learn why C++ is the slightly confusing mess that it is, and why Stroustrup believes it's the only way it could have succeeded. Having a grasp on why C++ is C++ (and not Objective C or Java) can improve your C++ coding abilities. And understanding why behavior you don't like is there can at least help minimize the suffering ("This is stupid, but there really isn't any way to change it.").

  87. Bjarne is the best. by Anonymous Coward · · Score: 0

    Dr Stroustrup is one of the most intelligent people on Earth, and C++ is the most powerful language ever invented.

  88. You don't have to have a new file by Trinition · · Score: 1

    You don't have to make a new file for a 'struct' in Java. You can make Inner or Nested classes. And as another poster replied, you can just use public members.

    public class Outer {
    public static class MyStruct {
    public int x;
    public int y;
    } // Rest of Outer's body...
    }

    Perhaps your frustration with Java is misplaced?

  89. C++0x by Anonymous+Brave+Guy · · Score: 2, Informative
    'Read what he's written about the C++200x standards revision cycle.' OK, fair enough, you do have evidence. Got a link?

    I think perhaps there's a misunderstanding in the grandparent post. Stroustrup, and others on the standards committee, are on record as saying that they don't see the need for many language changes. They do, however, propose to make extensive library changes. Their reasoning is simply that there is likely to be more than one sensible way to approach topics such as, say, concurrency and synchronisation, and thus building them into the language itself is unduly limiting.

    If you go to Stroustrup's home page (sorry, don't have a link handy, but it'll easily Google) and then look for his comments on C++0x, I'm guessing the slides from his presentation describing the above are still available.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  90. "memory allocation problem" by pyrrho · · Score: 1

    well, you can mismanage memory. You can have too many references to an object and cause a "leak". Seen it.

    You can horrendously mismanage memory in Java, and are more likely to because of all the people telling you that you don't have to "worry" anymore.

    Hey, it was no worry, worrying about memory management is my job. And guess what, allocating and deallocating the bits is THE LEAST OF IT.

    I agree with everything else you say, e.g., algorythm design is the most important source of optimization.

    --

    -pyrrho

    1. Re:"memory allocation problem" by Godeke · · Score: 2, Insightful

      True, you can fail to release resources, but in many cases it is handled for you in garbage collected languages by scope. That transparent handling probably is a big source of problems for those unaware of the problems of holding on to references beyond the scope necessary, but what I was refering to was the fact that I can't easily set a pointer up that points to incorrect memory locations and causes a subtle, usually non repeatable, near impossible to find bugs. Granted, tools like bounds checking software can help, but if I take a pointer to an object and then allocate some other objects and release a few, in C or C++ I can easily clobber my earlier object, causing modifications to it to do nearly random changes to other objects. Especially if you have a couple levels of indirection going. Maybe I just suck, but I have blown past the ends of arrays of more times than I probably should admit.

      --
      Sig under construction since 1998.
  91. we gots... by pyrrho · · Score: 1

    ... a couple registers in our 6502.

    --

    -pyrrho

    1. Re:we gots... by DrVxD · · Score: 1

      And more adressing modes than you can shake a stick at ;)

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    2. Re:we gots... by pyrrho · · Score: 1

      the serious part of this is that I suddenly think playing with 6502 is a great way to start programming for real, machines still work more or less the same way just with more magic addresses that control better hardware. The apple //e emulators are perfectly sufficient for this. And come on, wouldn't we be better off if all programmers had the experience of programming by entering numbers directly into the Apple "monitor"?

      --

      -pyrrho

    3. Re:we gots... by DrVxD · · Score: 1

      The 6502 was a great processor, don't get me wrong. I learnt an awful lot writing code for one of those in the days when we had 256 bytes of RAM to play with...(no fancy Apple //es in those days lol).

      But it's kind of irrelevant for todays processors, mostly because of the myriad adressing modes - most modern CPUs have far fewer. Probably the Z80 or the 8080 might be a better place to start. (The Z80 is another bit of silicon that has a special place in my memories...I still have both the Zaks and Leventhal "bibles" for both the Z80 and the 6502 :)

      But yes, we'd be far better off if more programmers actually knew how a microprocessor does what it does. I always find it hilarious how much difficulty some people have with coming to terms with (say) pointers in C - because they don't really have a grasp of what an "address register" is.

      Ah, those were the days...

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
  92. source code by pyrrho · · Score: 1

    I think programmers are getting a bet self indulgent. Two languages are equivalent in some respect if the syntax of the source is equivalent!?!?

    How about comparing what they compile to? Just to humor the old-school?

    --

    -pyrrho

    1. Re:source code by X · · Score: 1

      This specific thread was talking about syntactical issues, so "equivalance" was meant in that context.

      In a lot of ways, for a lot of projects, developer time is really far more important than execution time (I say this working in an environment where that is not always true). So, sometimes people do focus on the development ease side of things.

      Honestly though, assuming you're compiling to byte-codes in Java, a comparison with C++ is pointless. Even when you look at what a JIT produces, or a binary compiler, in a lot of ways the Java runtime is just so dramatically different than the C++ one that meaningful comparisons are difficult.

      --
      sigs are a waste of space
    2. Re:source code by pyrrho · · Score: 1

      ok, you're right, in context it was fair to focus on source.

      and I agree about developer time being important. However, the idea that Java saves developer time is a promise I have yet to seen proven. Just like "Java can run fast as C" is a promise I've heard but not seen proven.

      The comparisons are possible, but you are right, it won't be the compiler output, because one compiler is creating output that is nothing but data to the real program, the VM.

      The real contest is the built-at-compile time and built-for-the-task-at-hand programs created with C/C++ vs the VM. C++ source compiles to a program, it has to be compared with another program. That program is the VM. The question is, can your VM, a program that is designed to be able to do anything, ever really compete with C++ programs which are designed to do a specific thing?

      --

      -pyrrho

    3. Re:source code by X · · Score: 2, Informative

      I develop in both C++ and Java, and while I like both, it's pretty obvious to me that particularly for Junior and Intermediate level developers, Java development is significantly faster. Java's execution model also makes it much easier to design, implement and use frameworks and libraries. This in terms leads to faster development as well.

      While for certain types of problems (for example anything requiring unsigned arithmetic), it's very difficult for Java to outperform C, in other cases I've seen computationally intensive Java code that was written in a few days get within 10-20% of the execution speed of C code that was written in a month (and this was prior to JDK 1.4). That level of performance difference, particularly with reduced development times (which give you more time to improve the efficiency of the overall design) makes Java a worthwhile candidate for a large chunk of the projects out there.

      The sad truth is, a lot of C++ programmers are *not* at the skill level Bjarne is talking about. If even most C++ programmers were at that level, you'd suddenly find that C++ is a far better language to work with. Until programmers reach that level, it is a needlessly complex language which provides few useful advantages over it's competitors.

      --
      sigs are a waste of space
  93. Re:Invariant/struct discussions and binary compati by soft_guy · · Score: 1

    Yeah. I think he's talking about within an app or module. If you need binary compatibility, then you need to start looking at some of the COM - like abstractions, what they do, and why.

    --
    Avoid Missing Ball for High Score
  94. Re:OOP IS FOR PUSSIES by Anonymous Coward · · Score: 0

    No silly, it's "down with OPP".
    Yeah, you know me.

  95. bravo by DrEasy · · Score: 1

    My thoughts exactly!

    The interview changed my mind about C++. Before, I felt that it was only my ineptitude that made it hard for me to create classes in C++. Now, I understand that I may not be alone in my ineptitude (being part of the "rank and file" as you nicely put it), and that there is nothing wrong with using C++ simply as a way to access nice higher-level libraries and ADTs that couldn't have existed in pure C.

    If a purer OO approach is needed, then just use a pure OO language instead! (insert Ruby/Smalltalk/... based on your religion)

    --
    "In our tactical decisions, we are operating contrary to our strategic interest."
  96. Two words: code reviews by Anonymous Coward · · Score: 0

    Do them, and do them properly, and the problem is largely mitigated. Add to that a reasonable overall process, and you will be in good shape.

    If management doesn't want to invest the time and resources necessary to develop good code... well that's a management decision and they should be willing to accept the consequences. In reality they management never takes the blame, it's always those damn lazy, sloppy engineers.

  97. Sorry, but you're simply wrong. Here's the code. by Anonymous Coward · · Score: 0

    First off, you don't need a separate file to make a Java class. Secondly, making a separate Java class is not "a whole lot of extra code".

    public class myStruct
    {
    public String name;
    public int address;
    }

    How exactly is that any more code than with a struct? I'm afraid I don't see any merit in your claims.

  98. C++ is too simple. by rice_burners_suck · · Score: 2, Funny
    improving the style of C++ programming

    What C++ really needs is more features... LOTS more features. The language is not "rich" enough. C++ should add many other features to its syntax.

    • For example, the ability to name identifiers with any character in any character set.
    • As C++ is not complicated enough, we need a way to dynamically create syntax. It would work like operator overloading, but much more complicated. And it would be called Syntax Overloading. For example, the code, ("for (" class "in" class ")")() { [insert code here] } would allow you to specify a new type of for loop with your own syntax. The compiler, upon reading this line, would add the new syntax to its language rules. Then, you could type for (className in otherClassName) { some.code.here(); } and it would work as expected.
    • The language desperately needs some built-in cryptography functions. For example, the function const unsigned void do_it(const unsigned short void const crypto % arg) takes one parameter, arg, which is encrypted inside a processor register and cannot enter main memory for security reasons.
    • More complicated template syntax is needed. For example, suppose you want to create a class that is unknown at compile time... obviously, a way to specify runtime template processing is desperately needed.
    • Support for returning multiple return values from a function. For example, the function const unsigned short, const int *, const long long grok_the_file(void) might return three different return values, seperated by commas, as in, return i, j, size; Oh yeah, and you could specify functions that return an unknown number of values using ellipses, as in unsigned short... function_name() or simply ... function_name(). Suppose you want to call a funciton that takes 3 parameters... you could instead pass it one function that returns 3 return values and C++ would know what to do with it.
    • C++ needs a reserved word, like please_reconsider_cast, or something, that uses common sense to figure out what the heck you're trying to typecast into what, so that even if the code is faulty, the compiler will figure out what you really mean.
    These are all just a drop in the bucket. C++ is obviously too small and simple of a language.
  99. You must understand what the compiler does! by egoots · · Score: 1

    One of the challenges of C++ as a programming language, is that it requires the developer to truly understand what the compiler is doing or going to do in various conditions. In fact. there are many cases where you need to know what a compiler will do when you dont do something (e.g. when you dont write a copy constructor).

    I cannot think of a another programming language that does this to the same degree.

  100. self-discipline by pyrrho · · Score: 1

    no, that doesn't mean you suck. However, if you have the self-discipline to change languages over such issues, why not use a pointerless paradigm and appropriate class systems in C++.

    In other words, what's wrong with C++ that a good class system doesn't answer? And why redeem C++ this way? Because of it's no-overhead philosophy --- that is, if you love garbage collections, a C++ garbage collecting class is going to be more efficient and more tunable to your particular needs. Why not use that if the result is more efficient?

    As you point out, the tools to find memory leaks are quite mature and plentiful. The tools to avoid them, patterns of development, are equally mature. I think it's useful to learn them. Running away from them cannot succeed, as the issues are those of basic logical style. Open paren, close paren. Open bracket, close bracket. Allocate, Free, New, delete. This bookending of control is ubiquitous. When you allocate something, you have to free it. In java this means setting the reference to null, not thinking about it is a recipe for disaster.

    It's been a long time since I've blown past the end of an array is use the standard vector class now.

    --

    -pyrrho

    1. Re:self-discipline by Godeke · · Score: 1

      To be honest, modern C++ could probably achieve what I do in other languages. When I first tried to adopt C++, STL was a pathetic wreck in terms of both implementation and features. MFC (being that I programmed for Windows at the time) probably scarred me for life.

      I found coding muds in stock C with function dispatch tables more productive than the early rounds of C++ via classes. When work pushed me hard into data driven corporate applications, there was just not a lot of need for C style programming in my work. Maybe someday I will need to do system level or game programming again and I will have to opportunity to relearn C++ from a fresh perspective. At this point however, people pay me to do business logic object at a rapid clip, and C++ just doesn't seem like the best solution for that problem.

      --
      Sig under construction since 1998.
  101. learn logic... by pyrrho · · Score: 1

    and be multiparadigmed, and you shall be the light.

    --

    -pyrrho

  102. invariants by pyrrho · · Score: 1

    the key to what C++ gives you is in Stroustrups comments one enforcing invariance. C is missing some syntax that helps one accomplish this.

    --

    -pyrrho

  103. More like a gun by GunFodder · · Score: 1

    Statistically speaking there is danger in allowing a car to exceed the speed limit, but that danger is difficult to quantify and it may very well be exceeded by the improvement in travel efficiency when folks speed.

    OTOH a pistols generally tend to hurt more people than they help. Some people successfully defend themselves from other people (with guns), but the more frequent scenario is that someone carelessly leaves their gun unsecured and an inexperienced user hurts or kills themselves with it. C/C++ is more like that gun. There are systems programmers that really need the extra speed, but most people, like Homer Simpson, use it to turn off the lights or open a beer. They would be better served with a safer, more featureful language like Java.

    1. Re:More like a gun by Curien · · Score: 1

      And the far, *far* more frequent scenario is that the gun owner safely uses his gun at a target range, maybe taking it once or twice a year for some real hunting, never hurting anything but deer and bales of hay.

      Jesus, read what you wrote! Do you really believe that a gun is *more frequently* used dangerously than safely?

      --
      It's always a long day... 86400 doesn't fit into a short.
  104. it would look like C by pyrrho · · Score: 1

    but with '//' comments.

    why? C is a paradigm available in C++ and if it's really best, it is available.

    Of course, no doubt, a few contructors and other lightwieght C++ idioms would sneak in, becuase they introduce no overhead.

    --

    -pyrrho

  105. "multiparadigmed" by pyrrho · · Score: 1

    C++ is not an object oriented language, it's a multiparadigmed language with some OO idioms available for the paradigm you use in the end.

    even the standard library is not object oriented.

    --

    -pyrrho

  106. it just shows by pyrrho · · Score: 1

    the vector is not as basic as you seem. The array, with no bounds checking is primative, vectors, which resize and guard their bounds are not as primative, and there are many ways to do this.

    Besides, many people consider something that is a part of a languages standard library as part of the language. I'm with you though, and vector was worth having when it was separate, and part of the STL.

    --

    -pyrrho

  107. compromise by pyrrho · · Score: 1

    I see what you are saying. I came to C++ the "easy" way... I programmed in C and slowly adopted C++ idioms that made sense (I still am not fond of iostream classes). So for years I did not use exceptions or template classes. I have only in the last couple of years started using STL in earnest, now that it's settled down.

    Even though the compilers have mostly caught up to the language, I still think this is the way to go with C++... you don't use C++ full bore using all it's fun idioms, C++ is multiparadigmed, your program isn't supposed to be. Even with good compilers you need to limit yourself to the tools C++ offers that fit your problem domain.

    PS: there is little doubt in my mind that the VM is becoming specialized, and if it becomes specialized then it really can outperform a compiled language IN is special domain. The domain of Java is Busines To Business, and it's so well supported in that sphere, even I would not argue that it's not becoming the best platform for the kind of applications you mention.

    cheers.

    --

    -pyrrho

  108. Mod parent up: Invariant/struct discussions and b by stock · · Score: 1

    This indeed a very important issue on linux.

  109. April Fool, from Stroustrup by devphil · · Score: 1


    Go to his homeoage, find the list of publications, and read the article that he published on April 1st, back in '96 or so. It's six pages of extraordinarily wacky stuff written in a completely serious tone. (Until the very end.)

    Like, we can now assume that every computer display is capable of at least 256 colors, so make the color of the identifier part of its name. I.e., "int i;" in a red font is a different entity than "int i;" in a yellow font, even though they're in the same scope.

    This is the same paper that proposes to overload whitespace.

    --
    You cannot apply a technological solution to a sociological problem. (Edwards' Law)
  110. Don't mod grandparent up by Anonymous Coward · · Score: 0


    If an issue with a language happens is a deployment issue specific to a particular OS, then it normally indicates a questionable software design in first place .. which in turn means that application in question misuses both the platform services and the language itself.

  111. Re:Who is Bjarne Stroustrup? by Anonymous Coward · · Score: 0

    Minor bug in your code: DS not loaded.

    mov ax, @data
    mov ds, ax
    mov cx, 10
    mov di, offset dsarray
    mov ax, bndmp
    cld
    rep stosw

  112. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  113. SIR HAXALOT IS A KNOWN TROLL AND KARMA WHORE! by Anonymous Coward · · Score: 0
    Shut the fuck up, Sir Haxalot.

    Stop posting as an AC to try to get karma.

    Your question is complete nonsense.

  114. Comeau is for Pussies by Anonymous Coward · · Score: 0

    It's a C++ to C covnerter which uses gcc/msc/bcc or whatever as a backend. Why would you want to use comeau when you have g++, escapes me. Obviously, "export" is too trivial. If it was of any practical use, it would have been implemented in g++.

  115. magic programmer education by pyrrho · · Score: 2, Insightful

    I think you make an interesting point about a lot of this depending on the quality of C++ programmer, and I would extend that to admit that there are certain level of programmer that will always need a simplified environment, and that's fine.

    But for professional developers, wouldn't it be best if we just focussed on making he best tools and educating our industry to use them properly?

    I mean, if you look, there are a lot of tools of convienience in the hardware store that professional builders don't use. You can duct tape something and it's good to go, but that's not what you train engineers... though they might use duct tape in a pinch.

    I think you might be onto something about Java for newer programmers. I already have learned about all the things Java is to save me from, like the ins and outs of memory management, so I don't notice an speed up when I code in Java. The kinds of bugs I have to hunt in my stuff is not particularly addressed, and can't really by, by any language.

    If a java program was written in a couple days, and the C equiv in a month... that implies something. There is not that much difference in the language. That sounds like library availability, the C programmer had to write something that was already available in Java, which begs the question... was there a good library available they didn't know about and could they have used C++. The 10% would still make it a better tool and worthwhile.

    But where we really will probably have to agree to disagree is just on the "needless complexity" issue. That needless complexity is C++ giving you more than you need --- so you can decide what you need and have a wide range of paradigms under which you can code. That is C++ not trying to second guess for you. If C++ give an automagical solution, it also give no-solution so you can build your own automagic. If you don't like cout, there is still printf and if you don't like exceptions, it's up to you and your Coding Standards to decide is you have to use them.

    It's that old choice vs. chaos. Personally, I can handle the chaos of choice.

    --

    -pyrrho

    1. Re:magic programmer education by X · · Score: 2, Interesting

      It wasn't a library that really saved the Java project so much time. Indeed, because of performance considerations, the standard Java collection classes weren't used. No, the faster development time came from the fact that the C code had to deal with a lot of ownership and synchronization issues, much of which is quite error prone in C. Java's runtime simplifies these issues (and amazingly does it in a way that tends to be faster than what C can do without a LOT of work) such that you don't waste a lot of time on them.

      The complexity doesn't just stem from having choices. It's from exposing problems to the programmer that they fundamentally don't understand yet. Dealing with templates in a world where you don't understand generic programming is going to do more harm than good. Dealing with exceptions in a world where you don't understand RAI. Dealing with multithreading in a world where you don't understand how the C++ memory model doesn't grok threads. I could go on.

      I've interviewed "senior" programmers a fair bit, and I'm invariably struck by how many of them (basically all) can't do something as simple as a thread-safe getter/setter in C++, but even the more junior programmers can get it right in Java on the first try. These are the kind of mistakes that literally steal weeks of productivity.

      Sure, you can simply not use all those features, as a lot of C++ programmers do, but the end result is a crippled language that has most of the disadvantages of Java, without any significant advantages over C or Java. This is exactly the scenario where C++ turns out to be a poor choice.

      I think rather than hardware store metaphor, I'd suggest something along the lines of mountain climbing. Free climbing is the "cool" thing to do, and it has certain advantages over the "safer" approach, however the vast majority of folks out there shouldn't do it, as sooner or later it will do more harm than good.

      --
      sigs are a waste of space
  116. at the risk of belabouring this by pyrrho · · Score: 1

    I've interviewed "senior" programmers a fair bit, and I'm invariably struck by how many of them (basically all) can't do something as simple as a thread-safe getter/setter in C++, but even the more junior programmers can get it right in Java on the first try. These are the kind of mistakes that literally steal weeks of productivity.


    but aren't you implying we baby this condition? These guys are frauds. They need more education. They could get that education on-line! They could get it from good books. Amazon can even lead them to good books (if they know one good book).

    Programming in C may be like free climbing, but C++ isn't... that's the point of contructors and the class idiom in C++... ropes and wedges and all the rest. You don't have to touch a pointer in C++.

    I think people are objecting (I don't know about you) to the fact that you are ALLOWED to free climb in C/C++... but they claim you HAVE to. :)

    --

    -pyrrho

    1. Re:at the risk of belabouring this by X · · Score: 1

      It's not that they didn't know how to do it, it's that doing so in C++ is quite error prone, and they simply did not cover all their errors.

      It's true that C++ provides you with constructs that make life a lot easier than C. The whole point of this discussion though is that unless you understand how to use those constructs, you'll frequently find C++ to be a far less effective tool that other alternatives.

      --
      sigs are a waste of space
    2. Re:at the risk of belabouring this by pyrrho · · Score: 1

      I guess my argument is that there is no excuse for not understand contructors.

      C++ gives you a place to hide the "hard" and "error prone" parts, and in fact, others can cover that and you can use any of a wide range of classes to hide that word. You can use a pointerless paradigm in C++.

      Fact is, most don't do that because it's overkill, it's NOT hard to manage memory in C++ compared to C, and pointers are not so hard to understand. And freeing memory is no more complicated a responsibility than closing scope.

      --

      -pyrrho

  117. Re:Improvements? (some people... 8-) by IBitOBear · · Score: 1

    Er, rtfa? If you follow his very first recomendation and use the STL for vector and string (correctly) then you won't overrun.

    --
    Innocent people shouldn't be forced to pay for inferior software development.
    --"Code Complete" Microsoft Press
  118. what it really needs by Anonymous Coward · · Score: 0

    is a big fat I-can-do-anything Virtual Machine to slow it down, remove power, and slow it down without giving any noticeable benefits.

    Luckilly Microsoft has given us this.

  119. Multithreaded applications? by Anonymous Coward · · Score: 0
    If your application is multithreaded and it is possible for the class to be accessed by more than one thread sumultaneously, then you have two choices:
    1. x->lock(); x->foo = "bar"; x->unlock();
    2. x->set_foo("bar"); /* atomoic lock, set, unlock */
    I highly recommend using the second method unless you have a performance-critical reason to try using the first method.
  120. agreed by pyrrho · · Score: 1

    I started programming in Apple Basic. Within six months it was 6502. Pointers made perfect sense to me. I am baffled why people find them confusing.

    Of course there are difficulties handling pointers, but mostly because we use so many of them... conceptually it's not difficult.

    PS: You had 256 whole bytes of ram? why back in my day... oh no wait, you've got me beat.

    --

    -pyrrho