Tuesday, August 4, 2009

Why I dislike C++ and C#

I admit it. I am a "Object Oriented Programming" hater.

At first there was just a kind of disconcerting feeling about it, such as a sudden shifting from the simplistic terminology of C to the "elitist" terminology of C++. (These are not the only examples of opposite languages, but they are good for examples.) I always tried to program computers in the most simple, direct manner so that I could understand what I did later when it needed to be changed. Although C cannot make things assuredly simple, C++ makes the simplest things hard.

For instance, the "Hello World" program can be made almost identical for C and C++, since C++ will allow certain forms of C syntax and function to work right out of the box. This is a good thing, otherwise most C++ programs would never work. Yet it is possible to use the "class object method" model for programming "Hello World" and suddenly a 2 or 3 line C program becomes an entire screen full of symbols and gobbledygook with the string "Hello World" stuck in there several places.

Now, I am not saying that C++ doesn't have good aspects about it. Certainly I like the fact that objects clean up after themselves in a more orderly fashion than C functions, although part of that ability is on the part of the programmer to make sure it is done. I had the same habits when I programmed in C -- to make sure all allocations were freed, all files closed, all errors returned, etc. It was just a habit of programming rather than a structural part of the language.

I originally wrote code in BAL (IBM Basic Assembly Language), Burroughs Assembly Language and PDP-11/70 Assembly Language. There were some other awful things in there too, like Cobol, various Basics and Fortrans. Lisp, Forth and some self-written languages also made my list. But when you program in assembly language, you learn to think in certain patterns that keep you from shooting yourself in the feet. Other languages try to force your feet to keep out of the way of bullets, or disallow bullets entirely.

Macros were an important part of assembly languages. These allowed repetitious aspects of programming to be done once and then reused wherever necessary in new programs. In some ways the C language is merely an enormous macro language encapsulating all the goop of assembly language. Yet the very thing I liked best about assembly was the pinpoint accuracy it gave you. Whatever the machine was capable of, you could make it do it. In today's world, most of a machine's capabilities are wasted, and some small subset is used in 99% of programs.

Although I do not wish to program in assembly language any more, (carpal tunnel hell,) I do miss the pinpoint accuracy. Using C makes me feel like I'm using very dull pencils. Using C++ makes me feel like I'm using Legos with Swiss Army Knife attachments made from balsa wood. With C++ I hardly every achieve exactly what I set out to do with a particular program. It always winds up being what I am allowed to do by some hidden Fascist inside the machine.

C# is another level of icky gooey stuff poured over C++. In some ways it is like a scripting language, or a little bit like Java. I think the benefit of C# is sort of lost -- it is just another arbitrary thing created by Microsoft that could just as well been done with Java (but without Microsoft's purely profit driven reasoning...)

I stay away from C# for that reason. It isn't that I want to program with difficult, syntactically punctuated languages at all. I just dislike arbitrary reinventions of wheels. It was a great waste of programmer time and it is a waste of my own time to learn and use it for anything. Especially since there is a performance and capability loss with the use of C# (and its .NET world.) It is like using C++ with thick mittens on, and under the watchful eye of a vicious Nun.

No comments: