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."
Stroustrups (Score:5, Informative)
Google's in C++? (Score:3, Informative)
Re:Google's in C++? (Score:5, Informative)
Re:Stroustrups (Score:2, Informative)
First web browser not written in C++ (Score:5, Informative)
Re:Google's in C++? (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 [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)
Relevant parts from Section 3.2 of the cpp standard:
"There can be more than one definition of a class type
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
"Also, the first Web browsers." (Score:5, Informative)
"WorldWideWeb was written in Objective-C." [w3.org]
Re:Java (Score:2, Informative)
-If
Re:Google's in C++? (Score:4, Informative)
http://www.robotstxt.org/wc/active/html/googlebot
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)
Re:Bug in C++ (Score:1, Informative)
By the way, ld (the link editor) has has an option called --allow-multiple-definition whose documentation says: 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: 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);}
Re:"Also, the first Web browsers." (Score:5, Informative)
Re:CFG (Score:4, Informative)
Semantics.
Re:Google's in C++? (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:Coolest and lamest! (Score:4, Informative)
Actually, the "hello world" program using the native Win32 API is:
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)
Re:Stroustrups (Score:3, Informative)
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.
Re:Tiresome evangelising (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.
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?
Re:Only it's not C++ (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 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.