Sunday 22 May 2011

The broken language

Disclaimer: this is a rant. A huge one. A rage really. Consider yourself warned. I make no attempt to go easy on this piece of crap in this entry.

As described, I chose C++ as the language for my projects. It just seemed the right thing to do with its omnipresence in the programming world.

But I must admit that after 20.000 lines of code written in the darn thing (recently alone), I'm having increasing doubts about it. It just takes too much time to get anything done in it. And befory any of the C++ zealots come flaming me, please google your flames before posting, you will get enough counter-arguments.

This language is simply broken!!! And this was an understatement of the year! I have no idea what its proprietors are thinking when they go to the drawing board. But I'm very sure of one thing - it definitely isn't clarity and ease of programming. I've just been reading the proposed changes for C++0x standard (for the n-th time) and came back just as dissapointed as I am using this crap of a language.

I've been thinking long about how to list some of the things that bother me and decided on a plain old list in the end. There just isn't a prettier form for doing this, I think:
  1. The entire language is based on one of the oldest non assembler languages. In this case old implies unevolved, archaic and most definitely not modern. Note the triple use of what is essentially the same word.
  2. Even the basic types are completely messed up in this language. A programmer never knows exactly what he's going to get when he declares a simple integer (int). "Platform dependent" they say... Well, platform dependent my ass. I have yet to see an algorithm that scales from 8-bit to 64-bit CPU with the same int declaration. How idiotic. Not to mention that one of the most important (close to metal) integer types (byte or 8-bit integer) is named char. And to top it all off, it's even signed!!! How lame can this get?
  3. But these two are just the just the tip of the iceberg. The real fun begins when you pop the hood:
  4. There are two ways of using pointers - pointers and references. Well, references are a pathetic attempt at garbage collection. I guess. At least I have no idea what else they would be since the compiler seems to know better than me when to destroy an instance and when not. In the end you're just as forced to use pointers in C++ as you were in C since references are only useful for basic types. Either that or you have copy constructors all over the place. How can such a performance crap piece even be in the language?
  5. Here we have a language with templates, multiple inheritance and whatnot, but this same language has next to no run-time type information support
  6. We have a language with operator overloading, but for some reason class properties are evil and not to be supported even if hell freezes over.
  7. Compiler compiles your code in its entirety every time. Because the files your code is broken into are just good programmimg practice and there for your easier coding. To the compiler it's just a heap of code in one block.
  8. There is no difference between a .h and a .c / .cpp file. Whatsoever! None! Not even if you wish for it! This one actually took me years to finally understand. Especially because Pascal was my primary language and there the distinction between interface and implementation was a matter of language syntax.
  9. Stemming from the previous point is another language beauty: you can write fully functional implementation in the declaration section. Sure, it's meant only for inlining only the most inlinable methods, but since it doesn't matter to the compiler, why should you - the programmer - care?
  10. Despite its idiotic nature and completely useless existence, the preprocessor is still capable of processing one line only and is not recursive.
  11. In the end one of the things that disappointed me the most was my fellow programmers' mentality. Whenever I would ask how to get rid of some 4 bytes of memory usage in a class instance, all I got was: are you working on a 20year old 8-bit chip? No wonder a graphics driver control panel applet nowadays gobbles a couple hundred MB od RAM... When minimized, of course...
I could go on like this for thousands of items, but it would serve no purpose, so I'll just stop. You can find a million sites on the net detailing pretty much every flaw of this language many of which I totally agree with so I'll just return to what I think is the cause of this:

I believe C++ is broken as a language and will remain broken because of two things only:
  1. It is based on an archaic language and carries on its legacy despite the fact that they are very different languages and that the compilers actually have two separate code paths to be able to compile either
  2. The language is expanded and extended with the above in mind by people who know only C / C++ and are told of other languages' progress. The latest already late standard extension just proves this: it solves none of the existing shortcomings and introduces quite a few new ones. Sure it adds some nice things into the language, but the syntax for them is even more messed up than it already was.
All things said and done, C++ standards body should look at a good, popular modern language and try to adapt C++ to that instead of just complicating it further. I already mentioned one such quite successful project in my previous blog entry and I'm sure there are other, even better attempts.

Ahhhhhh, what the heck:
I vote for end of further mutilation of C++ language. I propose to accept for C++ 0X standard the specification of D 2.0. Then go from there and make it better.