Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

Bjarne Stroustrup and More Problems With Programming

Posted by Zonk on Sat Dec 09, 2006 06:39 PM
from the nothing-pleases-a-programmer dept.
Phoe6 writes "As a follow up to the first part of his interview, Technology Review Magazine has another article running titled 'More Trouble with Programming'. Bjarne Stroustrup shares his point of view on good software, bad software design and aspect oriented programming." From the article: "Technology Review: Name the coolest and lamest programs ever written in C++, and say what worked and didn't work. Bjarne Stroustrup: Google! Can you even remember the world before Google? (It was only five years ago, after all.) What I like about Google is its performance under severe resource constraints. It possesses some really neat parallel and distributed algorithms. Also, the first Web browsers. Can you imagine the world without the Web? (It was only about 10 years ago.) Other programs that I find cool are examples of embedded-systems code: the scene-analysis and autonomous driving systems of the Mars Rovers, a fuel-injection control for a huge marine engine. There is also some really cool code in Photoshop's image processing and user interfaces."
+ -
story

Related Stories

[+] Technology: Bjarne Stroustrup on the Problems With Programming 605 comments
Hobart writes "MIT's Technology Review has a Q&A with C++ inventor Bjarne Stroustrup. Highlights include Bjarne's answers on the trade-offs involved in the design of C++, and how they apply today, and his thoughts on the solution to the problems. From the interview: 'Software developers have become adept at the difficult art of building reasonably reliable systems out of unreliable parts. The snag is that often we do not know exactly how we did it.'"
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 Anonymous Coward on Saturday December 09 2006, @06:45PM (#17179176)
    It is,

    int main()
    {
          cout "Hello World" eol;
          return 0;
    }

    Very cool at first, then it just goes down from there.
    • Java (Score:5, Funny)

      by goombah99 (560566) on Saturday December 09 2006, @07:15PM (#17179418)
      Javac is the coolest program written in C++ :-)
      • by Z34107 (925136) <zealoussniper@ne ... ape.net minus pi> on Sunday December 10 2006, @01:22AM (#17182020)

        Actually, the "hello world" program using the native Win32 API is:

        int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) {
        MessageBox(NULL, "Hello, World!", "HelloWorldApp", MB_OK);
        return 0;
        }

        You don't need 100 lines of code, obviously. The WinMain function can be a little intimidating, unless you consider that the parameters actually make ince. hInstance is a handle to your program in memory - you only need this if you want to dig icons or other resources out of your EXE while it's running. hPrevInstance is no longer used. szCmdLine is - you guessed it - the command line (rarely used) and iCmdShow is whether your program should be starting maximized, minimized, etc (but can be ignored.)

        Granted, the 100 lines of code comes in when you want to make a "real" Windows app - have a real window that responds to events. But, all this entails is filling out a struct that describes your window, creating the window from that struct, and setting up your message queue. About 1 page of code, but it's the same for every program and you can copy/paste.

        MFC makes this easier, of course, but that's C++.

          • Re: (Score:3, Informative)

            Apart from the fact that the #includes are missing it's not C++. Shure (with the missing includes) it might compile. But it is not the way it is done in C++.

            The Windows API is written in C, and designed for C. Of course it's not C++.

            MFC - the Microsoft Foundation Classes - are a C++ object-oriented encapsulation of the original C API.

            Besides, just correcting parent poster (who didn't use correct cout syntax, or #include . But, yes, you would need a #include at the top of your program, and you'd pro

  • Stroustrups (Score:5, Informative)

    by abshnasko (981657) on Saturday December 09 2006, @06:46PM (#17179188)
    Please... he's one of the most influential people in the field of computer science today, at least spell his name right.
    • This site is about new spam, not accuracy, so keep your hopes down. Gems like this hidden in the muck of Microsoft bug articles (which are needed to pay the bills) still make Slashdot useful.
      • Re:Stroustrups (Score:4, Insightful)

        by EvanED (569694) <evaned@gmailPLANCK.com minus physicist> on Saturday December 09 2006, @07:23PM (#17179506)
        Programming, yes, but computer science doesn't use C++.

        Bull. At least sort of.

        First, it depends in part on what your definition of computer science is. Most CS courses are taught in a C-like languages. At my undergrad institution, most of my programming assignments were done with C++. Sure, there was exposure to ML, but my impression is that most places that's mostly confined to the PL classes. (There are some notible exceptions that use ML or Scheme for intro courses.) Even at those institutions, I expect that later classes have assignments in a C-like language.

        Second, there's a lot of CS that relates to C++. Compiler theory of how you implement things about it, and language design. It's not about C++ specifically, but it certainly relates.

        Third, there is a fair bit of work in PL that directly relates. Not all PL is people in ivory towers coding in ML and Lisp. CCured is a very nice bit of work, though it's only C because it's built on top of the C Intermediate Language (CIL). There's early work now to create a CIL++, and I'm sure that it hasn't escaped anyone there about the potential to extend CCured to C++ once that's done. The parser for CIL++ will be something called Elsa, which was a major part of the research of one of the people there. My own research is indirectly related even. I'm looking at static analysis of binary code. Earlier work done in my group was explicitly directed to being able to find vtable pointers that C++ compilers produce.

        You're right to the extent that the core of CS is really in some sense applied math, and is entirely language-neutral. However, to say that C++ has no relation to CS because it's just programming (which CS isn't about) is just wrong.
          • Re:Stroustrups (Score:4, Insightful)

            by Watson Ladd (955755) on Saturday December 09 2006, @10:08PM (#17180760)
            Penicillin. Lisp. BSD. Shannon's information theory. Smalltalk. The Web. The Internet. All of these came out of academia. Saying that academia is bull is saying that pure research counts for nothing. Well, look at number theory. Once considered unsullied by practical applications it now is used in cryptography. The atomic bomb started as pure research.
          • Re: (Score:3, Informative)

            Yet another huge point here is that when C++ was designed and written it really had one goal in mind, which was to bring the wonders of object orientedness to the unwashed masses of computer programming.

            Er, where did you get that from? I don't think Stroustrup ever said anything like that. See this interview [smartcomputing.com] for example:

            Stroustrup: My main aim with C++ was to be able to express ideas directly in code and have that code execute with close-to-optimal performance. In other words, to write programs that were

          • Re:Stroustrups (Score:5, Interesting)

            by macshit (157376) <miles&gnu,org> on Saturday December 09 2006, @07:51PM (#17179694) Homepage
            Actually the vast majority of recently written (last 5 years) code I've seen from CS departments (at very good schools) has been in Java, with C++ a somewhat distant second. This seems to apply across the board, from hard-core long term research projects to undergrad frameworks to quick experimental coding.

            I don't particularly like java (and it's particularly painful watching the hoops people jump through to make it perform well), but while it doesn't seem to really be the best at anything, I guess on average it turns out pretty well -- it's pretty safe, pretty fast, pretty readable, pretty well supported, pretty widespread, ... One important point that many people seem to ignore is that java seems to have huge number of freely available libraries, often for somewhat specialized subjects.

            The languages you mention are all great languages, and have carved out productive niches, but they seem to remain niche languages, even in academia...

            [Disclaimer: I have never written a java program (!), though I have read many...]
            • Re: (Score:3, Insightful)

              You know why schools teach Java instead of C++? So they don't have to teach pointers first. At least that's how it seems to work at Georgia Tech...

              • Re: (Score:3, Insightful)

                The downside is that you'll have to explain what " public class " is. What " public static void " means.

                The best intro language remains to be pascal. I don't know why people get so fed up with it. Sure it's not as powerful or as popular as C/C++/Java, it's a bit verbose, but the language is clean and readable.
            • CFG (Score:3, Interesting)

              What is a language anyways but a context free grammar? The school I goto teaches Java as the primary language, but once you get into the junior, senior classes you branch out into C and C++ (they even teach Cobol, ewww, I know). Once you take on Automata and Computability, and learn about CFG's then the language isn't the problem. On the other hand, learning a paradigm (like OO vs Structural) can be a bitch.
              • Re:CFG (Score:4, Informative)

                by BitchKapoor (732880) on Saturday December 09 2006, @11:27PM (#17181310) Homepage Journal
                What is a language anyways but a context free grammar?

                Semantics.

                  • Re:CFG (Score:4, Insightful)

                    by Anonymous Brave Guy (457657) on Sunday December 10 2006, @01:14PM (#17185786)

                    I suspect that's because, in the grand scheme of things, parsing is easy, particularly if you can structure your language so that it's simple to parse. It's also easy to write a textbook on parsing, because it's basically a cookbook of the usual methods with a few examples thrown in (though most authors don't seem to be very good at that part, which makes me question how much they really understand themselves and how much is just regurgitating what they once read in someone else's notes).

                    On the other hand, writing a compiler that optimises well (particularly in languages that don't lend themselves to easy optimisation), or a virtual machine that uses JIT compilation efficiently, or code generation engines that support compatible ABIs so you can link across programming languages... those things are seriously difficult. Even with all the effort concentrated on the big commercial tools or the big OSS players like the GCC, it's only in fairly recent times that JIT has become popular, and optimisation over the whole code base of a language like C++ is performed.

                    I've been interested in this field for a long time, and I've never seen a book or a set of lecture notes that come even close to the kind of detail you'd need to understand to write code that does these things. As you said, most of the standard references are just a checklist of compilation stages and a few kiddie examples of parsing that don't really convey the significance of each step anyway. All in all, I think compilation techniques are probably the least understood (and perhaps most misunderstood) of all the major programming areas. That's a shame, because we could certainly do with someone developing a good programming language one of these years! :-)

              • Re: (Score:3, Insightful)

                What is a language anyways but a context free grammar?

                What? What kind of question is that?

                If anything, it's the context free grammar part of languages that is LEAST interesting and, with the arguable exception of C++, easiest part!

                A language is a mapping of syntactic elements to an actual action that the computer will perform. Saying "x ? y : z" is a legal expression means almost nothing; saying "x ? y : z means that the computer will evaluate x, convert it to a boolean value; if it is true, the computer wi
          • Re: (Score:3, Interesting)

            As a bit of anecdotal evidence, I offer up my university - UW Milwaukee. All required programming courses are C++. Electives exist for most of the languages you mention, but no student is required to learn any of them. From what I hear of people I have hired from UW Madison, that school is a Java shop - again, with electives for the more obscure language.

            But then, of course, this is Wisconsin we are talking about. We tend to be practical up here, and have students learn stuff they will actually use in
  • Google's in C++? (Score:3, Informative)

    by feijai (898706) on Saturday December 09 2006, @06:47PM (#17179202)
    My understanding was that much of Google was in python.
    • Re:Google's in C++? (Score:5, Informative)

      by say (191220) <<on.hadiarflow> <ta> <evgis>> on Saturday December 09 2006, @06:53PM (#17179240) Homepage
      Googlebot is mainly written in Python. Google is mainly written in C/C++.
      • Re:Google's in C++? (Score:4, Informative)

        by Anonymous Coward on Saturday December 09 2006, @08:50PM (#17180210)
        No Google bot is written in C++
        http://www.robotstxt.org/wc/active/html/googlebot. html [robotstxt.org]

        When you need high performance, C++ is better choice than any other language. Google(or Yahoo) wont have a single language framework to run its platform. Always it will be combination of languages. Whatever have I read so far Google's core search engine is in C++ and several C++ libraries are available as python modules. Standalone products may be written in specific languages. Gmail and Google Calender are written in Java.
    • No, not the data-crunching engine, not the indexer, not the ranker.... Python (and java, and ruby) is cool, but, frankly... sometimes you need the most of your hardware.
    • Re: (Score:2, Insightful)

      How could something that large and efficiency-dependent be written in non-native code?
          • Re: (Score:3, Informative)

            That's benchmark-dependent. For some benchmarks, under some circumstances, you can generate faster native code during execution than a traditional compiler would generate beforehand.

    • Re:Google's in C++? (Score:5, Informative)

      by LauraW (662560) on Saturday December 09 2006, @07:52PM (#17179706)

      What I usually say when interview candidates ask about this is that back-end and data crunching code tends to be C++, web GUI front-end stuff tends to be Java and Javascript, and scripts tend to be Python. Whatever tool works best for the job. It's not much different from what I've seen at other jobs, except for using Python instead of something like Perl. But there are no hard and fast rules. For example, there was a slashdot article [slashdot.org] last week about an internal web app written in Python. Here's an older article [acmqueue.org] that talks a bit about Google's philosophy for choosing tools. There are various articles [google.com] on Google technologies floating around on the web site too. Before anyone asks, I have no idea what the relative size of the code base in each language is.

      Disclaimer: I work for Google.

  • by Larry Lightbulb (781175) on Saturday December 09 2006, @06:52PM (#17179236) Homepage
    Why try to imagine it, can't we just remember it?
  • by Anonymous Coward on Saturday December 09 2006, @07:07PM (#17179348)
    WorldWideWeb, being on a NeXT box, was written in Objective-C, not C++.
  • by suv4x4 (956391) on Saturday December 09 2006, @07:14PM (#17179414)
    FTFA: I hope you didn't put too much money on it! I don't see aspect-oriented programming escaping the "academic ghetto" any day soon, and if it does, it will be less pervasive than OO. When it works, aspect-oriented programming is elegant, but it's not clear how many applications significantly benefit from its use.

    Totally agreed. AOP is a strange form of "dynamic" insertion of code at special "cut points" of execution within the code and represent a very very lazy way to avoid good OOP structure of your applications.

    In a bigger framework AOP can be totally unpredictable and wreck otherwise locked and working code.

    When AOP started to pick some speed in the beginning I was naturally both interested and slightly annoyed that so short after OOP here's yet another concept for programming I have to learn and implement in my software.

    Not so fast though, since as much as OOP provides useful abstractions that makes your code more readable and predictable, AOP does exactly the opposite except in few very limited cases.

    The cons outweigh the pros.
    • Re: (Score:3, Insightful)


      AOP solves the N times problem nicely. For instance, if you wanted to take an object with N methods and add a call x() to each of them, if you used ordinary OOP, you'd have to override every method, then call x() from each method. What's the elegance of that? I don't see how "proper" OOP can solve this sort of problem better than AOP.

      AOP is largely mysterious and confusing because it's not something (yet) integrated with any standard languages. If it were integrated, then there would be proper tool support,
      • Re: (Score:3, Insightful)

        AOP is object oriented come from [wikipedia.org]. It can trash maintainability. In any program using AOP you can't look at any call in the entire program without assuming there's an arbitrarily large block of code somewhere else messing things up.

        While it's true that AOP can help the classes of problems it solves are fairly small compared to the cost it brings. Instead, adding calls to the first/last line of method implementations is no big deal. Less consistency checking but more debugability. If all you've got is binar

  • Google (Score:5, Interesting)

    by Anonymous Coward on Saturday December 09 2006, @07:23PM (#17179504)
    Claiming Google as a cool C++ program is about 1/3 true. Most Google code is written in C++, Java, and Python: C++ for performance-critical stuff, Python for scripting, and Java for everything in between. The trend is definitely toward Java at the expense of the other two.

    Also, for what it's worth, Google's use of Aspect-oriented programming is ramping up pretty fast.
  • by melted (227442) on Saturday December 09 2006, @07:38PM (#17179618) Homepage
    "Severe resource constraints"? Since when a datacenter with half a million servers in it is called "resource constraints"?
    • by halftrack (454203) <jonkje@nOspAM.gmail.com> on Saturday December 09 2006, @08:19PM (#17179946) Homepage
      Since always ... Getting a 10% performance gain in a 500,000 servers data center could mean a cost saving of 50,000 servers. On 5 servers you wouldn't bother because you wouldn't save anything. The resources we are talking about here are in essence entirely economical and pragmatical. Adding 50,000 servers is not easily done nor particularly cheap.
  • by SEE (7681) on Saturday December 09 2006, @08:25PM (#17179998) Homepage
  • Long Memory... (Score:3, Insightful)

    by evilviper (135110) on Sunday December 10 2006, @12:43AM (#17181798) Journal
    Can you even remember the world before Google? (It was only five years ago, after all.)

    Vividly... Searches for Hippopotamuses turned up porn. Searches for C++ turned up porn. Searches for Slashdot turned up porn...

    Other than the porn, there were dozens upon dozens of pointless hits for sites that only in-passing included the search term you wanted, and perhaps not even that, as search engine databases were often years old, and sites completely changed in that time. What's more, there was never any spell-checker, so with a trivial mistake, you could be wasting all that time with the wrong term, and never find what you want.

    Finding anything was laborious and extremely time consuming. Now with Google, almost ALL search engines have raised their standards near the Google level (alltheweb seems to be somewhat of an exception) and now only a tiny fraction of searches turn up page after page of pointless crap.

    However, Google doesn't seem to be improving much these days, while there are obviously other ideas to be explored. On vague or expansive subjects (or just if you aren't particularly good at searching) Clusty tends to be a better bet, as it automatically categorizes your results for you, allowing you to trivially easily narrow them down... much moreso than if you just included additional categorizing terms in the search.

    Can you imagine the world without the Web? (It was only about 10 years ago.)

    Yes... fondly. Links neatly grouped together in the same spot on every page, not in colors that blend in with the background, in tiny font sizes, or hidden in buggy, inconsistent javascript sub-sub-sub menus.

    No god awful color schemes, or Flash-only sites. No sites that have huge columns on the left and right sides (with almost nothing useful in them) that squish the center column (content) down to one-word-per-line (I'm looking at you, Slashdot).

    Never a single site that depended on your screen resolution (now all but 0.01% of websites are utterly unusable in 640x480 or below).

    No cookies, no javascript, no background images, no BLINK element, no pop-up windows, etc. To make a site, you actually needed CONTENT, not overindulgent designers.

    • Re: (Score:3, Insightful)

      I should probably add that i 100% agree with this statement

      I think that would be misguided. The idea of programming as a semiskilled task, practiced by people with a few months' training, is dangerous. We wouldn't tolerate plumbers or accountants that poorly educated. We don't have as an aim that architecture (of buildings) and engineering (of bridges and trains) should become more accessible to people with progressively less training. Indeed, one serious problem is that currently, too many software develop
        • by MoralHazard (447833) on Saturday December 09 2006, @07:51PM (#17179700)
          Ooh, but your analogy can extend! Sure, I can go down to Home Depot and buy some interior paint to spruce up my living room, or some 2x4s to build a new deck, or something like that. But have you ever heard of building inspections? Anytime you do serious work, like an addition or a new building or even heavy electrical, you're probably going to have to get permits, submit plans, and then have a licensed building inspector come out and check your work. And it if ain't done to code, you're going to have to rip it all out and hire somebody who know what they're doing.

          The reason behind all this bureacratic, intrusive government oversight is that building codes are written in blood. Code specs have emerged over time because people died when buildings collapsed, or bad electrical wiring caused fires. The lesson is that if you're not doing something that could cause injury or death, go ahead and do it yourself. If not, you'd either better learn the right way to do it or hire somebody.

          Code divides into similar categories, although I the decision point is different: Is the failure of this application tolerable? It may be a question of lives at risk (avionics, air traffic control, miliary systems, automotives braking/control, medical) or it might just be economic (my business stops and I lose money when our servers bug out). It's only prudent to analyze your situation and come to a rational decision about whether you want to tolerate the risks of hiring professionals (or learning professional methods and implementing them yourself), versus playing pickup ball.

          Having lived through a couple of start-ups, both successful and unsuccessful, I can tell you that the different approaches do make a difference. I think that's what Bjarne is getting at: if the application matters, you'd better do it right.
            • True, but there are huge classes of applications which are tremendously useful, for which a failure is tolerable, and which are relatively easy to write. So I strongly favor the existence of languages which allow people to write code with only a few months training. And as a professional software developer/computer scientist, I don't feel threatened by it - I wouldn't want to write those applications. When they need something more complex or more robust, they'll come to me.

              Severe ranting ahead, you have bee

    • Re: (Score:3, Insightful)

      Java and C# dont really augment c++. I think what Bjarne meant was they have augmented the programming paradigm in the sense that developers are able to focus more on adressing the problem space rather than the nitty gritty implementation of the the solution.
    • by igomaniac (409731) on Sunday December 10 2006, @05:11AM (#17183002)
      I have quite a bit of experience with C++ and this example is just _one_ of a seemingly unending list of problems that bite the unwary C++ programmer. And without 10s of years of experience, there is _no way_ you can know about all of these. Some of my other 'favourites' are problems related to ordering of construction/destruction of static objects, virtual overrides becoming overloads without warning (try to change one of the arguments of a virtual function to be 'const' in the base class and what happens if you forget to do the same change to the override in some derived class?), all kinds of memory overwrite bugs caused by hanging on to pointers to memory that have been freed, being able to pass the address of an object on the stack out of a function (there is no excuse for this, the kind of program analysis done by optimising compilers could catch this easily -- the worst thing is the code often works at first but breaks much later when no-one has a clue where the bug is). And so on, and so forth...

      Unfortunately the code I write is performance critical, so I have to put up with the nightmare that maintaining and extending a million line of code C++ project is...
      • The answer to this is not to hire unwary C++ programmers, but rather competent professionals. C++ is not a language for newbies or cash-grabbing McProgrammers, and I rather doubt Bjarne or anyone else on the standards committees has ever claimed it was.

        A professional would immediately tell you that you should not rely on the order of construction or destruction for statics, that the derived class implementation will hide the base class one in your const modification case (precisely to prevent the kind of

      • Re: (Score:3, Informative)

        The problem is that two different translation units define two different versions of struct A.

        Relevant parts from Section 3.2 of the cpp standard:
        "There can be more than one definition of a class type ... in a program provided that each definition appears in a different translation unit, and ... each definition of [the name defined more than once] shall consist of the same sequence of tokens ..."

        In the example provided, two translation units have definitions for struct A. However, they are not identical; in
    • Re: (Score:3, Interesting)

      Large part of the many (most?) business applications is glue to the system ("integration"), especially nowadays where much of the basic algorithms (supplied lib), data access (SQL), and UI are handled by underlying systems.
    • And the three Smalltalk books describing it are even more pages than the C++ book, so obviously ObjC is inferior to both? What a stupid way to compare programming languages.

      ObjC is a language which has a core with a static type system, which is somewhat weak because of the ease of casts and on top of that a language with a dynamic type system. So basically you have the worst of two worlds. It is neither as efficient as C/C++ nor as elegant as Smalltalk. And yes, C++ is multiparadigm, structured if you ba

    • Re: (Score:3, Interesting)

      One example would be pass by value, which at the time seemed like the safest default for parameter passing (the thinking was probably to avoid unintentional side effects).

      No, the reason is very simple, C++ was to be compatible to C and C uses pass by value as default. What kind of language would have resulted from passing variables of type int by value and objects by reference? Sorry, but I don't think I would want to program in that.

      Yet to read these articles, it's almost like he still thinks that C++ i

    • Re: (Score:3, Interesting)

      Power is the problem.

      The most powerful flow control construct is if/then goto. It's more power than you need.

      Likewise C++ has more features than anybody needs, although most of the features may be needed by somebody some of the time.

      This is not a criticism of Stourstrup; C++ simply implements what everyone thought was necessary in a high performance OO language twenty five years ago. Since the paradigm was not in widespread use, it's no surprising that the design is different from what we'd come up with
      • by idlake (850372) on Sunday December 10 2006, @08:36PM (#17188982)
        This is not a criticism of Stourstrup; C++ simply implements what everyone thought was necessary in a high performance OO language twenty five years ago.

        Sorry, no, that's false. People knew pretty much as much about OOP and high performance language implementations back then as they do today: dynamic compilation, dynamic optimization, generational garbage collection, incremental compilation, runtime class updating, method dispatch optimization, etc.

        Since the paradigm was not in widespread use, it's no surprising that the design is different from what we'd come up with today.

        We haven't "come up" with anything "today". What happened is that people like Stroustrup incorrectly postulated 25 years ago that efficiency was more important than good design and designed languages without what they naively considered "inefficient" constructs. We have been spending the last 25 years putting these features back in again. Today, Java and C# are almost where OOLs were before C++, except that Java and C# are far more bloated and less consistent.

        Stroustrup was simply wrong, and he could have known better if he had done his homework.