Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Interview Update With Bjarne Stroustrup On C++0x

Posted by CmdrTaco on Thu Aug 21, 2008 10:59 AM
from the name-spelling-indicates-language-complexity dept.
An anonymous reader writes "DevX interviewed Bjarne Stroustrup about C++0x, the new C++ standard that is due in 2009. Bjarne Stroustrup has classified the new features into three categories: Concurrency, Libraries and Language. The changes introduced in Concurrency makes C++ more standardized and easy to use on multi-core processors. It is good to see that some of the commonly used libraries are becoming standard (eg: unordered_maps and regex)."
+ -
story

Related Stories

[+] Developers: Bjarne Stroustrup Reveals All On C++ 371 comments
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."
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • by snarfies (115214) on Thursday August 21 2008, @11:00AM (#24690589) Homepage

    I saw the headline and thought I was seeing some 1337 form of "cox."

    huhuhuuhuhuh he said "form."

    • by Anonymous Coward on Thursday August 21 2008, @11:40AM (#24691251)

      C++ is to C as Lung Cancer is to Lung
      • Re:C#++? (Score:5, Insightful)

        by Noodles (39504) on Thursday August 21 2008, @11:25AM (#24691001)

        Because performance is important to some people.

          • Re:C#++? (Score:5, Insightful)

            by neokushan (932374) on Thursday August 21 2008, @11:55AM (#24691471)

            If it was as good as it stands, then newer languages such as C# wouldn't take off.
            Don't get me wrong, I love C++ and it's my primary programming language, but to say it's perfect as it is, is just silly.

          • Re:C#++? (Score:5, Informative)

            by drxenos (573895) on Thursday August 21 2008, @12:03PM (#24691617)
            No it's not. The standard does not define concurrency issues. Not how to spawn threads and create mutexes, but lower-level issues, like coherency. This is sorely needed for truly portable code. Rvalue references will help a lot with the creation of temporaries that are just copied and destroyed. You see this now in all the specializations in the libraries for the swap function. With rvalue references, you can write a single template that will be optimal for all types. Currently template error messages are a mess. several lines of unreadable garbage because your type doesn't supply a member or operator that the template needs. Concepts will lead to concise, easy to understand error messages. typedecl and the new use for the auto keyword will reduce verbosity, and stop the nightmare that is figuring out the type of a complex template (i.e., when using Spirit, et. al.). Lambdas and closures will simplify using the STL algorithms without having to create a lot of functors. REH
  • Objective C and C++ (Score:4, Interesting)

    by Midnight Thunder (17205) on Thursday August 21 2008, @11:04AM (#24690663) Homepage Journal

    If anyone has used both Objective-C and current C++, can anyone tell me whether the new specification is a clear improvement on either if these?

    • I can. (Score:5, Funny)

      by bigtallmofo (695287) * on Thursday August 21 2008, @11:10AM (#24690733)
      Yes.
    • by thermian (1267986) on Thursday August 21 2008, @11:13AM (#24690781)

      No, not really.

      In fact C++ is barely managing to hold its own any more against C# and Java.

      It's not that C++ isn't good, its just that its harder to do things in it then it is to do those same things in either C# or Java. Harder to do means more expensive, and businesses all over are having to tighten their purse strings.

      I keep finding that for fast number crunching apps, C beats C++, and for less intensive work its usually easier to use Java or C#, or indeed python, then it is to use C++.

      Also, its certainly true to say that in the UK C++ is not anywhere near as useful in terms of getting yourself a job as it used to be.

      • No, not really.

        Nothing else in your post either supports, or even directly addresses this assertion.

        It's not that C++ isn't good, its just that its harder to do things in it then it is to do those same things in either C# or Java. Harder to do means more expensive, and businesses all over are having to tighten their purse strings.

        This is the same bullshit that's trotted out there every time this topic comes up, and it's no more true now than it ever was, which is not at all. If you do a little looking around, you'll find very elegant libraries that support every single feature you'll see in ANY other imperative language, and MANY declarative language features to boot. If you're against code reuse and third party libraries on some sort of general principle, then you're kinda missing the whole point of C++.

        I'll be blunt, maybe an ass, maybe a troll, but having used all three of those languages extensively, I can say with almost absolute certainty that the only reason you should be having so much more trouble doing things in C++ (ESPECIALLY as compared to those two languages) is that you're either a very poor C++ programmer or have a pathological aversion to third party libraries.

        In fact C++ is barely managing to hold its own any more against C# and Java.

        Another thing that's been very much in the vogue to say lately, but I just haven't seen any meaningful evidence for. I think Bjarne covered this topic fairly even-handedly in TFA, and if he's to be believed then C++ usage is not suffering like popular belief seems to indicate. The crux of it being that web scripting was never a strong domain of C++ in the first place, and in actual applications programming C++ is still the leader of the pack.

          • by cduffy (652) <charles+slashdot@dyfis.net> on Thursday August 21 2008, @12:50PM (#24692365)

            Generally speaking, I agree with your post. However...

            Technically there isn't any, c is a subset of c++ so anything you can do in c you can do in c++.

            That's a really, really awful way to think about C.

            C has a completely different set of best practices and design principals; anyone who puts "C/C++" on a resume I'm reviewing loses points as opposed to listing them separately.

    • by Free the Cowards (1280296) on Thursday August 21 2008, @11:14AM (#24690791)

      Objective-C is essentially unrelated to C++ in every way. C++0x does not change this fact at all. Comparing the two makes just slightly more sense than comparing C++ and Prolog.

    • by TomorrowPlusX (571956) on Thursday August 21 2008, @12:29PM (#24692017)

      If you're writing C++, the spec is an improvement. If you're writing Objective-C, you probably don't care because you've already got a great language.

      Also, you'll gnash your teeth because god knows how long it will take for apple to provide a compiler toolchain ( gcc? llvm? clang? ) which supports the new features.

  • by Daimanta (1140543) on Thursday August 21 2008, @11:08AM (#24690707) Journal

    "control of alignment"

    I'd like chaotic good please

  • by jeffb (2.718) (1189693) on Thursday August 21 2008, @11:15AM (#24690821)
    ...or, as a former manager explained it, "When C++ is your hammer, everything looks like a thumb."
  • There's only one interview with Stroustrup that's worth reading: http://www.nsbasic.com/desktop/info/interview.shtml [nsbasic.com]
  • by Escogido (884359) on Thursday August 21 2008, @11:29AM (#24691073)

    http://yosefk.com/c++fqa/ [yosefk.com] - this site says it all.

    And it's also being argumentative and verbose at that, unlike your routine 'C++ sucks' rant.

  • by serviscope_minor (664417) on Thursday August 21 2008, @11:46AM (#24691345)

    We will see the usual litany of C++ hating here in this thread. The hating will be generally based around misconceptions or problems that are 5 years old.

    So to get them out of the way:

    If you're leaking memory or spending time managing memory in C++, then you're using C++ wrong. Get a book written in the last 5 years.

    If you're worried about compiler compatibility (with the exception of export which isn't much use anyway), get a compiler written in the last 5 years.

    If you think that C does some subset of your task better, then write it in the common subset of C and C++ and quit whining. Or, write it in C and link it against your C++ code and quit whining.

    If you think that templates simply provide code bloat, then get a compiler newer than 5 years old.

    If you think C++ is slower than C, then get a good optimizing compiler (you know one written in the last 5 years) and do a benchmark. You will generally find that templates make C++ faster.

    If you think "modern" languages are more expressive, then give "modern" C++ a try (insert comment about recent compilers here).

    Sure there are valid complaints about C++, but the majority of them I hear on slashdot are complete bull. The majority of the remaining complaints will be fixed by C++0x.

    One remaining problem is the lack of a vast array of standard, business oriented libraries. I don't write business oriented code, and I find the C++ STL one of the best libraries out there since it provides really good support for writing efficient algorithms.

    Another problem is the difficulty in parsing C++. Sadly that's never going away.

    But if you're going to complain about C++ compared to recent languages here, make sure that you're talking about recent C++ too, and try to make sure the complaints are accurate.

  • by Barnett (550375) on Thursday August 21 2008, @11:54AM (#24691467) Homepage
    C++ is an extremely powerful programming language and that is why I use it every day. But it has one major problem: It is too complicated. As long as you do programming full time you are OK but if too much of your time is spent on the application side of things you quickly get in trouble. This is what people like BS don't seem to get - not everyone can spend 100% of their time studying the language.
  • auto rocks (Score:5, Interesting)

    by ultrabot (200914) on Thursday August 21 2008, @11:57AM (#24691515)

    The new "auto" declarations really fix one of the biggest gripes with C++. Everybody is dead tired of doing


    std::map::iterator it = m.begin()

    Now you can just do:

    auto ip = m.begin()

    It takes much of the pain away from static typing...

    • by xenocide2 (231786) on Thursday August 21 2008, @11:11AM (#24690743) Homepage

      Yes. It's already been done once, aka C99. This isn't the thing that will replace C++, it's the next revision of the language, with multithreading support etc. Once C++ has worked out the hard stuff, C will have it's own next revision based on that.

      Once everything's finished, it should be finalized as C++09. It may carry on another year, in which case you might call it "C++0xa" ;)

      • by Free the Cowards (1280296) on Thursday August 21 2008, @11:12AM (#24690767)

        Been there, done that.

        Most of the time, the potentially reduced running time of the C++ implementation never comes close to the months saved in development.

        And when it does, it's trivial to go in and write the speed-sensitive portions of the program in a faster language.

        • by AmazingRuss (555076) on Thursday August 21 2008, @11:25AM (#24691011)

          ...what do people find so difficult about C++? Use the standard libraries, exception handling, and make sure your news all have deletes, and it's no more difficult than any scripting language. I actually prefer it over scripting languages, which have their place, but feel all sloppy and unspecific. It's like the difference between building a house out of 2x4s and building one out of sticks you found laying on the ground.

          • by Free the Cowards (1280296) on Thursday August 21 2008, @11:49AM (#24691405)

            Well, here's what I personally dislike about C++. You don't have to agree with them, but this is how I feel and I think it's how many other people do as well. Certainly when talking to people who prefer other languages over C++, they have expressed similar sentiments.

            1. Lack of libraries. The C++ standard library basically gives you file IO, containers, and that's it. If I want to do something like fetch the contents of an HTTP URL, parse XML, serialize objects, compute dates and times, use regular expressions, compress data, or even just simple, basic Unicode support, then I have to hit some external library that I may have to install and probably can't rely on existing on another machine.
            2. Flexibility. In C++ it is essentially impossible to make, say, a dictionary where each key can refer to an object of a completely different type. This is what you refer to as "sloppy", but I actually find this flexibility to be essential in designing good software. The fact that C++ does not allow it forces me to either twist my program's design in unnatural ways to fit the language, or do a lot of extra work to twist C++ to fit my program's design.
            3. Manual memory management. In any complex program, balancing your news with deletes is not as simple as you make it out to be. Object ownership is a tough problem. Lots of C++ code solves this problem by making a lot of defensive copies, which in turn hurts performance greatly.
            4. Errors. Make one simple typo in a template instantiation and you can generate literally pages of twisted, non-obvious errors. This makes it much harder to get a C++ program to compile than it should be.
            5. Nonportability. C++ compilers tend to differ massively in just how well they adhere to the C++ specification. Creating portable C++ code is much harder than it ought to be, especially when you take into account the necessary dependence on external libraries I mentioned above. And then you need a build system to go with all of that, which brings its own set of headaches.
            6. Readability and writability. With all the type information being declared all over the place, big template declarations, and the like, I find that C++ takes considerably more effort to both read and write.

            The really big issues for me are the flexibility and the lack of libraries. The rest is less important. But with C++ it's like building a house out of 2x4s that you're not allowed to cut to length, whereas with moer modern languages it's more like building a house out of prefabricated rooms, with a ready supply of 2x4s and tools to shape them as you need if the prefabbed rooms don't fit your needs.

            Please note that this is just my opinion, and you asked for it. Feel free to disagree, but please don't flame.

              • by Free the Cowards (1280296) on Thursday August 21 2008, @12:08PM (#24691693)

                Counter-counterpoints:

                1. Boost is an external library, and from my very limited experience none too easy to incorporate.
                2. Likewise, an external library. But putting that aside for a moment, what's the C++ equivalent to this python code?
                  d = {"name":"Bob", "age":42}
                  print "Name is %s and age is %d" % (d["name"], d["age"])
                  Keep in mind that this is a complete python program, no further code is required.
                3. While those are handy, they don't substitute for a real garbage collector.
                4. I hope you're right, but I'm skeptical. Massive template instantiation errors seem to be a compiler problem, not a spec problem.
                5. Key words being "can be". It's tough to do, especially since the compilers out there almost never comply perfectly with the spec.
                6. Of course it's a matter of taste, I never said otherwise.
                • by Kevin Stevens (227724) <kevstev AT gmail DOT com> on Thursday August 21 2008, @12:26PM (#24691959) Homepage

                  Boost has in many eyes really transcended from "just an external library" to an integral part of the C++ platform. It compiles on every major platform, and it is open source.

                  Boost is moving C++ forward at a rate 10x that of the standards committee. I am not sure why you felt integrating it with your project was difficult- it is header only for the most part and does not require you to use any specific pieces. Shared_ptr's, which are the most useful library of all, do tend to be viral in the sense that you have to use them everywhere, but this is a GOOD thing.

                  If you are doing C++ without Boost these days, you are really missing the boat.

                    • by Anonymous Coward on Thursday August 21 2008, @01:57PM (#24693441)

                      It is the discussion. Judging c++ with boost excluded is like judging perl with CPAN excluded. Who cares whether it's "part of the language" or not? Everyone who uses the language seriously uses them, and they're critical to understanding how the language is used effectively.

                    • by Kevin Stevens (227724) <kevstev AT gmail DOT com> on Thursday August 21 2008, @04:04PM (#24695565) Homepage

                      It doesn't solve anything that *couldn't* be solved before, but that's not the point, as anything can be solved given enough time and effort.

                      But out of the box, without even any compilation needed(!) you can get smart pointer implementations, timers, asynchronous I/O, a multithreading toolbox, conversion libraries, containers, memory pools, and tons more (some would say so much more that its bloated) with the added peace of mind knowing that tons of people out there are using them as well and they are thoroughly debugged. Its worth it for the shared_ptr's alone- those alone dramatically reduce the biggest source of C++ bugs.

                      In my previous company, I worked on a system that was about 10 years old- started before the STL came into existence, and long before it was well supported by compilers, and thus the team had spent a lot of time building STL-like functionality with dynamic strings, iterator like functionality, vector/list work-alikes, etc. This meant that now once the STL came around, a programmer familiar with "standard" C++ had to learn how to re-do mundane things like string and container manipulation. Similarly, that team had created smart pointer implementations, logger classes, multithreaded and socket libraries, etc. Boost not only provides all of this functionality, but you get it working right out of the box, and since Boost is well known, you don't have to wait for a programmer to get up to speed for a month or two while he becomes familiar with your code.

                      There are some more exotic features that you don't have to use, but I recently used multi_index to implement what is more or less an in-memory database cache in about 100 lines of code. This replaced a lot of code that read records and then threw them into hash maps or vectors using the OrderId as a key, then the CustomerId as a key, etc... so we had fast lookups to our most commonly used objects.

                      What are its advantages over ACE? ACE is a great networking and concurrency library, which not all applications necessarily need, and ACE's strong point is multi-platform networking and concurrency, which while I wouldn't call a small niche anymore, can't be used across all applications. At least some of Boost's libraries, most notably shared_ptr, can be used in any C++ program. In fact, until Boost::asio was released relatively recently, I would say ACE and Boost were entirely complementary. Also, boost is more or less a testing ground for the C++ standards committee, so it is more or less "blessed" and can be seen as a Beta for future versions of the standard.

                • First off, if you have a problem with using external libraries, then you just won't get anywhere with a C/C++. They are VERY general purpose, and intentionally so, and the whole idea is that implementation specific things are supposed to be provided in libraries, rather than the core language. That said:

                  1. Boost is actually very easy to integrate for most of its features. A few (small handful) of its components require compilation, but the vast majority of them are template-based and header only. Meaning just include a header file and there you go, you're using boost. No extra compilation/installation required.

                  2. This kind of thing is GREAT for doing small scripts, but HORRIBLE for doing large complex applications where type safety can be VERY important for avoiding bugs. If all you ever do are small, quick, limited scripts, then you're absolutely right that you should avoid C++, that's certainly not what it was meant for, and not so much the domain of a strongly typed language. For things like the software that runs large financial institutions and whatnot, there's a reason code like that should be avoided at all costs.

                  3. I have trouble imagining a situation where a real garbage collector would ever be superior to an RAII model with shared smart pointers for stuff allocated on the heap, outside of plugging up a leaking legacy app. Maybe for very simple programs, but once you get non-trivial destructors (for example, with objects that lock system resources), then you start having to do manual memory management in your GC environment anyway, and end up with a horribly ugly conglomeration of "mixed metaphors" as it were. Smart pointers really give you the best of both worlds: deterministic destruction, without having to worry about manually releasing anything. It's just a matter of getting used to declaring a smart pointer wherever you would have a "type *name" instead. So yes, I'd argue they ARE a substitute for garbage collection in almost any situation.

                  4. Sorry to be blunt, but you should probably RTFA on this one. The problem is solved through "concepts," which is the part of the new specification which deals with this specifically. It's essentially a C++ implementation of the "design by contract" metaphor.

                  5. In this case "can be" equates to "do whatever you like and it'll be portable on all major general purpose computers, and who uses Ruby or Python on embedded platforms anyway?" If you are able to compile with GCC, which is the case for pretty much every computer/OS combination in existence, then you can count on it being pretty damn portable. If you are programming for something like an ATM or a set-top box, then you probably aren't going to be using a high level scripting language anyway.

                  6. Yeah, it can get ugly. Thankfully this will be largely fixed with the "auto" keyword in C++0x.

                    • by Free the Cowards (1280296) on Thursday August 21 2008, @02:08PM (#24693617)

                      Again, I don't think I'm being unfair, I'm just saying why I use what I use. Python provides more libraries for the stuff I use than C++ does. "Batteries included" makes my life easier. Maybe this isn't fair to C++. So what if it's not? Should I make my life more difficult by using C++ out of a sense of fairness?

                      As for GC goes, no, it's not "just another memory management aid". Non-GC versus GC is the difference between having to think about memory management and not having to. Automatic refcounting still forces you to manually find and break reference cycles, and garbage collection does not.

                    • by Free the Cowards (1280296) on Thursday August 21 2008, @03:05PM (#24694655)

                      Yes, if C++ included the same libraries that Python does, this objection would go away. (Why wouldn't it?) The other objections would remain.

                      And no, GC does stop you from having to think about memory management. So-called "soft leaks" aren't a memory management problem, they're just a regular old code bug. GC doesn't save you from all bugs, or even from a particularly large number of them. It mainly just saves you from programming overhead.

                      GC also doesn't save you from having to manage external resources as that SafeHandle class does.

                      RAII is definitely not the design pattern I want. Believe me, I know what RAII is, and I know what I want, and the two do not intersect in any way.

                      I know it's hard to believe, but there are people out there who legitimately do not like C++. Not because we're stupid, or clueless, or because we've been misled, but simply because we have different constraints on our programming or even just different opinions.

          • by Hognoxious (631665) on Thursday August 21 2008, @11:50AM (#24691417) Homepage Journal

            It's like the difference between building a house out of 2x4s and building one out of sticks you found laying on the ground.

            Error 2317 - Invalid analogy - no wheels. Bailing...

        • by iplayfast (166447) on Thursday August 21 2008, @11:35AM (#24691153) Homepage

          I've found that the biggest advantage for C++ is the portability. I have written an application backend for PC's (back in the days of DOS) and since then ported it through various versions of windows, Linux (for web use), Palms, and Pocket PC's.

          Using C++ allowed me to very easily make the different processor needs, compatible, by writing little compatibility layers, which would swap bigend values, unpack data structures from disk into memory (so is on even boundary). and so on.

          Yes the fast speed was why I originally went with the C/C++ route, but the big benefit has been the portability.

        • by johannesg (664142) on Thursday August 21 2008, @11:35AM (#24691155)

          ...and roll on the C++-hatred! Second C++ article in a short time, and again lots of venom and anger. "Months saved in development"? Really? What are you doing, implementing your own OS before you start application development? Here's a newsflash: C++ also has support libraries, just like Java, Perl, Python and Ruby. They may not be part of the language specification (and I still think that's a weird idea to begin with, but I'm old-fashioned that way), but that doesn't mean they don't exist.

          Anything you could want for in a modern language is there. And nobody is holding a gun to your head and making you write those scary templates if you don't want to.

          I'm just positively amazed that Slashdot, in theory home of programmer geeks anywhere, should have such a violent dislike of C++. Not that there is nothing to criticize about it, but it is still an amazingly powerful, versatile tool that programmers anywhere would do well to learn.

          • by Yokaze (70883) on Thursday August 21 2008, @12:20PM (#24691883)

            > I'm just positively amazed that Slashdot, in theory home of programmer geeks anywhere, should have such a violent dislike of C++.

            Because C++ is not a pure language. It is a multi-paradigm language (imperative, OO and functional) with both a high and low-level language features and people seem to hate the aspect they which they don't prefer.

            The close-to-the-metal types hate the high-level aspects and rather use C. Disregarding the fact, that changing the code from C to C++ is purely syntactical and runs without any detriment in performance. Exactly the prime idea behind C++.

            The high-level people dislike C++ exactly for this approach. They don't like that the basics are so clearly visible, and are even the default. You have to hop through some loops, before you get to a higher abstraction layer. E.g. you have to use external libraries and/or special classes for memory management.

            Personally, I like C++ for exactly that reason. I can start on a fairly abstract layer with pure virtual interfaces, smart pointer, signal slots and there is not a single (raw) pointer or a manual deallocation to see (or other manual resource deallocation).
            Granted, it is more verbose than in a pure high level language, but that is what the machine has to do.

            And if there is a performance bottleneck, I can seamless go down in the abstraction level from simple inline functions, over imperative functions with pointer arithmetic, down to inline assembler and can even guarantee a certain timing, if necessary.

          • by TomorrowPlusX (571956) on Thursday August 21 2008, @12:27PM (#24691989)

            There are vanishingly few programmer geeks left on slashdot. Most of the "programmers" here, these days, are folks who've written a few scripts or set up a movable type install.

            There are a few real programmers left here, but they're lost in the noise. You know, the roaring noise made by the python and ruby folks.

            This post brought to you by a C++ programmer who happens to love Python and Ruby ( and javascript! it's an amazing language ), but uses the different languages where appropriate.

          • by ardor (673957) on Thursday August 21 2008, @11:41AM (#24691269)

            And I can say with a straight face that you are wrong.

            If you base your experiences on pre-2000s C++, you know very little of modern C++. I have been developing in it for more than 10 years, and a few years ago I would have agreed with you, but things have changed. Really.

                • by squarooticus (5092) on Thursday August 21 2008, @12:18PM (#24691849) Homepage

                  I am not going to go read a book simply to settle an argument: you need to summarize here.

                  In particular, explain to me why his techniques are not generally applicable to other languages (or to Python or Ruby in particular) or why using those techniques or similar ones and interfacing to C when necessary actually provide a less efficient development environment.

                  I know C++ can be made "acceptable" as a high-level language through sufficient effort; I spent 7 years doing such a thing. I want to know why that's a better solution than using tools that are---out-of-the-box and without reference to a magic cookbook---ready to do the things that require months of development or dozens of third-party libraries to achieve in C++.

            • by Free the Cowards (1280296) on Thursday August 21 2008, @11:55AM (#24691479)

              No, the "premature optimization" thing applies to all areas. Especially areas where it's never fast enough.

              Why? It's simple: resource management.

              You have X amount of resources to put into your product. X is always finite. It's kind of tough to measure X, but you can think of it as lines of code, man-years, or even just dollars. The amount of resources you have varies a lot depending on your budget, how much time you have, and the quality of the programmers you have. But the important thing is that X is always limited.

              Now you have two approaches:

              1. Spend X on making the code fast from the start, and keep spending X until you run out.
              2. Spend X on making the code functional and with good design. When appropriate (i.e. when the design is good and the code works), start spending X on making the program go faster. Keep spending X on speed until you run out.

              Paradoxically, I hold that #2 will produce a faster program. This is because the X you spend on making the program faster in #2 will be more effective, because you've already laid the groundwork for it. It's always difficult and time consuming to optimize code that doesn't even run yet. It's much more efficient to optimize code that already works. So the result, even though you spend less X on speed, is a faster program.

              Think of it as transporting a lot of material into the wilderness somewhere. If you first spend some of your resources on building a road, you'll get the job done for less time and money than if you just start hauling stuff into the woods immediately.

    • by Tenrosei (1305283) on Thursday August 21 2008, @11:22AM (#24690943)
      hours finding memory leaks? How bad are you at debugging? Plus there are tons of tools to assist with memory leak detection. However, protection is no substitute for abstinence. Learn to write code better. BTW go do some embedded software with C# or Java.
    • by ardor (673957) on Thursday August 21 2008, @11:27AM (#24691027)

      I'll consider Java and C# as C++ replacements once they get:

      1. REAL templates, not this generics joke
      2. Proper RAII, which many programmers mistakenly believe to be useful for memory management ONLY (scoped locks come to mind) (Java/C# finalizers are no replacement)
      3. Java: operator overloading

      These points are serious, especially the first, without real templates, generic programming/metaprogramming at compile-time is not possible. These two are one of C++'s biggest strenghts, though.

      To be fair, C# 3.0 is somewhat nice, especially its functional core. Java is a totally uninteresting language with very small expressiveness. Of course, if the job requires it, there is no discussion, but in my spare time, I prefer C++.

    • by CyberKrb (774549) on Thursday August 21 2008, @02:02PM (#24693519)
      You surely are a careless coder, then. C/C++'s memory/pointer-related problems are due to careless/clueless programmers, not due to the language itself. You clearly fail to understand the language, yet pretend to answer with authority. Do you use (or even know) the RAII idiom? that smart pointers have been there for years? Yes, I mean auto_ptr and shared_ptr. How about the Boost library (which is being included partly in C++0x). Garbage Collectors are non-deterministic by nature; Therefore, they are a real no-no for real projects (think real-time systems or massive number crunching, where memory pools are common).