C++: the Ugly Useful Programming Language

“Aren’t you going to pack this, Mother?” Roberta asked, pointing to the beautiful cabinet inlaid with red turtleshell and brass.

“We can’t take everything,” said Mother.

“But we seem to be taking all the ugly things,” said Roberta.

“We’re taking the useful ones,” said Mother; “we’ve got to play at being Poor for a bit, my chickabiddy.”

When all the ugly useful things had been packed up and taken away in a van by men in green-baize aprons, the two girls and Mother and Aunt Emma slept in the two spare rooms where the furniture was all pretty.

— from The Railway Children by E. Nesbit

Eric Raymond, editor of the [Computer] Jargon File and author of The Cathedral and The Bazaar and a number of well-used but little-known pieces of software, is working on a book, putatively titled Why C++ Is Not Our Favorite Programming Language. In his recent announcement, he lays out why he wants to “harpoon the Great White Whale of programming languages”:

C++ is an overcomplexity generator. It was designed to solve what turned out to be the wrong problems; as a result, it lives in an unhappy valley between two utility peaks in language-design space, with neither the austere elegance of C nor the expressiveness and capability of modern interpreted languages. The layers, patches, and added features designed to lift it out of that valley have failed to do so, resulting in a language that is bloated, obfuscated, unwieldy, rigid, and brittle. Programs written in C++ tend to inherit all these qualities.

In the remainder of this paper we will develop this charge into a detailed critique of C++ and the style it encourages. While we do not intend to insult the designers of C++, we will not make excuses for them either. They repeatedly made design choices that were well-intentioned, understandable in context, and wrong. We think it is long past time for the rest of us to stop suffering for those mistakes.

C++ is my own favourite programming language, not that I am any great expert, given that the only other language in which I have brought any other project to fruition is Java, and that was in 2004. This is not to say that C++ does not have its fair share of annoyances, but as the title is not Why C++ Sucks but simply why it’s not their favourite, I will lay out why it remains mine, and more to the point, why it endures despite the existence of alternatives such as Java.

To be fair, I don’t know if Raymond and his friend Rob Landley have the same bugbears about C++ as the people who have put out various “reformed” object-oriented C-derived programming languages, but the results usually involve the stripping out of not only the irritating features and bloat, which may be a consequence of layering object-oriented features onto an existing language, but a whole lot of useful features as well. The usual suspects are operator overloading, multiple inheritance and the macro preprocessor. Java got rid of all three, C# and D, a more recent attempt, get rid of all but the first. (Note: I will attempt to explain the terminology in layman’s terms.)

Operator overloading is programming an operator (i.e. a mathematical symbol or brackets) to do what you want them to. This means that, when you’re writing code to handle lists or other data structures, you can use symbols, or allow the programmers who use your code to use them, to manipulate or chop up their data by using the plus sign to add a bit onto the end of the string or list, to use an equals sign to test for whether two strings are identical, and to use square brackets (as was common in C) to identify a particular item in the list. You cannot do any of this in Java, so to identify item three in a list, you have to type something like “list.item( 3 )”, rather than simply “list[3]”.

The reason commonly given for stripping out this feature is that it facilitates obfuscated code (i.e. code whose meaning cannot be easily discerned when another person takes over its maintenance or wants to use it to build something for himself). However, they are also commonly given perfectly sane and logical meanings, such as + for adding and = for testing sameness.

Multiple inheritance is described here; it means that your class (a sophisticated type of data structure, which includes functions as well as data) can include the features of two or more classes, rather than just one. A common criticism of it is that nobody ever uses it; Jesse Liberty, in his book on C#, had said that in years of teaching C++, he never used it other than to demonstrate to students that it could be done, and he’s never missed it as a C# programmer. The toolkit I use to write the blogging client I used to write this article offers multiple inheritance as one way of implementing forms designed in their form designing program, Qt Designer, and I use it myself (not all the time, but some of the time). So there goes the claim that multiple inheritance has no uses or that nobody uses it.

Finally, the macro preprocessor. This is a means of getting the compiler to substitute one piece of text for another when the program is built. What use could that possibly be? For one thing, you might just want to have to save a regular long bit of typing, but macros have other uses. Suppose you don’t know which version of a particular library your end user will be using, and perhaps a given class will be present in a later version but not an earlier one; you might want to allow the newer class to be used if it’s there, and the older one if it’s not, and use the same word to refer to them both because they have similar interfaces, and perhaps the library tells you (via a macro) which version is present, which enables you to exclude bits from your program which only pertain to the newer library. I use this feature myself in QTM; newer versions have a lightweight plain-text editor while older ones don’t. I can do this in C++ because of its preprocessor, and more to the point, I can exclude bits that are not needed from the finished product, which makes things a bit more efficient.

The preprocessor even allows for features to be added to C++, such as the “signals and slots” feature in Qt (signals and slots means pre-arranging for one thing to be done when another thing happens, such as a web page to be loaded when you type in an address and press Enter). Most of the methods I have seen for implementing this feature in C++ use macros, and although there are alternatives, the macro-based system used in Qt is the cleanest and least complicated I have come across.

The Jargon File has an entry for what he calls a “bondage and discipline languages”, which is a language “that, though ostensibly general-purpose, is designed so as to enforce an author’s theory of ‘right programming’ even though said theory is demonstrably inadequate for systems hacking or even vanilla general-purpose programming”. A typical example is Pascal, about which Brian Kernighan, co-originator of the Unix operating system and documentor of C, wrote an essay entitled Why Pascal is Not My Favorite Programming Language, the reasons essentially being that it is a teaching language unsuited for serious programming, lacking an awful lot of functionality that C programmers (C++ had not yet been invented then) take for granted. Kernighan noted that Pascal had been extended in various ways, but that these extensions resulted in various incompatible versions of Pascal; one criticism of C++ is that, because of its complexity, different programmers learned different subsets of it, such that these programmers have difficulty working together on a project in the same language.

C++ is the opposite of Pascal; it gives you everything that C does (and Pascal doesn’t), and layers object oriented features on top of it, basing them on C’s existing data structure syntax (rather than a bolted-on one, as in Objective-C). Perhaps some might say “C++ has the exact opposite problems to Pascal”, but others might say it gives you freedom, treats you like a proper programmer rather than like a student, and allows you to program “straight to the metal”. Many of the “C++ replacements” are not designed for the last purpose; they are designed for programming virtual machines, i.e. other computer programs, rather than actual computers, and often for less serious applications, such as in-house database front-ends. There are very few proper applications, especially commercial applications, written in Java or C#, simply because they are not as fast as any program which actually runs on your computer.

