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.

The pain of choosing the right tool to work with

I've been programming in many languages. Some of them were easy to learn, some prove difficult even after months of intensive use. In the end the most important part of learning a language are the libraries provided with it. Until you know the name of that particular function, you spend tons of time looking it up in documentation.
A while ago I had to make a choice about what I'd use to program my little projects in. I wanted to use Python which I consider programmer's heaven - language wise. They don't say "batteries included" for nothing when it comes to Python. Just about anything you need is already provided for your programming pleasure. And it just feels natural to use it. If you're not sure, just type the code and to your surprise: it will usually just work. This language simply rocks!
Alas GIL, some performance issues and inability to protect my code turned me away from this beauty. So I started looking for other options. Compiled languages of old that I learned programming with and used them all my life. Surely they would provide me with more or less the same level of programming enjoyment so that I can finish my projects quickly and with minimal fuss?
I looked at Pascal, which was my primary language for years. Even in its latest incarnations I saw that I'd still have to write entire classes just to get me a simple sorted list of records. Not to mention that Borland is no more and the language itself turned to a niche player. FreePascal sure is a fine compiler and tool, but it still didn't evolve the language enough to even attempt competing with Python.
Then I looked at C++ which was never really an important language for me - Pascal was just so much easier. But it has one major advantage: just about everybody uses it. The compilers are the most advanced for this language and they exist for just about any platform you could ever think of. And it has templates and STL and libraries for just about any purpose all over the net. And pretty much everything comes with a C++ libraries and samples. However, C++ also wasn't even close to perfect. Despite all its advantages, it's still an archaic language which doesn't really evolve much and in the recent years it certainly didn't evolve into something modern.

So I looked around and I found what seemed lie a perfect candidate: D. It's a C++ derivate which took ideas from other modern languages and merged them into a language that seems the perfect mixture between Python and plain old C. I'd even go as far as to say that D is pretty much a strictly - typed Python, as much of it as can be implemented into strict types.
The problem with this language I didn't find in the language itself, but in its proprietor. For some reason Digital mars, the creators of this language, don't want to open the compiler source. Instead of them contributing to an open project, they continue to develop their own closed-source (partly open is still closed) compiler. Also the entire documentation about the language is hosted directly on the company's web site and not on a site devoted to the language itself. There are open source attempts, but they are obviously undermanned and thus too little. The entire thing smells too much of a - as in one single - company. There are simply too many what ifs.

In the end, C++ prevailed, but mostly due to its popularity. But with it came much pain. Following in the next blog entry.