Slashdot Mirror


Bjarne Stroustrups and More Problems With Programming

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."

20 of 313 comments (clear)

  1. Stroustrups by abshnasko · · Score: 5, Informative

    Please... he's one of the most influential people in the field of computer science today, at least spell his name right.

    1. Re:Stroustrups by abshnasko · · Score: 2, Informative

      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.
    2. Re:Stroustrups by Anonymous Coward · · Score: 2, Informative

      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. Not that it's entirely relevant, but keep in mind that a lot of computer scientists don't write

    3. Re:Stroustrups by Ed+Avis · · Score: 2, 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 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.
      --
      -- Ed Avis ed@membled.com
  2. Google's in C++? by feijai · · Score: 2, Informative

    My understanding was that much of Google was in python.

    1. Re:Google's in C++? by say · · Score: 4, Informative

      Googlebot is mainly written in Python. Google is mainly written in C/C++.

      --
      Roses are #FF0000, violets are #0000FF, all my base are belong to you
    2. Re:Google's in C++? by LauraW · · Score: 5, Informative

      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 last week about an internal web app written in Python. Here's an older article that talks a bit about Google's philosophy for choosing tools. There are various articles 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.

    3. Re:Google's in C++? by Anonymous Coward · · Score: 4, Informative

      No Google bot is written in C++
      http://www.robotstxt.org/wc/active/html/googlebot. html

      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.

    4. Re:Google's in C++? by Chandon+Seldon · · Score: 2, 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.

      --
      -- The act of censorship is always worse than whatever is being censored. Always.
  3. First web browser not written in C++ by Anonymous Coward · · Score: 5, Informative

    WorldWideWeb, being on a NeXT box, was written in Objective-C, not C++.

  4. Re:Bug in C++ by EvanED · · 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 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

  5. "Also, the first Web browsers." by SEE · · Score: 4, Informative
    1. Re:"Also, the first Web browsers." by iabervon · · Score: 4, Informative

      Even Mosaic wasn't written in C++. I'm looking at the 2.7b4 source now, and it's definitely C.

  6. Re:Java by Iffy+Bonzoolie · · Score: 2, Informative

    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

    --
    Run a pencil-and-paper RPG campaign with your far-off friends: Gametable!
  7. Re:Bug in C++ by Anonymous Coward · · Score: 1, Informative
    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);}
  8. Re:CFG by BitchKapoor · · Score: 3, Informative
    What is a language anyways but a context free grammar?

    Semantics.

  9. Re:Coolest and lamest! by Z34107 · · Score: 3, Informative

    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++.

    --
    DATABASE WOW WOW
  10. Re:Java by vocaro · · Score: 3, Informative

    Uh, Javac is not written in C++. It's written in Java. Download the source code and see for yourself. It's in the com.sun.tools.javac package.

  11. Re:Tiresome evangelising by JLeslie · · Score: 2, Informative

    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.
  12. Re:Only it's not C++ by Z34107 · · Score: 2, 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 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.

    --
    DATABASE WOW WOW