Java and C# are a step away from the freedom of C and C++ towards a dictated programming style; they hide features of C++, such as pointers, to make it less easy to make mistakes, when the ability to use or not use pointers is power and flexibility, even if there are more pitfalls. Java makes it easy to “finalise” a class, meaning anyone who wants to use the class in their own programs cannot build their own classes on top of it. This is possible in C++ as well, but it does not seem to be as common. Java’s string class is final, for example, as is the window class in the Standard Widget Toolkit (SWT) used in Eclipse. Of course, some might say it’s not good programming practice to put all your application’s functionality into the window class, but it’s a programmer’s choice. If I pay money for a class library, I do not wish to be dictated to how to use it; if it’s free, it is hardly logical that you can freely redistribute or modify a class, but you cannot subclass it! (Perhaps this is compensated by the fact that in C++, any function in a class can be declared virtual, meaning that it can be overridden by having a function of the same name in a subclass, but the default is that it is not; by contrast, all functions in Java classes are virtual.)

Then there is the added verbosity of Java: the fact that you cannot put all your public, protected or private functions or data in a list, with “private:” or whatever at the top, as you can in a C++ class header, for example. You have to put public or private next to each item. Your “main” function has to be “public static void Main”, when in fact Main is always “public static void”, so why can you not just put “Main”? Why does Main have to be void anyway, preventing you returning an exit value (to tell whichever program called yours how it finished, i.e. whether the job got done or not)? Why does Main have to be in a class at all?

Bjarne Stroustrup, the inventor of C++, is quoted as saying that “within C++, there is a much smaller and cleaner language struggling to get out”, and Raymond adds that many hackers would say that this language was Java. However, Java is a stripped-down language intended for programming a closed system in a specific style, while C++ gives you the computer, allowing you to manipulate objects as flexibly as C allows with raw data. Perhaps somebody can come up with a new language which does all these things as well as C++ does now, with all the power that C++ has and Java takes away, and none of the annoying features. Otherwise, we will end up with yet another stripped-down C-like object-oriented language, probably with yet another standard library with a different vocabulary, and which is incompatible with all the others - a problem which C++, despite its groups of programmers who learn different subsets of C++, does not have: they can all at least use what others develop.

I find some of the complaints about C++ to be petty. One complaint was that, on encountering the “< <” symbol used in a “Hello world” program in a popular C++ tutorial, he “got lost”. This is the fault of that one book (my tutors at Kingston University did not explain it all that well, either), not the language; it is a function disguised by a symbol. He also mentions that he asked “what’s with the colons?”, presumably meaning the “::” operator, known as the scope resolution operator. This actually makes it clear whether what is to the right of it pertains to the class itself (like a public static method), or to an object of a class; why would anyone want to get rid of an operator which makes this explicit?

A few years ago, in response to a question I posed at a Linux Expo in London, I was told that C++ sucked, and was for programmers who could not implement object-orientation in C, as the GTK+ graphical toolkit supposedly does. Matthias Warkus, in The Official Gnome 2 Developers’ Guide, notes that “to put it bluntly, defining a class in GObject [the basis for GTK’s so-called object orientation] isn’t easy” and that the procedure would “look quite awkward” to anyone used to C++ or any other object-oriented language. The FAQ for GTKmm, the C++ interface to GTK, claims that “the derivation of new widgets in GTK+ C code is so complicated and error prone that almost no C coders do it”. However, C++ offers a ready interface to a C-based graphical library. It, and not Java or C#, let alone Python, is the logical choice for developing non-trivial, object-oriented graphical applications.

Yet another complaint, from this article (not by Eric Raymond, who says that the author “understands that C++ sucks, but he’s enumerating symptoms rather than dissecting causes”) also entitled Why C++ Is Not My Favorite Programming Language, gives the example of a Perl script which manages to grab content off the web and output it in five lines, while the equivalent in the C++ library he chooses to use as an example takes twenty. Qt can do the same in considerably fewer lines (note that SomeClass can be any subclass of QObject, which provides Qt’s signals and slots, http is an object of class QHttp and textBrowserObject is an object of class QTextBrowser, both of which are QObject subclasses):

SomeClass::someFunction()
{
http = new QHttp( "www.demiurgestudios.com" );
connect( http, SIGNAL( done( bool ) ),
this, SLOT( handleDone( bool ) ) );
http->get( "/blog/2007/10/why-c-is-not-my-"
"favorite-programming.html" );
}

SomeClass::handleDone( bool error )
{
if( !error ) {
textBrowserObject->setHtml( QString( http->readAll() ) );
}
}

That’s twelve lines (excluding whitespace and with the connect and get calls each reduced to one; they have been split to fit them on the page), and five of actual tests or calls to functions. Why does the result of the GET request have to be in another method? Because Qt’s HTTP requests are asynchronous, meaning that they do not block a graphical user interface’s operations (i.e. make it look like it’s crashed), so your program can keep working while the page is loading. However, even though this shows that it’s possible to write a C++ library to get an HTML document from a website and display it in less than 20 lines, the fact is that Perl does this in five lines because it’s a scripting language, and is thus necessarily a high-level language which takes care of the low-level business for you, while C++ is a low-level programming language, or rather a potentially multi-level one. Someone, somewhere, wrote the code (in C) that’s behind those five lines of Perl, and there is probably more than twenty lines of it, just as someone wrote what’s behind the five lines of C++ by which you can do it in Qt. The reason the author of that essay was frustrated is that nobody did, in the case of the library in his example.

To conclude, if C++ is to be overhauled, it needs to be in favour of something as powerful as it is, and not yet another stripped-down object-oriented language like Java. It needs to provide ready access to the C library and all the things the “safe” C++ derivatives lack. It needs to treat me like an adult, giving me the world inside my computer, not a walled garden. Can Raymond and Landley come up with an alternative that fits this bill? Then again, perhaps I am reading too much into all this, because in my experience, Qt demonstrates that producing a library which offers a sane C++ programming environment is possible. If I were to go inside the former Trolltech offices (now the Qt Software unit of Nokia) and repeat the claim, which originates here but cited in a comment on Eric Raymond’s blog entry, that there “is no reason to use C++ for new projects”, I would be presumed drunk and escorted out of the building. I would like to know what the developers of Qt would change, if anything, about C++.

Possibly Related Posts:


