Slashdot Mirror


Bjarne Stroustrup Reveals All On C++

An anonymous reader writes "Bjarne Stroustrup, the creative force behind one of the most widely used and successful programming languages — C++ — is featured in an in-depth 8-page interview where he reveals everything programmers and software engineers should know about C++; its history, what it was intended to do, where it is at now, and of course what all good code-writers should think about when using the language he created."

96 of 371 comments (clear)

  1. Oh... my... god... by Anonymous Coward · · Score: 3, Funny

    C++ is a woman?! I didn't see this coming.

    1. Re:Oh... my... god... by Anonymous Coward · · Score: 5, Funny

      It shouldn't be that surprising. The new operator should have given it away. After all, in C++ you can create objects (children) that consume resources and don't clean up their garbage. The secret to how it works is that C is a man.

    2. Re:Oh... my... god... by PPH · · Score: 2, Funny

      Is that you, Verity Stob?

      --
      Have gnu, will travel.
    3. Re:Oh... my... god... by mav[LAG] · · Score: 4, Funny

      C++'s social life is a bit weird as well: I hear that friends have access to your privates.

      --
      --- Hot Shot City is particularly good.
  2. Normal Read by MoonlightSeraphim · · Score: 5, Informative
    1. Re:Normal Read by Anonymous Coward · · Score: 3, Funny

      Where is the printf() version?

    2. Re:Normal Read by Chris+Mattern · · Score: 3, Funny

      You mean the cout version, noob!

  3. Interesting Read by dreamchaser · · Score: 5, Informative

    It's always cool to see this kind of interview. It's even cooler when you can read it all on one page rather than 8.

    I suggest that anyone who uses C++ or is interested in the history of programming read this. Some of it is a bit banal, like how they chose the name, but some of it is really intersting. RTFA for once, you lazy clods!

    1. Re:Interesting Read by morgan_greywolf · · Score: 5, Funny

      RTFA for once, you lazy clods!
      Hey! I'm illiterate, you insensitive clod!
    2. Re:Interesting Read by afidel · · Score: 5, Interesting

      I was kind of interested in the comment that C++ required a proper compiler rather than just a pre-processor macro package. From the fog of my memory I remember many of the early commercial C++ offerings being mostly a pre-processor package, were those really just C with Classes compilers rather than true C++ ones?

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    3. Re:Interesting Read by c · · Score: 3, Informative

      Early C++ "compilers" usually did more than just macro processing, but only just; most of them were implemented in terms of translating C++ to equivalent C code and then compiling the resulting C. Not so elegant, but it allowed compiler vendors to pick the low-hanging fruit and get something on the market ASAP.

      It wasn't just commercial compilers, either. g++ worked that way.

      Of course, it goes without saying that these early C++ compilers sucked hard.

      c.

      --
      Log in or piss off.
    4. Re:Interesting Read by rbanffy · · Score: 2, Interesting

      "that's no longer possible."

      Remember... This is Slashdot. Comments like these may have unintended consequences when made here.

      It's, of course, possible to build a CFront-like preprocessor that converts current C++ code into C. It's not easy and the C code would probably be even less readable than what CFront wrote. It's not practical either. Or wise.

      But it's certainly possible.

    5. Re:Interesting Read by c · · Score: 3, Interesting

      > Aren't you just a bit biased?

      If you're gonna be pedantic, it's a lower-case 'c'.

      But I'll freely admit to being biased. I've spent my time in the C++ trenches. C isn't a terribly good language, but when you shoot yourself in the foot it's usually a clean wound.

      c.

      --
      Log in or piss off.
    6. Re:Interesting Read by Mikkeles · · Score: 4, Funny

      Hey! I'm illiterate, you insensitive clod!

      As are most c++ programmers.

      --
      Great minds think alike; fools seldom differ.
    7. Re:Interesting Read by shutdown+-p+now · · Score: 2, Informative

      For the record, the first C++ compiler that compiled directly to native code was Zortech C++ (which beget Symantec C++, which beget Digital Mars C++). Its author, Walter Bright, is the guy behind D programming language.

    8. Re:Interesting Read by hitchhacker · · Score: 2, Informative

      C isn't a terribly good language, but when you shoot yourself in the foot it's usually a clean wound. From TFA:

      "C++ makes it harder to shoot yourself in the foot; but when you do, it takes off the whole leg" is sometimes quoted in a manner hostile to C++. That just shows immaturity. Every powerful tool can cause trouble if you misuse it and you have to be more careful with a powerful tool than with a less powerful one: You can do more harm (to yourself or others) with a car than with a bicycle, with a power saw than with a hand saw, etc. What I said in that quote is also true for other modern languages; for example, it is trivial to cause memory exhaustion in a Java program. Modern languages are power tools. That's a reason to treat them with respect and for programmers to approach their tasks with a professional attitude. It is not a reason to avoid them, because the low-level alternatives are worse still.
      -metric
    9. Re:Interesting Read by Anonymous+Brave+Guy · · Score: 2, Funny

      Oh know were not.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  4. Humour by morgan_greywolf · · Score: 2, Funny

    I needed a tool for designing and implementing a distributed version of the Unix kernel. At the time, 1979, no such tool existed. I needed something that could express the structure of a program, deal directly with hardware, and be sufficiently efficient and sufficiently portable for serious systems programming.
    I take it Bjarne hasn't used KDE.

    (C'mon KDE guys, it's funny. Laugh.)

    1. Re:Humour by Rob+Kaper · · Score: 3, Insightful

      The pun seems to be that KDE isn't structured, efficient, portable or serious, despite being written in C++. I can't blame you for missing it, or finding it not funny.

  5. yawn by Anonymous Coward · · Score: 4, Insightful

    C++ is a language of a million gotchas. The moment I start having to think about implementation detail and I'm not writing an operating system or compiler, I know I'm using the wrong language.

    1. Re:yawn by gbjbaanb · · Score: 2, Insightful

      then you're going to have a hard time of programming, perhaps you'd be happier being the Boss.

      All languages have "implementation details" and various gotchas. Look on any programming forum for any language and you'll see tips and tricks in using it. I think you're in the wrong job.

    2. Re:yawn by Chemisor · · Score: 3, Insightful

      > C++ is a language of a million gotchas.

      Whenever you want to use a language, you must learn it first. That's true even of Visual Basic. The reason you see those problems of yours as "gotchas" is that you don't understand how the language (and, in the case of C++, the computer) works. If you let the language shape your thoughts instead of trying to cram your crummy thoughts into C++, it would have been much easier and simpler for you.

      > The moment I start having to think about implementation detail, I know I'm using the wrong language.

      In other words, you don't want to know how your program really works. A fine attitude for a PHB. I suggest you switch to english.

    3. Re:yawn by Anonymous Coward · · Score: 2, Insightful

      You evidently either (A) don't know thing one about C++ or (B) FAR FAR FAR worse, you do think you know about it.

      Next time you're in a bookstore, browse through Scott Meyer's "Effective C++" books.

      They're basically a huge list of comments to the effect of, "Gee, you THINK you can do X because it's perfectly legal syntax and it makes sense because you do X in other object-oriented languages, but in C++ it either fails outright or its undefined behavior in the language, so it will fail at the worst possible time in the worst possible way".

      For example, if you declare even one virtual member function, you HAVE to declare your destructor virtual. Ummm, what? Don't I get some help from the compiler?

      This, most emphatically, is not "you let the language shape your thoughts", this is psychosis.

    4. Re:yawn by clickety6 · · Score: 2, Insightful

      >> The moment I start having to think about implementation detail, I know I'm using the wrong language.

      > In other words, you don't want to know how your program really works. A fine attitude for a PHB. I suggest you switch to english.

      When I'm driving my car and I turn the steering wheel right, I expect the car to run right, without having to think about exactly how all the rods and pinions and bearings and whatever are making the car turn right. Sure, I need to know that the more I turn the steering wheel, the tighter I turn, but that should be it. Why should a programming language force me to think about low level implementation details that are nothing to do with the algorithm I'm trying to write?

      --
      ----------------------------------- My Other Sig Is Hilarious -----------------------------------
    5. Re:yawn by iMaple · · Score: 2, Insightful

      When I'm driving my car and I turn the steering wheel right, I expect the car to run right, without having to think about exactly how all the rods and pinions and bearings and whatever are making the car turn right. Sure, I need to know that the more I turn the steering wheel, the tighter I turn, but that should be it. Why should a programming language force me to think about low level implementation details that are nothing to do with the algorithm I'm trying to write? It is nice to know when you are driving the car that if there is snow or an oil slick or a flat your turning response would be different. You don't have to know how the steering works, but know a few things more than just rotate the wheel right are useful when you want to do anything non-trivial. And just like programming you will learn these things by experience (if u don't get into any serious crashes).
    6. Re:yawn by larry+bagina · · Score: 4, Funny

      Why don't you ride the bus? You wouldn't need to even think about steering at all!

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    7. Re:yawn by Rocky · · Score: 2, Funny

      Be careful - you should Turn Left. Turning right may make you dissolve into little fat monsters.

      --
      "I'm an old-fashioned type of guy. I worship the Sun and Moon as gods. And fear them."
    8. Re:yawn by khchung · · Score: 2, Insightful

      Whenever you want to use a language, you must learn it first. That's true even of Visual Basic. The reason you see those problems of yours as "gotchas" is that you don't understand how the language (and, in the case of C++, the computer) works. If you let the language shape your thoughts instead of trying to cram your crummy thoughts into C++, it would have been much easier and simpler for you. I used to think like that when was still a C++ programmer, until one day I read an FAQ somewhere that details the possible differences between "f(a++)" and "f(a); a++;". That's when I saw the light and seriously switched to Java. I think when a normal person looking at a normal piece of code cannot know what it will do, there is something wrong with the programming language.

      Quick question (which I always used to interview candidates claiming familiarity with C++):

      What, if any, are the differences between 2 programs, one using "f(a++)" and the other "f(a); a++;"? For added fun, also compare "f(++a)" and "++a; f(a);".

      Hint: If you answer "no difference" you don't know enough about C++.

      More hint: there are at least 2-3 ways where the result of the program can differ significantly, depending on the signature of f(), the actual type of a, how is operator ++ defined for that type, etc.

      --
      Oliver.
    9. Re:yawn by Samrobb · · Score: 2, Informative

      For example, if you declare even one virtual member function, you HAVE to declare your destructor virtual.

      I don't know where you got this idea. If you have virtual member functions, you probably want a virtual destructor, but it's neither a requirement, nor a given.

      From the C++ FAQ lite, read [20.7] When should my destructor be virtual?

      --
      "Great men are not always wise: neither do the aged understand judgement." Job 32:9
    10. Re:yawn by shutdown+-p+now · · Score: 3, Informative

      All languages have "implementation details" and various gotchas.
      It's true, but some have more, and others have less, and C++ is on the "a fucking lot" end of the spectrum. Of all the languages I know, the only one that has more (mostly because it covers a lot more ground) is Common Lisp.
    11. Re:yawn by bigstrat2003 · · Score: 2, Insightful

      Oh, java must be crap because you can't tell, right? It's pretty damned easy to tell what should happen. f(foo(a)); should run f on the return value of foo(a). f(a); foo(a); will depend on the specific functions involved (and whether a is passed by reference or value), so it isn't the language's fault if your example is bad. In the c++ example, the expected behavior is clear: f(a++) should be the same as f(a); a++; because it's a postfix increment. If the actual behavior doesn't match that, that's C++'s fault. Likewise, if the Java behavior doesn't match what's logical, that's Java's fault.

      Also, saying "Java sucks too so that makes C++ not suck" doesn't hold any water. If C++ sucks, and Java sucks too, they both suck, C++ doesn't magically become ok. It's not like C++ sucking depends on Java not sucking.

      --
      "16MB (fuck off, MiB fascists)" - The Mighty Buzzard
    12. Re:yawn by Chemisor · · Score: 2, Insightful

      > When I'm driving my car and I turn the steering wheel right, I expect the car to run right, without having to think

      That's what I would expect when using your software, because that is the proper analogy to driving the car. Programming is more like designing the car, and yes, you do want to know what the steering wheel does. What if car designers just had little modules described as "this thingy makes the car turn right"? Then they would just snap the parts together and secure them with duct tape. Would you drive a car designed in this manner? I thought not.

    13. Re:yawn by Plutonite · · Score: 3, Insightful

      This is the problem with people who don't know how to appreciate C++ capabilities. Do you even know why a "virtual" declaration on a method may be useful, or what it does internally? The whole idea is that you write code that can call methods named in a base class but defined in a derivative (child), via pointers. So, if you want to keep your code clean, you just have one line like:

      Parent *p = new Child();

      and the rest of the "user" code stays the same. You change the one line above to change functionality of every virtual method.

      Now since destructors are called implicitly most of the time, and since you OBVIOUSLY DECLARED VIRTUAL METHODS FOR A REASON, the compiler will warn you if the destructor is not virtual too, because then the object will be destructed as if it is a Parent object. It is a very valid warning, and will save you memory leaks(child objects contain more stuff to be freed..etc). It all makes sense now, see. The compiler is being nice, yes? Do you not agree that you should be blushing, after accusing the heavenly father Stroustrup of psychosis?

      Advice for life in general: If you don't know how to use something, don't use it ;)

    14. Re:yawn by ultranova · · Score: 3, Insightful

      When I'm driving my car and I turn the steering wheel right, I expect the car to run right, without having to think about exactly how all the rods and pinions and bearings and whatever are making the car turn right. Sure, I need to know that the more I turn the steering wheel, the tighter I turn, but that should be it. Why should a programming language force me to think about low level implementation details that are nothing to do with the algorithm I'm trying to write?

      Because a programmer is a car designer, assembler or a mechanic, depending on his specific job description. The user of the program is analogous to the driver of a car.

      If you want to be a car mechanic, you'd better learn how cars work. If you want to be a programmer, you'd better learn how programs work. You'd think this would be bloody obvious, but oh well...

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    15. Re:yawn by pigwin32 · · Score: 2, Funny

      Umm, QED?

  6. everything programmers should know about C++? by OglinTatas · · Score: 5, Funny

    in an 8 page interview? I feel like a sucker for buying the 900 page book

    1. Re:everything programmers should know about C++? by linal · · Score: 2, Funny

      Just be thankful you didn't buy this book
      http://www.amazon.com/gp/product/1418499757/ref=cm_rdp_product

    2. Re:everything programmers should know about C++? by 192939495969798999 · · Score: 2, Funny

      Yeah, he is apparently very good at refactoring.

      --
      stuff |
    3. Re:everything programmers should know about C++? by GeckoX · · Score: 2, Funny

      Yeah, but that's 8 pages of pointers into said book ;)

      --
      No Comment.
  7. And ... by LizardKing · · Score: 4, Informative

    ... for an equally partisan view from another perspective, the C++ FAQ.

    1. Re:And ... by Kamineko · · Score: 2, Informative

      In case anybody got confused, that's FQA above, not FAQ. This is FAQ: http://www.parashift.com/c++-faq-lite/index.html

    2. Re:And ... by Anonymous Coward · · Score: 4, Insightful

      ...it's largely a waste of time. The author spends an inordinate amount of time complaining that C++ prefers compile-time overhead to run-time overhead, and has no understanding that C++ is designed to have no unnecessary performance penalty relative to C. It would be nice if he did, as whatever insights the FQA author has concerning OO languages could be gleaned without wading through a few thousand lines of whining over the lack of things like garbage collection, heap compaction, run time bounds-checking, etc. He also has apparently never heard of Boost.

  8. Favorite line... by wiredog · · Score: 3, Funny

    programs in C++ could be simultaneously elegant ... and efficient for systems programming... Obviously, not every program can be both and many are neither

    Many are neither. Ain't that the truth.

  9. The name by Anonymous Coward · · Score: 2, Funny

    FTA they tried calling it C with Classes, but that didn't stick, so they asked for suggestions and got C++

    I think they should have called it Class-C. Much more fun to pronounce.

  10. The Truth about C++ by Anonymous+Admin · · Score: 5, Funny

    On the 1st of January, 1998, Bjarne Stroustrup gave an interview to the IEEE's Computer magazine.

    Naturally, the editors thought he would be giving a retrospective view of seven years of object-oriented design, using the language he created.

    By the end of the interview, the interviewer got more than he had bargained for and, subsequently, the editor decided to suppress its contents, for the good of the industry, but, as with many of these things, there was a leak.

    Here is a complete transcript of what was was said,unedited, and unrehearsed, so it isn't as neat as planned interviews.

    You will find it interesting...

    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 - re

    1. Re:The Truth about C++ by Anonymous Coward · · Score: 3, Interesting

      What a wonderful bit of fiction. I did find it entertaining, so thank you.

      I have worked with some very good programmers, and some mediocre ones. The very good ones usually liked C++, and often preferred it when given a choice. The younger (good) ones tend to go with C# these days, though they don't bad-mouth C++.

      It is always the mediocre ones who badmouth C++.

      That has just been my experience, I don't know if this is true across the board, but I do encounter this a lot. Average and below-average programmers hate C++ with a passion, whereas the really good ones like it (or at least respect it).

    2. Re:The Truth about C++ by Mongoose+Disciple · · Score: 3, Interesting

      Nice. If you don't like C++, it must be because you're a bad programmer.

      It's much harder to write C++ code that, for example, will never leak memory no matter what goes wrong than in the assorted garbage collected languages, or even vanilla C. That, I don't see how anyone could even reasonably argue.

      C++ was an important step on the way to better languages (for the problems it was trying to solve -- not for everything), but that doesn't mean that given today's alternatives it should be considered good.

      Being a good programmer is about being good at solving the problem at hand in a clean, maintainable way. It's not about being able to memorize the weird inconsistencies in a language or fight a better fight with a difficult language. Even for a project that has to be done close to the machine, you'll almost always get in less trouble using C. (Or, if you must, using C++ but generally ignoring the C++ features.)

    3. Re:The Truth about C++ by lefticus · · Score: 5, Insightful

      Yawn.

      If you don't like C++, you probably just don't understand it. Yes, it's a complex language. However, if you use RAII (a fundamental tenant of C++) you will not. leak. memory. ever. Same arguments about C++ are used over and over again by people who don't grok the language. Is it the end-all be-all language? No. But it is darn good at what it does (performance minded system level code) with almost none of the problems C has (memory leaks and weak typing).

    4. Re:The Truth about C++ by jamesswift · · Score: 3, Insightful

      It's much harder to write C++ code that, for example, will never leak memory no matter what goes wrong than in the assorted garbage collected languages, or even vanilla C. That, I don't see how anyone could even reasonably argue.

      Probably true. But what does that tell us about general language fitness really since it's equally as easy to hog resources in a language with GC? Database connections for example.

      When you absolutely need deterministic release of resources you end up having to approach the problem in a similar fashion to c++ memory management anyway.

      Many people believe seem to believe GC allows you to forget about resource management when it doesn't at all.
      It's a great tool for a certain class of problems but not a panacea.

      --
      i wish i could stop
  11. "What good progammers should think" by Anonymous Coward · · Score: 3, Funny

    and of course what all good code-writers should think about when using the language he created Let me guess. "How am I going to shoot myself in the foot today?"
  12. Re:Bjarne does.....what? by Anonymous Coward · · Score: 3, Funny

    Inaccurate. You forgot COBOL. But that's understandable, I want to forget it, too.

  13. Language stability by Yetihehe · · Score: 2, Interesting

    I wrote C++ code 20 years ago that still runs today and I'm confident that it will still compile and run 20 years from now.
    Funny thing, I tried to use some c++ code, but after one day and correcting about 300 errors (about 20 different TYPES of errors) I gave up and scraped the code (this was Object-Oriented RayTracer from Nicholas Wilt).
    --
    Extreme Programming - Redundant Array of Inexpensive Developers
    1. Re:Language stability by LizardKing · · Score: 2, Insightful

      Stoustrup probably means the binary still runs on the now antiquated system it was originally compiled for. I very much doubt he means that the 20 year old source code still compiles with a modern compiler, as the language has changed way too much. So, Stoustrup's probably being a little bit disingenuous as usual.

  14. Non Geeks by s31523 · · Score: 2, Interesting

    Everybody agreed that semantically ++C would have been even better, but I thought that would create too many problems for non-geeks. Um, how many non-geeks know anything about programming languages... Why worry about them.
  15. If you liked that, read "Design and Evolution"... by SuperKendall · · Score: 2, Informative

    The interview just seems like a very brief sampling of "The Design and Evolution of C++".

    Even if you do not care much about C++, it's an excellent look into the philosophy and thought that goes into language design.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  16. Use this link to read article on one page by Animats · · Score: 4, Interesting

    First, read the printable version of the article on one page. The original version is one paragraph per page, surrounded by ads and related dreck.

    There's really nothing new there. It's the usual Strostrup stuff. He's still in denial about C++ being the cause of most of the buffer overflows, system crashes, and security holes in the world.

    The fundamental problem with C was the "array=pointer" concept. If array sizes were carried along with arrays, we'd have far less trouble. Even FORTRAN has conformant array parameters. That should have been fixed in C++, but it wasn't, and as a result, we had two more decades of buffer overflow problems. This isn't a performance issue, by the way; Modula 3 got it right, but Modula 3 disappeared for non-technical reasons - Compaq bought DEC and closed down the software R&D operation.

    C++ is also the only language that has hiding ("abstraction") without memory safety. C has neither; almost all later languages (Java, Delphi, all the scripting languages) have both. C++ stands alone in this unsafe place. Nobody ever repeated that mistake. So subtly incorrect calls to objects can result in the object overflowing.

    Yes, some of these problems can be papered over with templates. The C++ committee is full of templateheads, focused on template features that few will use and fewer will use correctly and productively. That crowd is still struggling to make auto_ptr work.

    1. Re:Use this link to read article on one page by PhrostyMcByte · · Score: 4, Informative

      The developer should know if he'll need the size of an array or not. Which is why there is a convenient std::vector and std::tr1::array for when you do want the size. Not forcing you to carry around a size is a feature, not a bug - if you don't need the size, it's just a waste of space.

      And auto_ptr is likely to be depreciated in C++0x, with unique_ptr and shared_ptr replacing it.

    2. Re:Use this link to read article on one page by erikvcl · · Score: 2, Funny

      How is it Stoustrup's fault if people use the C features instead of the C++ ones? Your claim that Stroustrup is the "cause of most of the buffer overflows, system crashes, and security holes in the world." is absurd.

      You made this statement: "If array sizes were carried along with arrays, we'd have far less trouble". Array sizes ARE carried along with arrays. See the following code:

      #include
      #include

      int main(int argc, char **argv)
      {
                      const char str[] = "hello world";
                      const char *str1 = "hello world";

                      printf("array len: %d\n", sizeof(str));
                      printf("ptr len: %d\n", sizeof(str1));

                      return(0);
      }

      This code produces the following output:

      array len: 12
      ptr len: 4

      Arrays and pointers to character strings are not the same thing, though they are related and, in many circumstances, can be used interchangeably.

      It seems that you should learn more about C before you start criticizing C++. As others have stated, it's usually the mediocre programmers who complain about C++.

    3. Re:Use this link to read article on one page by Animats · · Score: 2, Insightful

      Array sizes ARE carried along with arrays.

      No, they're only available where the original declaration is visible. Try:

      void arraylength(int tab[])
      { printf("size of tab: %d\n",sizeof(tab)); }

      which won't work. "sizeof" is not meaningful in that context.

      Compare FORTRAN, which allows

      SUBROUTINE ARRAYLENGTH(TAB, N)
      INT TAB(N) ! conformant array declaration using param
      WRITE(*,*) SIZE(TAB) ! write size of array, as known by language

      This carries along the info needed for subscript checking. It also encourages users to request the size of an array from a known good source.

      The retrofit of conformant arrays into FORTRAN wasn't perfect, but it's ahead of C/C++. ISO Pascal, of course, also has conformant arrays, as do Modula 1/2/3, Ada, and Delphi.

    4. Re:Use this link to read article on one page by shutdown+-p+now · · Score: 2, Informative

      C++ is also the only language that has hiding ("abstraction") without memory safety. C has neither; almost all later languages (Java, Delphi, all the scripting languages) have both. C++ stands alone in this unsafe place. Nobody ever repeated that mistake. So subtly incorrect calls to objects can result in the object overflowing.
      Delphi is no more memory-safe than C++ is. For that matter, Delphi actually requires you to call destructors for all objects explicitly, and woe be on you if you forget to, or, worse yet, accidentially call it twice. No smart pointers either: welcome to hell.

      By the way, what the hell is "object overflow"?

    5. Re:Use this link to read article on one page by Eli+Gottlieb · · Score: 2, Informative

      I can see why you've been modded Funny. Null-termination is not, at all, even slightly, the same thing as an array carrying its size with it. Null entries can pop up anywhere for any reason, often bugs. It's much, much, much safer to just use the extra integer word and store the number of entries in the array.

    6. Re:Use this link to read article on one page by IdeaMan · · Score: 2, Interesting

      Programming lanuages don't cause bugs....programmers cause bugs Programming languages were written for humans, not other computers.

      Inferring from what you said that we never make mistakes and know all the features of the language intimately, why did he bother putting in type checking? That the Bjarne went to all the trouble of implementing type checking, then again for templates, and STILL has not addressed resource allocation is very frustrating to me. What? You'll define the type of an object but not its lifetime? Huh???

      --
      They ARE out to get you simply because They are in it for themselves and they don't care about you.
  17. Love C++, but it still sucks... by UnknownSoldier · · Score: 4, Informative

    * No standardized pragmas
    * Macros after-thought and not type safe
    * No 24, and 32 bit (unicode) chars
    * Still has float / double crap, instead of being properly deprecated and f32, f64, f80 used instead
    * Still has short / long crap, instead of being properly deprecated, and i8, i16, i32, i64, i128, u8, etc...
    * No distinction between typedefs and aliases
    * Inconsistent left-to-right declarations
    * Compilers still limited to ASCII source
    * No binary constant prefix (even octal has one?!)
    * No standard way to assign NaN, +Inf, -Inf to floating point constants at compile time

    1. Re:Love C++, but it still sucks... by PhrostyMcByte · · Score: 4, Informative

      * Pragmas are made specifically for non-standard compiler extensions. There can be no "standard" pragmas.
      * C++0x is adding support for UTF-8, UTF-16, and UTF-32 character types and literals.
      * TR1 adds cstdint which includes int32_t etc. types.
      * NaN and +Inf (not -Inf, though) can be had from std::numeric_limits

      alas, if those are the first complaints you think of, you haven't been using C++ long enough to really know the painful bits.

    2. Re:Love C++, but it still sucks... by Eponymous+Bastard · · Score: 5, Informative

      Most of your complaints seem aimed at C and not C++. Let's see:

      * No standardized pragmas

      You want standardized *compiler extensions*?

      They standardized the extension mechanism. That sounds good for a start, but I don't see how you could go farther.

      * Macros after-thought and not type safe C compatibility, basically deprecated now as they also affect everything, including members, variables, anything that gets #included, etc.

      * No 24, and 32 bit (unicode) chars wchar exists, toghether with I/O stuff, though I'm not sure about the encoding type. You can even declare streams and strings for any character type you build.

      * Still has float / double crap, instead of being properly deprecated and f32, f64, f80 used instead
      * Still has short / long crap, instead of being properly deprecated, and i8, i16, i32, i64, i128, u8, etc... C compatibility. I believe they are inheriting the new types from C99 too.
      Also, short/int/long give you the sizes optimized for the specific processor, so you can use that if that's what you want. You can't really deprecate them because of that

      * No distinction between typedefs and aliases What on earth is an alias? Are you talking about C's struct namespace? (one of the few things that C++ doesn't inherit)

      * Inconsistent left-to-right declarations Inconsistent in what sense?

      * Compilers still limited to ASCII source C++ has included trigraphs for over ten years now, which allow an editor to insert any unicode character and still store everything in ASCII for compatibility. Compilers don't even need to support unicode for things to just work. The editor just has to interpret the trigraphs and paint them on screen as the appropriate character.

      I've never used them though.

      * No binary constant prefix (even octal has one?!) I've never met anyone who actually worked in binary. Hex is close enough and less error-prone. Octal probably got included for a) C compatibility and b) People did use to work in octal (see file access permissions)

      * No standard way to assign NaN, +Inf, -Inf to floating point constants at compile time Would you like a quite or signaling NaN?

      For double:
      #include <limits>

      const double inf = std::numeric_limits<double>::infinity ();
      const double minf = -std::numeric_limits<double>::infinity ();
      const double nan = -std::numeric_limits<double>::signaling_NaN();

      See more here for example.

      There are has_infinity() and related functions to check for a type's capabilities (say, in a template)

    3. Re:Love C++, but it still sucks... by Bazer · · Score: 2, Informative

      * No standardized pragmas

      Pragmas were meant to be OS and compiler specific. If your OS or compiler doesn't provide a standard then it's the language is not at fault.

      * Macros after-thought and not type safe

      Macros weren't meant to be type safe. You should use templates if you need type safety.

      * No 24, and 32 bit (unicode) chars

      What about std::wstring and cwchar?

      * Still has float / double crap, instead of being properly deprecated and f32, f64, f80 used instead * Still has short / long crap, instead of being properly deprecated, and i8, i16, i32, i64, i128, u8, etc...

      Use cstdint and cfloat

      * No distinction between typedefs and aliases * Inconsistent left-to-right declarations

      I don't have much experience with those in C++ so maybe someone else should elaborate. Could you provide examples where these two would be a problem?

      * Compilers still limited to ASCII source

      This is true but hard-coding unicode strings is considered a no-no.

      * No binary constant prefix (even octal has one?!)

      This is true.

      * No standard way to assign NaN, +Inf, -Inf to floating point constants at compile time

      Standard since C99.
    4. Re:Love C++, but it still sucks... by blueforce · · Score: 3, Funny

      ... +Inf, -Inf...

      Everything has its limits, you know.

      --
      If you do what you always did, you get what you always got.
  18. Re:Printer Friendly by Anonymous Coward · · Score: 2, Insightful

    If the messages are the same, no one has any reason to see both, so scoring one out of the default view is the Right Thing. If you're pathetic enough to care about karma and this happens so often that it even matters, complain to the admins that the author of a redundant comment hasn't done anything wrong.

  19. Cfront by metamatic · · Score: 2, Insightful

    And in fact, Cfront was a compiler, not just a preprocessor; it was just a compiler that compiled C++ into C.

    --
    GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
  20. Sand-bagger by blueforce · · Score: 3, Funny

    Bjarne Stroustrup Reveals All On C++

    You mean... He's been holding back?

    --
    If you do what you always did, you get what you always got.
  21. The FQA is "equally" partisan? by Anonymous+Brave+Guy · · Score: 5, Insightful

    I'm afraid that web site is one of those things that gets way too much attention in some on-line communities because of its controversial nature.

    The reason the two sides are far from equally partisan is that Stroustrup freely admits there is another side to the debate and that C++ has its flaws, and he is making efforts to improve the situation. The FQA, on the other hand, just makes blanket statements like "For example, the lack of garbage collection makes C++ exceptions and operator overloading inherently defective", which simply isn't true (and neither are many of the statements made in the FQA under those particular headings).

    If you read the comments the guy who wrote the FQA makes on forums like reddit, as well as throughout the FQA itself, it's pretty obvious that unlike Stroustrup, he has little interest in any balanced discussion on the subject. He's just out to prove the other side wrong — where "wrong" often means "not agreeing with him" — and perhaps, the cynic in me suspects, to make a reputation for himself in the process.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  22. Want to know more? Read the book by idiot900 · · Score: 3, Insightful

    "The Design and Evolution of C++" by Stroustrup is a must-read if you are interested in why C++ is the way it is.

    After reading it, I really hated C++. It's the classic example of a project that gets ruined by too many people working on it, all with their own goals, and the book tells you exactly why this happened. C++ now is a hideously complex monstrosity that is popular because it is all things to all people, not because it is a good language.

    Anyway, if you disagree with me, have a look at the book. It is a testament to Stroustrup's objectivity that I came to the conclusion I did, and that you may come to the exact opposite conclusion as me after reading it.

  23. Re:managed code by gbjbaanb · · Score: 3, Interesting

    I think any language that doesn't support managed code is going to die out over the next 10 years You'll still be a Windows-only shop then? In ten years Microsoft may have changed its mind again about a programming platform. they seem to do so every ten years or so. Hell, in 10 years Microsoft might not even exist.

    And I suppose your shop used to say "COM only", and now says "ugh, COM, who'd want to code those things up". You seem to have swallowed the Microsoft marketing man's sales spiel wholesale.

    When you find out how slow some parts of .NET is (eg DB access), or how much memory it uses when you don't want it to, or how to find the object you expected to be GCd but hasn't been.. then you'll think about writing a chunk of your code in old C++.

    MS did do a lot of work (pretty poor IMHO though) with C++/CLI to get some interop going between C++ and C#/VB. Poor because of the somewhat contrived bodges to the language they put in that they could have hidden behind the compiler, and also because there isn't any real interop with old unmanaged C++ except by wrapping it with a managed dll (or recompiling with the /clr flag set). Its also a poor implementation - eg STL/CLR is a lot slower than the .NET containers surprisingly.

  24. and worst of all... by mkcmkc · · Score: 3, Interesting

    25 years later there's still not a !@#^%^&$ single compiler that implements the entire language correctly. We're all waiting for Godot...

    --
    "Not an actor, but he plays one on TV."
  25. Re:useful but oh so flawed by pclminion · · Score: 2, Insightful

    Back that statement up, buddy.

  26. Re:useful but oh so flawed by hey! · · Score: 5, Insightful

    Well, there's no doubt in my mind that C++ is a language design tour de force. The question is whether its design objectives are the right ones.

    They were probably the right objectives for the place (Bell Labs) and time (1979) it was conceived.

    At the time, computers were inconceivably slow by today's standards. I worked at a small developer that had a very nice AT&T 3B2-400, which had a WE32000 microprocessor, which probably ran at about 10-15MHz; a half dozen programmers shared it.

    As for the place, well, it was crawling with C programmers and C libraries, doing rather complex and important systems programming. Compatibility with C and proven C libraries would have been a huge thing.

    So, an efficient, object oriented version of C was probably exactly what was needed.

    I think that if there was any fault, it was the attempt to meet the goals of efficiency and compatibility with a language that implemented everything that (at the time was thought to be) necessary for programming in an object oriented style. Multiple inheritance carries too much baggage when all you want to do is to guarantee objects have a certain interface. Likewise, I think operator overloading is another example of trying to do too much. Yes, it makes programmer classes "first class citizens", but it really has no demonstrable practical benefit in my opinion. In situations where you need a special purpose language, it's probably better just to create one.

    Still, that's hindsight. If you really understand all the things Stroustrup was trying to do, C++ is quite awe inspiring.

    --
    Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
  27. Re:useful but oh so flawed by everphilski · · Score: 3, Insightful

    Likewise, I think operator overloading is another example of trying to do too much. Yes, it makes programmer classes "first class citizens", but it really has no demonstrable practical benefit in my opinion.

    I write math codes for fun and for a living. I have this discussion on an infrequent basis with a Java buddy of mine. Now granted I'm a dumb mechanical engineer and he's a smart CS major, but when I need some custom math classes that aren't provided by the language (tensors, vectors, Jacobians, Quaternions, etc.) and evaluating long math expressions, it is so much easier to view it using the native math symbols than to nest it all in member functions .add(), .subtract(), .multiply(), etc. Once I transliterated a piece of C++ code I had wrote for him and it consumed three times the space and was much less readable due to the nesting of the member functions... being able to use natural math symbols and natural parenthesis makes the math so much more readable, and when 90% of your code is math, you come to appreciate it. I wouldn't have it any other way, at this point.

  28. It was never a preprocessor by Joce640k · · Score: 2, Interesting

    If you're thinking along the lines of a bunch of #defines making C into proto-C++ then you're completely wrong.

    The early compilers produced C as a sort of "assembly language" so that it could be used on many different targets (C was widely available).

    But it you looked at the C it produced you'd have a hard time relating it to the original C++ source code.

    --
    No sig today...
  29. Anyone trying to defend C++ as a language by frank_adrian314159 · · Score: 3, Informative

    Anyone trying to defend C++ as a language should read this. And I speak as a programmer who has used C++ since cfront 1.0 was released to the world.

    Useful, yes. Pragmatic, maybe. Design heavily rationalized ex post facto by its creator and its proponents, most certainly. But a well-designed programming language, it is not.

    --
    That is all.
  30. Re:useful but oh so flawed by everphilski · · Score: 3, Insightful

    On the other hand, that's not the only natural way to handle the situation you are talking about. Another way is to create a new language. Altogether, I'd rather do the kind of work you're talking about in Matlab or Octave.

    I write code for clusters, now specifically CFD. Lots of math, lots of parallel processing. Matlab and Octave isn't gonna cut it, and you really desire the close to the metal aspects of c++.

    It may be a narrow range, but there's a lot of people in this narrow range. Specifically, (mechanical/aerospace/etc.) engineers. C++ isn't sexy like Java or Python, but we do a lot of things you just can't do in Python, and can't do fast in Java.

  31. Re:useful but oh so flawed by pclminion · · Score: 3, Informative

    Good book, but I don't see how some minor nuances translate to insurmountable design flaws. It's true that proper use of C++ requires a level of expertise beyond what's required for many other languages. IMHO, that just makes real C++ programmers more valuable.

  32. Re:useful but oh so flawed by toriver · · Score: 3, Insightful

    Basically when you have rules you ought to (or "must" unless you want magical bugs) follow that are not enforced by the compiler, the language is flawed. Like when you oveload new but not delete and thus have incompatible memory management. Or you return a reference to a method-local (auto) string object.

    It does however give rise to a market for code analysis tools that checks all the stuff the compiler will let you get away with.

    But you can save the cost of these tools (or the alternative manual hunt for bugs) by using more modern and productive languages like Java or Ruby, leaving C++ for operating systems and games. And the latter is moving into other lanbguages as well, i.e. Microsofts push for C# in game development, and the widespread use of Python in e.g. EVE Online, ToonTown, Civ IV and other games.

  33. Re:useful but oh so flawed by TheLink · · Score: 2, Interesting

    If 90% of your code is math, how about Lisp or Fortran?

    Of course that might depend on what the 10% is.

    --
  34. Bitmasking by bill_mcgonigle · · Score: 2, Insightful

    Hex is close enough and less error-prone

    When you're actually bitmasking, it's nice to see the bits rather than having to accumulate them in your head.

    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  35. C++ Debuggers by saccade.com · · Score: 3, Funny
    At a corporate event a few years ago, I found myself seated across from Mr. Stroustrup. I asked him what debugger he used for his own development.

    His answer was along the lines of: "Oh, I never use a debugger. If something's not working right I just think about it...maybe I'll add a printf once in a while if I need to check something."

    Now you know why utterly un-debuggable features like templates went into the language...

    1. Re:C++ Debuggers by Traf-O-Data-Hater · · Score: 3, Insightful
      "you're better off actually understanding your code instead of having the computer explain..."

      That's just the point. Your code isn't the problem for you to understand. In the real world where people have to look at other people's code, you often need all the debugging help you can get.

      Stroustrup is being very smug in his response here. He lives in an ivory tower, how much real-world code written by other people (to a deadline or management constraints) has he ever dealt with?

      My feeling is, very little..

    2. Re:C++ Debuggers by zaphle · · Score: 2, Insightful

      Just a side-note on unit-tests and debuggers (actually off-topic): They're all fine and well, but bugs resulting from bad synchronization (e.g. use of mutex etc) in multithreaded programs will not be detected. Often, if an object is not well synchronized, the chance of having race conditions or lost updates are generally very small and therefor hard to reproduce, but in a production environment they would still come up fairly regularly. E.g. If there's a chance of 1 in a million for something to go wrong due to bad synchronization, you would only encounter it on average every one millionth time you debug your application (=never), while for a computer it's not a big deal to run a piece of code billions of times per day. By definition, unit tests are never run while other threads are touching the same memory because they are meant to test an isolated unit, which boils down to testing them on a single thread, so unit tests will even never spot them.

      Don't get me wrong, it's good practice to have unit tests, but there are actually people out there (often IT managers) who imagine that if all code is covered by unit tests that this would guarantee that the program as a whole can't fail so I always like to add this disclaimer when talking about unit-tests or testing in general.

      --
      And what if there's nothing behind the door until it is being opened?
  36. Stroustrup seems to say (don't use exceptions!) by EMB+Numbers · · Score: 2, Informative

    Here is a real eye opener: Bjarne Stroustrup cited the JSF coding standard as an example of C++ usage: "Also, embedded systems programming is a major area of use and growth of C++; for example, the software for the next generation US fighter planes are in C++ (see the JSF++ coding rules on my home pages)." http://www.computerworld.com.au/index.php/id;408408016;pp;5;fp;16;fpid;1

    I particular like the following statement in the JSF++ coding rules that the creator of C++ holds up as an example of how to use C++:
    AV Rule 208 C++ exceptions shall not be used (i.e. throw, catch and try shall not be used.)

    Rationale: Tool support is not adequate at this time.

  37. Re:useful but oh so flawed by neonsignal · · Score: 2, Funny

    the bloke was complaining about function nesting and you suggested Lisp?

  38. Re:WTF? Re:Interesting Read by bytesex · · Score: 2, Interesting

    It's the real reason that D hasn't taken off yet. Well, that and the fact that it has 90+ (!) keywords. The guys at digital mars are doing what Sun tried to do with java; it's ours, ours, and ours alone ! Yes, there is a spec, and yes you can build compilers, but wait - not so fast. You have to let us test your stuff, or you can't call it D. And maybe pay us a little. Or at least remember us in any code that you write.
    .
    Whenever I go to digital mars' website, I'm reminded of my Corba days and that institution - I forget what it's called - that was in charge of it. People should be well reminded that the days of commercial languages are over. Even Microsoft won't try it anymore. That should say something.

    --
    Religion is what happens when nature strikes and groupthink goes wrong.
  39. Re:useful but oh so flawed by twistedcubic · · Score: 2, Insightful

    Altogether, I'd rather do the kind of work you're talking about in Matlab or Octave. Or you could do something like Beanshell -- have an interpreted language that is closely tied to the underlying language and its libraries. Matlab (and its clones) are mostly useless in the numerous areas of math outside of a standard undergrad curriculum, even for "profiling" since the data structures aren't even in the language. It's a zillion times easier to write these in C++. This never gets mentioned on forums like this, but C++ provides the right balance of power and flexibility (especially with memory managament) for people who do specialized math/science. And even in not-so-specialized areas, sometimes objects in Matlab clones are represented in a way which is cumbersome to use. Writing a representation in C++ might save hours.
  40. Re:useful but oh so flawed by twistedcubic · · Score: 2, Insightful

    If 90% of your code is math, how about Lisp or Fortran? Maybe Lisp is too slow and it's hard to represent objects in Fortran. Imagine how you would represent a multivariate polynomial with rational coefficients in Fortran.
  41. Cut the senseless C++ bashing, please. by js_sebastian · · Score: 2, Interesting

    It's much harder to write C++ code that, for example, will never leak memory no matter what goes wrong than in the assorted garbage collected languages, or even vanilla C. That, I don't see how anyone could even reasonably argue. You don't see? let me try to show you...

    About C: you think it is easier to manage memory with C char* and arrays than with C++ string,vector,and exceptions + resource-acquisition-is-initialization paradigms? I can only call that an outlandish claim! Hell even auto_ptr helps (I use it to express ownership transfers in function parameters and return values), and in C++0x they will finally have a real smart pointer standardized too. If you use raw arrays in C++ and get buffer overflows, don't blame stroustroup.
    About garbage collected languages: true, memory management is not your problem anymore, which makes coding a bit easier (although there are other resources than memory which must still be managed manually). The problem is performance and, specifically, memory usage. My memory-leaking C++ implementation may well use half as much memory at any given time as your non-leaking GC code. Despite what people think, computers do not have over-abundant performance for all relevant tasks. I myself wrote 2 pieces of code in C++ just in the first months of this year where I knew from the start performance would be a problem. In one case because of the sheer size of the data I was handling, in the other because I knew the problem was NP-Complete. The first one would have simply page thrashed me to death in a GC environment.

    The problem is that GC is viral, in the sense that if I link my non-GC code to a single library written to run in a GC environment, GC needs to be enabled for the entire program. This is the difficulty of adding GC as an optional feature to C++. Making it mandatory is not an option for performance reasons. In a GC environment you have little in the way of guarantees that memory will be freed right away, and this will occasionally come back to bite you hard when your application slows to a crawl as it runs out of memory. GC may be fine 98% of the time, the problem is if the language uses GC, you just can't turn it off locally where the memory usage is really hurting you.
  42. Re:Operator overloading... by Javagator · · Score: 3, Interesting
    It is a feature of the language everyone has to deal with for a tiny minority of users.


    The people using C++ for engineering, mathematical, and scientific applications may be a minority, but not a tiny minority. No one has to deal with operator overloading if it is not applicable to their application. If a developer is too immature to recognize when a feature is a bad choice, then operator overloading is the least of his problems.

  43. A wisely used tool for elegant implementation by Douglas+Goodall · · Score: 2, Informative
    I am the first to admit you can write totally unmaintainable code in c++ if you want to. I will also admit that I have known a lot of c++ programmers that absolutely had to use every feature or they weren't happy.

    I on the other hand used about 10% of the features and had a wonderful time using a subset that probably was actually just "c with classes". I used c++ as a better c compiler with warnings turned up all the way. I found classes an elegant way of encapsulating code that dealt with hardware. Concrete classes were my favorite. My c++ programs were straightforward and easy to read. I am thankful that BS wrote the language. It was a lot of fun. I never really needed more than I learned in the first month. Strong type checking kept me out of trouble. I actually spent very little time subclassing and enjoyed the luxury of keeping my prime classes functional. Modeling hardware as c++ objects was the most fun I had in programming ever. When done right, the code was as compact and maintainable as any I have written in any other language. Unfortunately I got very little follow-on work because the functionality of my code was obvious. Vendors like Microsoft and Borland just couldn't wait to use polymorphism to create frameworks. I hated frameworks because they were these huge collections of c++ complexity that had to be studied endlessly, and about the time you knew enough, the vendor brought out a new version. MFC is a prime example of a piece of code I just couldn't get my head around. It seemed to me that the point of all the frameworks was to make hello.cpp in 100 lines or less, but anything non-trivial got huge quickly.

    I suspect that there are other people out there that felt like I did about c++. At least I hope there are. Every time I encountered a project where the legacy code used every feature of c++, my spirits took a dump. C++ was a tool that consultants often used to make themselves indispensable. Some of the code I encountered, like the bio-rad application was a good thesis, but a lousy piece of intellectual property. Twenty levels of nested classes, heavily subclassed made for a long research project every time you needed to track down a bug.

    The secret of c++ for me was knowing just how much to use to leverage off the power of it's object orientation. Encapsulation was good, Inheritance was ok sometimes. Multiple inheritance was almost never a good thing, and polymorphism usually lead to spaghetti code. IMHO

  44. Re:useful but oh so flawed by zaphle · · Score: 2, Insightful

    Multiple inheritance carries too much baggage (...) but it really has no demonstrable practical benefit in my opinion. This is basically heresay. Most people who *think* multiple inheritance is not needed have never gotten into programming deep enough to understand that it actually *is* necessary if you want a clean object model. Sure C# and the like give you interfaces, but they require you to implement the code behind them over and over again, resulting in most programmers to just start copy-paste code. Then one day, a bug or change request comes up for that particular copy-pasted code and hell starts: you can start updating all that copy-pasted code and make sure you don't forget any of it. With multiple inheritance, the shared code is actually where it should be: in one class. I dare people to actually show an example of where multiple inheritance is flawed that can't be solved with virtual inheritance or dynamic_cast. The problem is that most programmers who *think* they are C++ programmers are actually enhanced C programmers (at best) who never even heard of dynamic_cast or virtual inheritance, not to mention partial template specialization. Here's a link if you want to know more: http://en.wikipedia.org/wiki/Modern_C%2B%2B_Design

    I also like to remind that generics as now widely used in languages such as Java and C# initially started as templates in C++, only the latter has far better support.

    For those who think that garbage collection is the holy grail against leaks in a program, think again. While it may solve memory leaks, it doesn't solve resource leaks (like open connections, file locks, ...) who on the other hand can be nicely solved in C++ by implementing their release in the destructor. The use of garbage collectors inherently prevents the destructor paradigm (since one can never be sure when or even IF the Finalize method will be called - yes the GC of .NET doesn't guarantee that it will be called even when the program terminates, so freeing up a resource in a Finalize is a no-no since it may still leave you with locked resources), so basically, you're required to manually clean up your resources instead of having your object deal with the cleanup automatically. Makes garbage collection quite controversial if you ask me.

    If you want to know more, I'm always in for a discussion on the subject. Happy to inform.
    --
    And what if there's nothing behind the door until it is being opened?