Forgot your password?
typodupeerror
Programming IT Technology

Bjarne Stroustrups and More Problems With Programming 313

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."
This discussion has been archived. No new comments can be posted.

Bjarne Stroustrup and More Problems With Programming

Comments Filter:
  • Stroustrups (Score:5, Informative)

    by abshnasko ( 981657 ) on Saturday December 09, 2006 @07:46PM (#17179188)
    Please... he's one of the most influential people in the field of computer science today, at least spell his name right.
  • Google's in C++? (Score:3, Informative)

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

    by say ( 191220 ) <sigveNO@SPAMwolfraidah.no> on Saturday December 09, 2006 @07:53PM (#17179240) Homepage
    Googlebot is mainly written in Python. Google is mainly written in C/C++.
  • Re:Stroustrups (Score:2, Informative)

    by abshnasko ( 981657 ) on Saturday December 09, 2006 @08:03PM (#17179316)

    Programming, yes, but computer science doesn't use C++.

    Unless you get your CS degree to try to develop a faster sorting algorithm, you are going to be doing some type of programming. He is head of the CS department at Texas A&M, to say he "has nothing to do with computer science" is ridiculous.
  • by Anonymous Coward on Saturday December 09, 2006 @08:07PM (#17179348)
    WorldWideWeb, being on a NeXT box, was written in Objective-C, not C++.
  • Re:Google's in C++? (Score:5, Informative)

    by LauraW ( 662560 ) on Saturday December 09, 2006 @08: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.

  • Re:Bug in C++ (Score:3, Informative)

    by EvanED ( 569694 ) <evaned@gmailBLUE.com minus berry> on Saturday December 09, 2006 @08:58PM (#17179732)
    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 particular, one has members that are ints, the other, shorts.

    However:
    "If the definitions of the [name defined more than once] do not satisfy these requirements, then the behavior is undefined."

    In other words, the compiler is not required to diagnose violations of the ODR (One Definition Rule).

    In this particular example, the compiler compiled bar as if doprint had a four-byte argument* (two shorts) but then threw out one of the definitions of doprint, leaving the other to treat shorts as if they were ints.

    *or maybe an eight-byte argument with misc padding that wasn't cleared
  • by SEE ( 7681 ) on Saturday December 09, 2006 @09:25PM (#17179998) Homepage
  • Re:Java (Score:2, Informative)

    by Iffy Bonzoolie ( 1621 ) <<iffy> <at> <xarble.org>> on Saturday December 09, 2006 @09:26PM (#17180004) Journal
    What do you mean by "see the JVM start up" ? It doesn't have an animation or anything - javac is a native stub that launches the VM and invokes the compiler. It's all within that "javac" process. Now, there is a native Java compiler: Jikes. But last I checked it was pretty outdated. Also, GJC will compile Java to native code, and it is also native, but I haven't played with it yet.

    -If
  • Re:Google's in C++? (Score:4, Informative)

    by Anonymous Coward on Saturday December 09, 2006 @09: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.
  • Re:Stroustrups (Score:2, Informative)

    by Anonymous Coward on Saturday December 09, 2006 @09:59PM (#17180270)
    That's education, not research. Computer science gets done in a variety of languages. Everything from asm on up gets used. C and C++ included. To say that "computer science doesn't use C++" is incredibly ignorant. Plenty of evidence to the contrary [google.com]. Not that it's entirely relevant, but keep in mind that a lot of computer scientists don't write
  • Re:Bug in C++ (Score:1, Informative)

    by Anonymous Coward on Saturday December 09, 2006 @10:53PM (#17180660)
    The real problem is that the linker crosslinks lightweight symbols without checking if those symbols really are equivalent. But the linker folks don't seem to care ("not our bug").


    By the way, ld (the link editor) has has an option called --allow-multiple-definition whose documentation says:
    Normally when a symbol is defined multiple times, the linker will report a fatal error. These options allow multiple definitions and the first definition will be used.
    This tells me that it is a bug in the linker (or at least the linker's documentation).

    Note that ld also has an option called --warn-common whose documentation says:
    Warn when a common symbol is combined with another common symbol or with a symbol definition. Unix linkers allow this somewhat sloppy practise, but linkers on some other operating systems do not. This option allows you to find potential problems from combining global symbols. Unfortunately, some C libraries use this practise, so you may get some warnings about symbols in the libraries as well as in your programs.
    This option does not warn about the issue in question, so I consider that a linker bug as well.

    p.s. The best policy is to disallow header files to define nonstatic symbols. This is fairly difficult to enforce programmatically, but you can at least catch multiple definitions and reject them before linking if you do something along the lines of: nm -ogC --defined-only *.o | cut -d: -f2 | sort | uniq -dc. In this case, you'll get 2 00000000 W void doprint<A>(A const&), which indicates that there are two weak symbols with the name void doprint<A>(A const&), so your custom build process can halt with an error.

    p.p.s. The fix for the case in question is to change its definition to be template<class T> static void doprint(T obj) { printf("The numbers are: %d %d\n",obj.num1,obj.num2);}
  • by iabervon ( 1971 ) on Sunday December 10, 2006 @12:04AM (#17181172) Homepage Journal
    Even Mosaic wasn't written in C++. I'm looking at the 2.7b4 source now, and it's definitely C.
  • Re:CFG (Score:4, Informative)

    by BitchKapoor ( 732880 ) on Sunday December 10, 2006 @12:27AM (#17181310) Homepage Journal
    What is a language anyways but a context free grammar?

    Semantics.

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

    by Chandon Seldon ( 43083 ) on Sunday December 10, 2006 @12:40AM (#17181400) Homepage

    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.

  • by Z34107 ( 925136 ) on Sunday December 10, 2006 @02: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:Java (Score:4, Informative)

    by vocaro ( 569257 ) * <trevor@vocaro.com> on Sunday December 10, 2006 @05:29AM (#17182856)
    Uh, Javac is not written in C++. It's written in Java. Download [sun.com] the source code and see for yourself. It's in the com.sun.tools.javac package.
  • Re:Stroustrups (Score:3, Informative)

    by Ed Avis ( 5917 ) <ed@membled.com> on Sunday December 10, 2006 @09:27AM (#17183676) Homepage
    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 both elegant and efficient.
    Really, the object-oriented part of C++ is not the most important. More useful is the support for generic programming and efficient, type-safe libraries. I do recommend you read The C++ Programming Language, which is to C++ what K&R is to C. The object-oriented stuff with classes and inheritance isn't introduced until quite late in the book. It's a mistake to characterize C++ as 'C with classes', although it might have started out as that in the very beginning.
  • by JLeslie ( 710921 ) on Sunday December 10, 2006 @10:22AM (#17183932)

    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.

    But that is exactly what Java does. I thought it sounded bad at first too, but it works really well.

    Is it so hard to accept that there might be languages which are "better" (I don't even know, if harder and needing more experienced programmers is "better") in some way or other?

    When I first started on Java (I was 'forced' to learn it for a Uni class) I thought it was lame. 'How will I be able to do anything without pointers?!' After a few weeks I gave up the ghost deciding that there was a lot of stuff in Java that made life easier. C++ does need developers that are very experienced--in C++, but I don't think that necessarily makes them 'better'. As I said, it has its place in a few specialised areas, but it's not the general purpose tool it one was. It just seems like Bjarne can't really see that.
  • Re:Only it's not C++ (Score:3, Informative)

    by Z34107 ( 925136 ) on Sunday December 10, 2006 @12:24PM (#17184894)

    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 probably want a #define WIN32_LEAN_AND_MEAN if you want to keep your program size smallish reduce your compile times.

    The C++ (as well as C99) standart define 0 to be the null pointer. With older C standards that was different and there where indeed some platforms with [...]

    That's nice, except windows.h defines NULL to be 0. You can also use HWND_DESKTOP for the first parameter of MessageBox(), or the actual window handle to your program. You're also forgetting that C has been ANSI/ISO standardized, too.

    Most C++ programmers don't actualy know how C++ works. And just because MS used NULL it does not mean it is current standart.

    Silly you - it doesn't matter what the current pointer standard is; the first parameter isn't a pointer, but a window handle (hwnd). Besides, I'm pretty sure Microsoft decides what's "standard" for their own API. You may not want to use NULL in other programs, or you may want to #define your own if you're paranoid about it compiling in Borland Turbo C.

    As for the slam on C++ programmers from a person who didn't recognize C code... We'll leave it at that.

The party adjourned to a hot tub, yes. Fully clothed, I might add. -- IBM employee, testifying in California State Supreme Court

Working...