Share
  • jliberty.pip.verisignlabs.com

    Just more or less “for the record,” you quote me as saying that I never used M.I. and that I don’t miss it, but then attempt to refute that with the fact that you use it, and state “So there goes the claim that multiple inheritance has no uses or that nobody uses it.” — But of course, I never claimed that.

    Actually, what I believe I’ve said for some time is that it has no real world use I’ve found that can’t be handled better with interfaces, and that I never used it except to show how it works, and that I don’t miss it. That is, I think you’ll agree, different; and not at all refuted by your using it, your liking it and your missing it if it goes away.

    Good article, though.

    Thanks.

    -jesse liberty Silverlight blog Everything Else

  • http://mythicant.com Jon

    “There are very few proper applications, especially commercial applications, written in Java or C#, simply because they are not as fast as any program which actually runs on your computer.”

    I would beg to differ.

    “To conclude, if C++ is to be overhauled, it needs to be in favour of something as powerful as it is, and not yet another stripped-down object-oriented language like Java.”

    You mean like C#?

    “Why does Main have to be void anyway, preventing you returning an exit value”

    In C# the Main method can return an integer value.

    “Java and C# are a step away from the freedom of C and C++ towards a dictated programming style; they hide features of C++, such as pointers”

    You can use pointers in C#. You just have to explicitly state that you want to use them. Protecting you from yourself but giving you the freedom if you need it.

    I could continue, but I won’t.

    I know how easy it is to get defensive when your language of choice is under attack. I do it myself. But it seems as though you’ve struck out a little too far. Many of your arguments have merit when taking Java (which you state as being the language which you are the most familiar with after C++) into consideration, but are not valid when extended to many other languages (which you attempt to do) and C# in specific (my current language of choice, though I have used Java and C++ as well as others).

    My personal opinion is that C++ has its place, but that that place is not general, client-side application development or web development. If I need some part of a program to interact “straight to the metal” as you put it, then C++ would be a great option. I would include OS kernel development, writing drivers and cutting edge 3D game engines in that category. However neither I nor anyone I personally know does any of that kind of development (there obviously are non-zero sized groups of people doing all of those kinds of development). For the kinds of development I do and that most of the developers I know do, a more elegant, less “straight to the metal” language allows for much faster, more efficient development which is easier to debug and is ultimately a higher quality product for the same amount of effort.

  • http://meneame.net/story/c-feo-util-lenguaje-programacion-eng meneame.net

    C++, el feo y útil lenguaje de programación [ENG]

    Eric Raymond, famoso programador y autor del texto La Catedral y el Bazar está trabajando en un libro que titulará Por qué C++ No Es Nuestro Lenguaje de Programación Preferido. Según el propio Raymond, "C++ es un generador de sobre-complejidad. Se…

  • anonymous

    I think this article betrays a lack of commercial development experience on the part of the author. Especially this:

    Many of the “C++ replacements” are not designed for the last purpose; they are designed for … less serious applications, such as in-house database front-ends. There are very few proper applications, especially commercial applications, written in Java or C#, simply because they are not as fast as any program which actually runs on your computer.

    IMO, this paragraph blew any credibility you had waaay out of the water. You actually make some decent points in the rest of the article, but that’s just too big a whopper.

    Firstly: “There are very few… commercial applications written in Java or C#”? Seriously, what planet are you living on? I don’t think it’s the same one I’m on!

    Secondly, you seem to imply that applications not written in C++, or those that do not get “straight to the metal” are somehow “less serious” or not “proper” applications, which I think shows, at best, a lack of experience with other languages and their applications, and, at worst, blind prejudice.

    Is C++ somehow superior, because people use it for systems programming instead of those those “database front-ends”? No. If anything, it simply means C++ is inferior for programming database front ends! Sure you could do it in C++, but most people need to knock up those database front-ends, and do it quickly, and easily, without in-depth knowledge of a powerful language like C++, and all that mucking about with pointers, exceptions, templates, compilation, manual memory management, etc. Writing good, bug-free C++ apps is hard and time-consuming. Doing so quickly with minimal training is beyond most people. In most applications, the language needs to just get out of the way and let somebody do their job. C++ is, IMO, a very “in your face” language. (Java doesn’t get off lightly there either.)

    Use the right tool for the job. C++ is something of a Swiss-Army knife, but that doesn’t make it ‘superior’ to any other language that is domain-specific, or otherwise limited in scope. Ever heard the phrase “Jack-of-all trades, master of none?”. The vast majority of people are not doing systems-level programming, or time-critical stuff, so C++ probably isn’t the right tool for them.

    Most commercial applications will sacrifice “bare metal” coding and performance (and all the difficulty that entails) for fast development, robustness, fewer bugs per line of code, reliability, readability, flexibility, ease-of-use, scalability, concurrency, maintainability, cheaper developers, productivity, affordability, and many other qualities. Otherwise we wouldn’t have the proliferation of languages, and the current massive trend for Java and C# development that we see today. Oh, except you didn’t seem to know about that. ;)

  • Cade Foster

    To whom it may concern, I was a C coder during 1990-1996 (during my engineering doctorate days) and since 1996 have been a C++ coder (contracts/private research).

    In my opinion, the jump from C to C++ was a “god-send”.

    It has given me the freedom to implement:software paradigms geared to the effective handling of the intended problem-domain ( easily “avoiding one size fits all” approach). I have very useful debugging facilities and an admirable freestore management facility making pointers fun (not scary) to use accompanied with simple/efficient memory leak detection.

    C++ has the potential to solve a wide cross section of problems but this also depends on the mettle/spirit of the coder. C++ is not for everybody and I do not have a problem with the myriad of other languages that exist today. I do have a problem when “mimimally trained” coders are allowed to work on “serious” projects requiring mature design/implementation skills.

    Design and implementation skills have to be earned, not largely borrowed. Design patterns are important and you may have coded to an extent where your own code reflects the more common design patterns and that is a very good sign that you are on your way on being a SUPERMAN-like figure as you are using C++ to effectively produce software solutions for the intended problem-domain.

    The above comments are based on experiences using C++ for implementing 3D engine/tools, GUIs, database/data-mining tools, scripting language, research on numerical/AI algorithms.

    Alas, many people will not have C++ as an effective tool since it requires more than “minimal training”. This is not necessarily a negative point since simpler problem domains do exist that would be more suitable for less-trained people.

    It would be likely that relatively fewer super-men/women would exist that would shine with a language like C++.

    Cade

  • spikeysnack

    Well, There is again the Troll factor here; as in all lang wars, the didacts come a.out to play();

    As a C-trained programmer coming up through the university system in the mid 90s, C was THE thing. Pascal and the new thing from Sun (Java) were taught as intro courses, and C was it for systems programming and Data Structures and Algorithms. Interestingly, Fortran was taught to all non-CS majors as they needed it for their Post-Grad majors (Biology, Physics, Math ..) Fortran had superior facilities for matrices and multi-dimensional data tables and was the language of choice for the CRAY supercomputers. The Official US Government Programming language (ADA) was dying out, but was offered as an elective for Military students and masochists. C++ began to be taught toward the end of the 90s but it seemed that java was favored as it was easier to read by teachers as there were far fewer ways to actually do the assignments so the code was basically the same student to student. The Biggest barrier for learning any language at the beginning seems to be its IO mechanisms, and C,C++,Pascal and Java all have quirky ways to input and output. Usually in C the student learns IO as an early programming assignment in and of it itself, but with C++ and Java the Teachers have to supply “IO sugar” classes to get the students over the hump of “System.IO.Console.writeline(System.String.StringFormat F, String S)” and the >>

  • DavidG

    @ Jon, C# is slower and has a higher memory overhead, this is undebatible. Memory overhead is immediately obvious when you consider that every object in C#/Java have a base object that contains members which include some type info. When you have a program with millions of objects at runtime, and each of these base objects stores a few bytes, you have a few mb more memory taken. When using a mobile device ( iphone for example ), this makes a huge difference, and hence C++/C/Obj-C are the best options. C# is slower because it is memory managed, and there has to be overhead where memory management happens. Also in C# you have less control over the raw memory usage, so a sloppy C++ coder might produce similar performance to C#, but in C++ there is almost always a lot of room to optimize. Don’t get me wrong, i like C# for some things, its a great lang to prototype stuff and get stuff done quickly, but C++ runs on the raw hardware, and when you need that speed, C++ is probably the best way to go.

  • Nick

    @ Anonymous

    You are obviously not a programmer. Could you troll somewhere else please?

  • Isak

    Just for the record, a C# program will always run on the raw hardware. After the final Just-In-Time compilation, the code that runs is x86 assembly, just like any other C or C++ program.

    People often forget this and tends to think that C# is just another interpreted language. It’s not.

    (I think the above is true for java too, but I’m not 100% sure)

  • DavidG

    @Isak Doesn’t a C# application run on top of the CLR, allowing for things like reflection? That was always my understanding. Fair enough, the CLR runs as x86 assembly, but the C# app itself runs on top of that? Apologies if im wrong. Java is compiled to “bytecode” which is then interpreted and run by the JVM, so altho it’s compiled, it’s also interpreted. The JVM is a requirement for Java, and hence the assembly isn’t really assembly, its as if it was built for a different machine ( namely the JVM ).

  • DavidG

    @Isak Confirmation from http://channel8.msdn.com/Posts/MSIL-the-language-of-the-CLR-Part-1/ an MS tutorial site about the CLR ( Common Lang Runtime ) and MSIL ( MS intermediate lang ) C# is not compiled to x86 assembly, it is compiled the MSIL, which is then run on the CLR, pretty much just like Java. Quote from the above link: “What is MSIL?

    Microsoft Intermediate Language (MSIL) is what all high level languages that target the CLR compile down to, e.g. if you code some C# and then use the C# compiler (csc.exe) you don’t actually get as output a native representation of your code (whether that is x86, x64, IA64) what you get is an architecture neutral intermediate representation of that code - MSIL.”

  • M Risbrook

    C++ was never intended to be a mainstream language for commercial programming in the first place. It was invented as an experiment at Bell Labs to add OOP capability to C. It’s popularity in commercial programming was the result of IT managers in the 1990s incorrectly assuming the jump from C to C++ would be small, and similar to moving from FORTRAN 77 to FORTRAN 90, thereby resulting in companies retaining their investment in existing staff and programs written in C. Many a time you find job applications saying C/C++ programmer. Does the company want a good C++ programmer who knows a bit of C, or vice versa? Many good C++ programmers aren’t very good C programmers, and many good C programmers don’t know much C++.

    Criticisms of C++ tend to be directed at its complexity and the features it has. My biggest criticism of C++ is not the features it has but the features is doesn’t have. Just because C++ has features like operator overloading and multiple inheritance doesn’t mean that every programmer has to use them in every program. In fact many programmers don’t use them at all. What C++ lacks are standardised higher level features such as hashtables, graphics, networking, and effective error handling. The success of Java isn’t because it is a clean OOP without the complex baggage of C++, but because of its rich collection of high level features provided as standard. This enables inexperienced programmers to create “cool” software with little effort. In contrast, most C++ books don’t even tell the reader how they can draw a circle on the screen or make the text blue.

    The key to improving C++ isn’t stripping out features in the style of C# (which can only be used to create programs for Windows) or Java, but by adding in new features that users want and features which will make programming easier.

  • pcunite

    I use C++ for database front ends. What is so complicated about the following lines of code? I am afraid that the C++ haters have come to late to convince me that I should learn a new language every five years (java, c#, perl, ruby) and profit from all their seminars and book sales.


    class Paper { private: std::string Color; std::string Text;

    public: Paper(); ~Paper();

    // Getters std::string GetColor(void); std::string GetText(void);

    // Setters void SetColor(std::string Color); void SetText(std::string Text); };

    // Create some blank paper. Everthing is free inside the computer! Paper1 Paper; Paper2 Paper;

    // Set some info about each piece Paper1.SetColor(“White”); Paper1.SetText(“Buy some eggs and Milk\nDon’t forget the cheese!\n”);

    Paper2.SetColor(“Green”); Paper2.SetText(“You may have already won one Million Dollars!\n”);

    // Create a container to hold paper and put some paper in it. std::vector MyTrashCan; MyTrashCan.pushback(Paper1); MyTrashCan.pushback(Paper2);

    // See what is in the Trash can. Thus: for (size_t i = 0; i

  • Fernando

    @DavidG

    Yes, the C# compiler output is MSIL, but the JIT translates the intermediate representation to native as needed right before the code is executed. See this article Compiling MSIL to Native Code

  • M Risbrook

    If the owner of this blog knows so much about C++ programming then why does he work as a truck driver rather than a software developer? Equally intriguing is why does he have a degree in politics rather than something computing related? Is programming something he has only got into since graduating?

  • Paulo C

    Nah, C++ it’s nice, much faster then Java or C# and very easy to program when you use great frameworks like QT4

    For me the best options are Ruby for rapid application development and web, and C++ Qt4 for serious desktop applications

  • http://mythicant.com Jon

    @DavidG

    Did you read my original comments? My premise was that using a language other than C++ results in more efficient development for client-side applications. I state that for for some types of development then C++ would be an ideal choice. But that client-side development is not such a case. If you’re talking about user interaction speeds a few milliseconds difference in performance will not be noticeable. The increase in development time due to the added complexity of a more “straight to the metal” language will be very noticeable.

    And for the record, a C# application being slower and taking more memory than a C++ application is debatable. Now I will definitely agree that in the general case a C# application will be slightly slower and take slightly more memory, but not in all cases. There are some situations (I’m sure not the majority of cases, but they do exist) where C# code runs faster than C++ code. This is due to the optimizations that can be done at run-time by the CLR. A normal C++ application can only perform optimizations at compile time. But going back to the general case where C# is slower than C++, we are generally talking about a difference of milliseconds or less. For most applications the user will never notice a difference. As stated above, they will however notice if your application takes longer to develop because you’re trying to gain that extra 5% of speed by using a more “straight to the metal” language.

    My machine has 8GB of RAM. I don’t care about a few extra MB if I can develop my app significantly faster (which I can). I don’t think I’ve ever written an application that has millions of objects anyway (thousands, yes. Millions, no). I have four cores. One can run my application, another run the garbage collector, and I still have two left over for whatever else I want. Obviously those specs are for a dev machine as opposed to a normal user machine, but 4+GB of RAM and 2+ cores is pretty much standard now. Sorry to harp on this again, but it’s really my point: my users won’t notice a few extra MB of RAM used or a few extra CPU cycles being taken up. Their machines are already faster than they know what to do with. The extra months or years saved on development time because I have helpful tools like garbage collection and objects will be very noticeable. (Thinking about it your argument that objects = bad is an odd one, since isn’t THE main feature going from C to C++ the addition of object oriented features? Did I miss something?)

    “C++ runs on the raw hardware, and when you need that speed, C++ is probably the best way to go.”

    When you need that speed C++ probably IS the best way to go. That’s exactly what I said in my original comment. However, for the vast majority of normal, business applications that the vast majority of users care about, you don’t need that application speed. Instead you need development speed, where a choice other than C++ is probably the best way to go.

  • mark

    pcunite you just demonstrate that you are ignorant. You can do THE VERY same in both ruby and python with less characters.

    The ONLY difference will be in speed. But I happily trade speed advantages over my own life time by simply implementing something faster in a higher, easier language than C++.

  • mark

    Risbrook btw, does it matter what kind of degree anyone has on a topic? Take economic professors in the USA. They developed the shock syndrome to induce massive debt onto other countries (hi chicago university)

    If someone makes good points, it DOES NOT MATTER IF HE HAS A DEGREE OR NOT.

    Quit doing those argumentum ad hominmen

  • George Carty

    M Risbrook,

    I suspect that “no job without experience, no experience without a job” is the problem - no doubt exascerbated by the glut of programmers which resulted from the bursting of the dot-com bubble…

  • Cyril

    Hi,

    Just for your own interest, preprocessing isn’t required for “signal/slot” functionnality. QT using it’s own preprocessor doesn’t mean it’s the standard.

    You have another library that’s really, really simple to use and learn, it’s Juce ( http://www.rawmaterialsoftware.com/juce ).

    In this library, preprocessor stuff is kept to a minimum. After all, macro trickering is probably the hardest concept to understand, if even possible. That’s why they “invented” templates, and that’s why it’s highly discouraged to use preprocessing except for “version checking” in the last standard.

    For me, the most confusing thing about C (not C++) is the preprocessor stuff (try to #define i 23 anywhere, and you’ll broke every C program written so far).

    Every other feature (operator overloading / templates / multi inheritance) have a real use, and I really, really miss them in C# or Java (and no, C# doesn’t allow you to use pointer like said above, it allow you to marshall pointer, that’s completely different).

  • Ropieur

    New standard library is under development (look at http://www.boost.org). Part of boost has been proposed and under acceptation. Unfortunately, the standardization process is very slow (this is due to the complexity of the standardization). The difference with Java and C# is that the standardization is monopolized by respectively Sun and Microsoft. Boost libraries is a second big step (after STL). It is certainly not enough but it advances slowly (too slowly ?) and surely.

  • Sorpigal

    A lot has been said in defense of C# about how it really isn’t as bad as the author claims. Most of the same and more could be said about D. D is really the perfect successor to C in a way that C++, Java and C# really aren’t. Pointers? Check. Bare metal? Check. All of the things the author complains are stripped out of Java and C# are present in D, or can be accomplished in a slightly different but equally powerful way.

    What D lacks is a Microsoft to push it or a sufficiently broad open source project to drive it. It’s a fine, fine language.

  • Patrick

    @Risbrook

    ”..why does he work as a truck driver rather than a software developer?”

    Oh jesus, what does that have to do with anything?

    Anyway…

    The scope resolution operator “::” should go away. C++ already has two: “.” and “->”. Why is Classname::classthing better than Classname.classthing? Or why is namespace::token better than namespace.token? By the same token classobj.classthing should also go away. By class_thing I mean all non-instance things.

  • Paulo Cesar

    @jon “I state that for for some types of development then C++ would be an ideal choice. But that client-side development is not such a case. If you’re talking about user interaction speeds a few milliseconds difference in performance will not be noticeable.”

    Are you gone nuts? Sorry, but I work with Netbeans on my daily basis, and by far it’s one of the worst things I have to do on my job.. Everyday on my work I pray to Flip-flop God that some illuminated soul make a Ruby on Rails IDE in c++ because I just HATE having to wait almost a minute for a advanced Core2Duo process a fucking “go to file”

    So don’t come with the stupid idea that, oh .Net and Java are the most perfect thing on the world and if our users don’t have 8gb of RAM and Core2Quad overclocked and with liquid nitrogen cooling system, that’s not our problem!

  • Chris

    Every language has it’s pros, and it’s cons. No language is perfect. Could C++ be improved ? - Yes. Is there scope for another, better OO language which hit’s the machines metal, rather than a virtual machine - Yes.

    But right now it doesn’t exist.. so “you pays your money and you takes your choice.” - for me that’s currently C++. But if something better comes along, (I don’t really care about pascal v’s c syntax) I’ll probably take it.

  • Arpad

    All the programmers who say that Java and C# are interpreted languages, should be sent to pension. They did not follow IT trends for the last ten years.

    The Sun JVM is probably the best piece of software ever made. Java programs are interpreted in the first 30 seconds, until the JVM chooses the best optimization methods, and are compiled by JIT to machine code, and run as native after that.

    JIT vs static compilation: The JIT can choose to use CPU specific instructions. In statically compiled C, you either have to compile multiple binaries, or add code to handle the differences at runtime, but then you are starting to use virtual code, just like in the JVM.

    Overhead of JVM: It comes from heap object allocation and mandatory bound checks. There is no stack allocation currently in the JVM, which has two drawbacks: the heap allocated object needs to be processed by the garbage collector at some point, and its harder to take use of CPU cache, because its not guaranteed that objects lie continuously in memory. It is possible to get around this by conscious optimization, it is not like C optimization, but possible to an extent. The bound checks on arrays is added by the JVM, i hope the JVM will be able to optimize that away in some future release.

    When working in C++ i had the vision of the class file as working on a source code file (the preprocessor enforces that view), while in Java i always have the view of working on a class, and not on a piece of source code. It is a more healthy mind-set.

    Before two weeks i went to evaluate some C++ code, and its ugly compared to Java. Readability of C++ is a disaster. So i went and installed D, which is compiled the same way as C++, but has no preprocessor, and is just as readable as Java. I’m going to write native stuff in D from now on.

  • fsilber

    I believed C++ was doomed for having been based on C. First of all, the inside-out notation for declaring pointers was motivated by the desire for one-pass compilers on primitive computers such as the PDP-11. The second mistake was using pointers to implement and access arrays. The third was using zero-terminated character-arrays as strings.

    If you throw those out, you could probably create an object-oriented language with manual memory management that is much simpler, more coherent and predictable, and probably just as efficient.

  • http://mythicant.com Jon

    @Paulo Cesar

    Does no one here actually read comments? I can see I’m going to have to stop posting here. Either that or write shorter, easier to read posts. Goodness.

    “Everyday on my work I pray to Flip-flop God that some illuminated soul make a Ruby on Rails IDE in c++”

    You use a sucky IDE so therefore the language in which its written sucks? As other posters have mentioned, it’s not any harder to write sucky applications in C++ than it is in any other language. Your argument is like saying that Spanish is a terrible language because someone wrote a book in Spanish that you didn’t like.

    “if our users don’t have 8gb of RAM and Core2Quad overclocked and with liquid nitrogen cooling system, that’s not our problem!”

    Did I say that? I said that’s what my work machine has. I specifically stated that my users’ machines don’t have specs that good but that it doesn’t matter, because their machines are still faster than they know what to do with. I would say that my typical user machine is actually a P4, painfully out of date by today’s standards. And you know what? They still pay thousands of dollars for our .NET applications and think they run plenty fast enough (the ones that are written well. The ones that are written poorly are a different story, but that would be the case regardless of the language).

    As I mentioned in my original comment, I know it’s very easy to get worked up when you feel like your language of choice is under attack. I know because I get that way myself sometimes. But impassioned, illogical arguments certainly don’t help your case.

  • Some Programmer

    C# can use preprocessor macros.

    C# can use raw pointers.

    C# can do operator overloading (though perhaps not quite as extensively).

    Statements to the contrary are just wrong/misinformed.

    Just sayin’.

  • Airdrik

    I have to agree with a lot of what the author has said. The world could use a new systems programming language with all of the power, speed, low-level-access, etc. of C++, using a more elegant syntax.

    Such a language should take into consideration all known language design constructs, and select the best selection of features to include in the language. The syntax could be based on one of a couple different language syntax styles, including c/c++/c#/d/java, python, ruby, lua, among others; or it may define a new syntax style (which should be clean, and help promote good code). The language should be compiled to machine code.

    The problem with developing a new language to replace c/c++ generally is that c and c++ are used everywhere for systems programming—most of the world’s libraries, applications, systems and OS’s are written in c and c++. Temporarily to boost adoption, there would need to be a compatibility layer/library available for the new language to enable the use of existing c/c++ libraries until new libraries could be written in the new language. In the end I anticipate that it will take the good part of a decade for a new programming language (however well designed) to replace c/c++.

  • seriously?

    “ESR claims that C++ is inferior to ‘modern interpreted languages’. I—someone who does not know a single modern interpreted language—will disprove his claim by pointing out flaws in Java, a language utterly unrelated to this discussion.”

  • Tom Lynch

    There’s two obvious levels to any argument about C++ vs its VM-based cousins C# and Java: syntax and implementation / runtime.

    Even as a seasoned C++ programmer who rather likes the language, I have to agree that its syntax and its source layout conventions could use an update. Header files are a problem mainly because they mandate coupled code across multiple files (every function and class def).

    I would prefer to remove .h files from C++ convention, and instead have the compiler auto-generate public interfaces from the external structures and functions of libraries. Write all your code for a class in one place, and generate the interface for other modules as a separate entity.

    Although other aspects of C++’s syntax are clunky (for example, now that the strengths of template metaprogramming have been uncovered for some time, the reserved word “template” seems far too long for readability in typical TMP expressions), the real problem with the language is how hard it is to parse, which is the reason there are so few good, reliable tools for C++ code. It’s HARD to write a decent pretty-printer for C++, for example. Some researchers from Monash University wrote a paper about an alternate syntactic binding for C++ that is more readily parseable; it’s quite interesting.

    As far as runtime issues go, static compilation in C++ means a lot of limitations relative to dynamic languages: limited reflection (or even RTTI), no “open classes”, no MOP. But C++ shines in areas like compile-time computation with TMP (D, on the other hand, even offers almost arbitrary computations using regular code at compile-time, which is awesome). And of course, C++ tends to be faster, although as some point out, VM designers are now exploiting runtime code profiling techniques to optimise hosted code on the fly in ways that are unavailable to C++ compiler writers.

    Once the features for C++0x become a proper standard, C++ will be somewhat revivified. They include cross-platform networking (via asio), concurrency (something similar to boost::thread), and a shorthand for lambdas / closures that will make it much more pleasant to (for example) write functors for use with STL algorithms. And a huge amount of other stuff, including the invaluable std::tr1::shared_ptr that everyone’s already using as a more than adequate substitute for a GC when dealing with heap-allocated objects.

    The last thing I pray for, every day, is for C++ to get a standardised ABI for libraries, per-platform. If that could happen, it would be great.

    As for D, although it’s a cool effort (and a pretty incredible project for basically one guy, Walter Bright, to have taken on), there are aspects of its syntax that I really don’t like. Exclamation points for its template equivalents, for example. And it doesn’t have much industry traction.

    In summary, at this moment C++ is a significantly better and more productive language to be writing code for than it ever has been before; the quantity of legacy code written in C++ means it isn’t going away; there is still no obvious successor to C++ other than “better-written C++”; and it is a qualitatively different beast from Java / C++ / Ruby / Common Lisp etc. and ultimately that means schoolboy comparisons break down unless they’re focussed on specific details.

  • Dummy00001

    “Qt can do the same in considerably fewer lines […]”

    Please run first all preprocessors on the Qt code. Check just how much C++ deficiencies Qt library (and build chain) has to hackaround to get the few lines you have quoted to work.

    To me Qt library is significant precisely because it shows that C++ is not fit for modern age, where weak typing (a.k.a. late binding) and integral event handling are must.

    P.S. Of all direct C descendants, I like most Objective-C. Apple did it right by making object oriented constructs distinct from C code. As much as ObjC is often lacking, its excellent libraries are filling most (all?) gaps. Most importantly, one does not need to reinvent a thousandth time event handling.

  • Indigo Jo

    Dummy00001, that’s not the point. The point was, it takes a programmer the same number of lines in C++ with Qt as in Perl. It doesn’t matter how many lines of code are called by the Qt code, because the Perl code calls a whole load of other lines of code as well.

  • Paulo Cesar

    @jon “You use a sucky IDE so therefore the language in which its written sucks? “

    You should read my comment better too, because I didn’t said that Java or .Net sucks, I just said it’s not fast, at least not as fast as C++

    Netbeans was just an example, I already tested Eclipse, IdeaJ, little programs like Mercury, and others, and they are all SLOW, slow on Linux and even slower on Macs, oh, and ugly too, but that’s not the case.

    Are you saying that all these software suck? And all that developers at Sun or at IBM who wrote this software just suck? I really don’t think so… For me it was just an unfortunate choice of software.

    About your customers, I think it really depends on what type of software you make. Little client software that doesn’t do much processing can be made even in Ruby, a remarkable slow language, and nobody will notice it, because it wont make that difference.

    But, big programs like Netbeans or Eclipse should never* be written on interpreted or semi-interpreted languages, it’s like a disrespect with users with simpler hardware.

    *ok, never is a bit strong, I think in a near future we will all program only on interpreted languages, but today they are just too slow

  • Anonymous

    I got so annoyed reading this that I had to tie my right hand behind the back to stop myself from pointing out all the nonsense at the end of every single paragraph.

    And even then, my left hand thinks you should learn a few more languages instead of whining about how much people with a broader horizon thinks the first language you learned sucks.

  • Chekke

    C++ is nasty, After years using it I don’t get yet some of it features and I think are bugs as generic programming and OOP in C++ is a mess and complex, it seems is bolted on.

    The new System programming language is Haskell. For example PUGS perl 6 implementation it is in Haskell. Haskell is pretty fast in all the benchmarks compared with C++ performance. It is a Pure language not an Hybrid, It’s a Functional language opening for many ways of programming and for multicore development, It is easy to learn, The syntax easy as Python and different than curly braces or C based languages. I dont like the curly braces syntax anymore is boring and not cool. Anyway check Haskell you will see is an awesome language that we could use for system programming, multithreading, desktop, etc, etc.

    I drooped C and C++ long time ago. I still learning Haskell and I will use it for system programming, For enterprise/databases systems I use Java and for web development Python.

    Another choice could be Lisp or D, I like those too.

  • Chekke

    @Paulo Cesar, you are trolling around!. Im running right now IntelliJ IDEA 7.4 and Eclipse 3.3 on Leopard and runs very fast and smooth, Maybe you have a crappy system so you are getting that problems.

    The slow argument of C# and Java is getting very old really. If you understand about virtual machine design you will understand the benefits of JIT’s and virtual machines. Native or compiled languages still have benefits as system programming but for the rest development as applications, desktop or web a VM with C# or Java or even Python is enough.

    The people that keep saying Java/C# is slow doesnt make sense anymore, they are just trolling or does not understand the benefits of virtual machine design and they think native/compiled programing resolves everything. We dont live in that world anymore, sorry bro, you need to realize and move on, Technology have to move on as all the world moves.

  • Matej

    Programming languages are tools.

    There are proper tools for each of the jobs.

    A tool in the hands of the master can make magical creations. For example hammer, chisel and Michelangelo?

    Giving hammer to a one year child can result in broken glass all over the house, but it is not the tool to blame.

  • Dave

    Raymond didn’t write the Jargon file.

  • olivier

    C++ is mainly designed for programmers. C# and Java are mainly designed for the business world. Commercial software that you can buy with a computer will mainly stay written in C++, software written by business for business will mainly stay written in C#/Java. Actually, Microsoft tried to put some C# in their last OS (Vista), they make something heavier and slower than XP, which makes many people hate Vista. Any commercial software which uses C# or Java will just look like not really integrated to the system (different widgets) and slower. I don’t get the many benchmarks you can find on the net arguing that Java and C# have nearly the same execution speed that C++. Mostly, any software on my personal comp that is written in C# or Java, I feel it and that’s a bad feeling. Internal developments will always need to be fast and bug-free as much as possible, that’s where C# and Java excel. To me, C++ allows a lot of dirty things, that doesn’t mean you cannot do safe things with C++. But if you are a bad programmer, you are likely going to do less bugs with Java / C# (Sorry for my bad English)

  • CWW

    What you say may well be true. But that attitude is exactly why the world has gone from well crafted efficient software to to absolutely incredible bloat. I can process words with CP/M and Wordstar with a few k of code. Or I can use a “modern”, “efficient”, “innovative” program that is crammed on two CDs. And the bloat does not provide anything like a commensurate increase in functionality. No, the user doesn’t care if you deliver pizza in an 18 wheeler, but someone should. For full disclosure, I write in C unless coirced.

    Regards

    cww

  • none

    What’s all the fuss with programming languages?! All are the same. C, C++, C#, LISP or Assembler, all allow you to do the exactly same things. It’s the programmer what matters!!!

    Having to write 10 lines instead of 5 is not a big difference. A programmer that knows his language is a difference, but the real difference is a programmer that understands what he is trying to program. So learn to use your brain.

  • http://federkiel.wordpress.com Raphael

    You might want to take a look at the Vala programming language.

    Vala is, essentially, a boiler plate code generator for the GLib object framework. Vala is pre-compiled in C and after that can be compiled using any decent C compiler. Vala also makes heavy use of the GObject introspection - it’s thus extremely simple to make bindings for other languages.

    For a quick introduction, take a loot at http://www.vala-project.org/ or http://federkiel.wordpress.com/2008/07/04/application-development-with-vala-fists-steps-getting-the-vala-feeling/

  • Flirek

    Why does Main have to be void anyway, preventing you returning an exit value (to tell whichever program called yours how it finished, i.e. whether the job got done or not)?

    becouse your program did NOT call JAVA CLASS, it called VIRTUAL MACHINE to execute class :) so virtual machine should return status value (for example 0 if class interpretation is o.k.) look at java System.exit() for exit status option

    Why does Main have to be in a class at all?

    “Main” is reserved name of method which tell VM where to start execution point. alternative would be to start java class something like: java MyClass.someMethod(arg1, arg2,…)

  • Paulo Cesar

    @Chekke

    Good attitude, the program is slow, blame the user’s computer!! It’s so easy!

    I remember years ago when I had a Pentium II MMX! I used to talk on icq, listen to mp3 and edit photos on Photoshop without problems, now to do the same things I need a CoreDuo..

    And that’s not because of the languages, Java, C#, C++, or whatever, it’s because of the mentality of programmers who doesn’t think that fast is good, hate simplicity and loves bloat..

    Now, that Haskell thing, I head about, but never saw anything made in it, I’ll take a look, if it’s fast, easy, and good designed I’m in ;)

  • Paulo Cesar

    @Chekke

    Ok, I retire what I said.. No Haskell for me

    I saw an example and it’s nearly identical to Prolog, and it was bad enough having to learn Prolog on my AI classes.. No, you can call me dumb, but no functional programming for me..

    I’m not saying it’s a bad language, it’s just another paradigm completely different, I would have to forget years of learning and spend a good time learning how to use this new paradigm efficiently..

  • Paulo Cesar

    Strongly agree with you olivier.

    On my city there will be at least 100 students graduating in something that involve programming, and I would be surprised if more than 20 can write good code in C++

    That’s why the business prefers Java (at least here), because it’s a much better environment for these other 80 graduates..

    I’m NOT saying that Java is for bad programmers, I’m saying that’s a much more restrictive language, and bad programmers are likely to make less mistakes on Java than on C++, Ruby* or Python

    *I feel like i have to explain everything I say to be not misunderstood..

    I already experienced this.. I have to maintain a Ruby code from a asle that definitely is NOT a good programmer, and it’s some of the worse things I had to do on my career.. Man, I already had to simply delete 1000+ lines of code from a class and write it again in 100 lines because it was too unmaintainable!

  • jkl

    I have to wonder at some of these comments.

    C# in Linux, anyone? Java on Windows? These are proprietary languages. Is it surprising they can use C (and C++) libraries but can’t themselves be used by others?

    Every Java application I’ve used on Windows has been a clumsy pig. (I never noticed any lipstick.)

    I’ve tried to learn the objects-in-C model in the GTK. It’s very hard, especially knowing that most of the boring, error-prone work is better left to a compiler….

    But show me. Show me the email client, the file manager, the window manager, the PDF viewer, the photo manipulator, the graphing tool, the typesetting tool, the word processor written in these oh-so-much-better languages.

    The proof of C++ superiority is in the results.

  • Rick C

    “C++ has to have some of the most unreadable compile-time error messages: something like if you put salt into a cake in place of sugar and the oven tells you “Error: Carbon deficiency. Carmelization may not be completely defined.”

    That is entirely the fault of the compiler, not the language. If you want to see overly verbose/obscure compiler errors, see any VMS compiler, particularly the Ada one.

  • Unknown

    C# is not even a programing language, if it were we would be considerating that Microsoft actually did something good, and that’s a big mistake.

  • http://thebeezspeaks.blogspot.com Hans Bezemer

    The trouble with C++ is that it is object oriented. Edsger Dijkstra already said it: “Object orientation is a particularly bad idea that could only have been invented in California”.

    I have always distrusted languages where I cannot predict what kind of assembler it spits out. I still use -S every now and then just to see what happens under the hood. It saves a lot of invoking ugly things like debuggers or class browsers.

    That doesn’t mean I don’t think that OO can be a useful thing every now and then, but a good programmer doesn’t need C++ to make an object oriented program. X was programmed that way. Because in essence a class is nothing more than a structure with pointers to functions. And a structure is nothing more than a block of memory with offsets where the fields ought to be.

    A friend of mine - a VERY good programmer - used C only as an assembler generator for those parts of his program he didn’t really care for. He took the listing C provided and optimized it by hand. You’d never find a guy like that with a C++ compiler..

    Any C++ program is inferior to its C equivalent, just as a C program is inferior to its assembler equivalent. It takes more memory and runs slower. Now talk to me about “bare metal programming”..

    Webfrontends should be programmed in PHP. Unless you want some fancy graphic interface, plain every day data entry is better served with PHP or equivalent. No need to fire up your C++ compiler.

    The only real use for a C++ is when compiling fancy frontends like Qt. Qt - and its derivate KDE - is elegant with its slot mechanism. That’s why it needs its own preprocessor.

    Still, many fancy functions are better served with an intelligent C envelope than an OO mechanism. Compare the plain C stdio.h to the streaming I/O interface of C++. It’s mind boggling to even get an open file to send a bunch of bytes to!

    For the moment I refrain from using fancy things like C++ or its decendents. I prefer using C and Forth, since it makes it a lot easier to predict what code is generated and how memory is actually used.

  • Paulo Cesar

    “good programmer doesn’t need C++ to make an object oriented program. X was programmed that way”

    Sorry, but that really doesn’t prove anything.. X is well known for it’s awful code base, and for being slow and bloated

  • M Risbrook

    OOP certainly has its critics and I am one of them. Some of these critics say that OOP is more of a craze of industry (bosses) rather than a serious improvement on good old fashioned procedural programming. Programmers skilled in a variety of languages often know it is quicker and/or easier to accomplish certain tasks using plain C or a scripting language than it is to use C++, C#, or Java, but corporate policy doesn’t allow them to.

    A question I have is if C++ had never been invented then would OOP have become mainstream or would it have remained a curiosity of confined to academia like Smalltalk was back in the 70s?

    An alternative to OOP is to build software from many small compiled programs written in a procedural language, and connected together using code written in a scripting language. A Unix shell script which invokes several compiled executable files is a very simple example of this. John Ousterhout is a proponent of this method of software engineering.

  • Andrey

    Good apps written in much better languages, just one per category, are: Java - Eclipse, Pascal - Total Commander, C# - Paint.NET, Ruby - Rails, even PHP - 50+% of the Web.

    C# may be faster than C++ (better library + better jitted machine code). As of .NET 3.0, C# can do things C++ cannot even dare to think about.

    Pascal is often faster than C++. Just a simpler language so it is easier to make a better compiler.

    C++ is still with us just because any alternative is plagued in some way:

    C# - it is Microsoft and we know MS fails everything. Think Vista.

    Java - suddenly slow, bloated, unexpressive, VM STILL CRASHES!!!(at least on Windows).

    Ruby - slow even with Rubinius. Idiots do damage tenfold. Otherwise perfect.

    Pascal - insane price, COM plagued interfaces, confusing Unicode (Compare: Python 3.0 went Unicode right).

    Besides, C#/Java managed memory has a fundamental flaw: an object is freed when unused. OK so far. How can I free an object and tell its users that it does not exist any more? Back to C/C++/Qt….

  • Sean

    @DavidG

    You obviously lack knowledge of .NET fundamentals. You shouldn’t be commenting on what you don’t understand. Similar to Sun’s HotSpot compiler, .NET’s (not just C#) JIT compiler will translate CIL (the acronym MSIL was dropped a while back) into native machine code, which is then cached for subsequent use. I.e., contrary to your misinformed assertion, it’s not interpreted.

  • http://sourceware.org/gdb/wiki/STLSupport daniel

    it would be a good idea if you actually used c++ for at least few years, before publishing newpapers style personal impressions, you aggregated from others…

    just my $.02 d

  • http://www.cyberdesignz.com/ alex

    C++ is still with us just because any alternative is plagued in some way: C# - it is Microsoft and we know MS fails everything. Think Vista. Java - suddenly slow, bloated, unexpressive, VM STILL CRASHES!!!(at least on Windows). you can get more information about programming from this. http://www.cyberdesignz.com/

  • Hostingservice11

    I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!

  • http://www.web-hosting-service.in HostingServices

    This article is from a series of articles useful and enjoyable for each reader.

  • zashi

    OMG.. “even though said theory is demonstrably inadequate for systems hacking”.. I never thought java kids would start to be so agresive.. they need to relax and stop watching horror movies (and/or fapping).. How could anyone consider C++ not good for hacking while Java is considered better at it?! Eric Raymond is sooo trolling us.