Friday, December 4, 2009

For The Love Of C++

Alot of programmers that use more modern programming langauges (C#, VB.Net, Java, Python, Delphi etc) dish C++ by saying what bad language it is, how its the worse thing ever created etc.. But they don't know it (have you ever code any C++? have you ever even see any C++ code?) Don't dish something that you don't know...

Languages like C#/Java is very abstract, they hide things from a programmer like memory management that get managed by a garbage collector etc Where in C++ memory management get done by yourself via pointers (yes pointers are very difficult!) C++ have pitfalls, very bad once aswell yes but they can be privented by putting rules in place, use 3rd party libraries like Boost that support smart pointers for memory management (for this artical am not going to explain what smart pointers are) have code reviews etc. A programmer can write crap in any language, in C++ its just more easy for this you need serious programmers that take there job seriously that are willing to learn the C++ pitfalls and how to deal with them, are willing to read books like Effective C++.

C++ is powerful it teach you how to come close to understanding how the machine works, you learn new things / new ways of doing things all the time... its fun! Think abit beyond... The OS that you use (MS Window/Linux), your mouse driver, your Webcam, your iPod, your iPhone, your IM program like Skype etc are all written in C++ or some dialect of it (like Objective C)... the C# / VB.Net etc geeks can also stop moaning since do you guys know? the compiler for your language is written in C / C++.

So why does C++ have so many pitfalls?

To start, every language has some form of pitfalls... am studying for my Java Programmer Sun Certification and let me tell you, even Java got alot of pitfalls. C# aswell! So don't think C++ is the only language that you can write crap in, you can write crap in any language and any language can make you scream from frustration when you struggle with some weird issue that is actually a language pitfall.

C++ have alot of pitfalls, full books are written for them like Effective C++ (btw you also get Effective Java) get see the reason why we need to go back into history... (time Machine please!)

C++ was called "C for Classes" where Bjarne Stroustrup want to add object oriented programming (OOP) features to the powerful C programming language from his experience coding in Smalltalk, Simula etc. (interesting artical here) it was criptic way of adding classes but it worked and soon the name was given "C++" along with more languages features added over time... like meta programming, generics in the form of templates, run-time libaries like STL etc To keep C++ standard a standard committee formed, standards are there for a reason since it protect us my dear fellow programmers from one compiler vendor adding some language feature that isn't part of a standard meaning that when you ever wanted to move your code over to that compiler you will have issues - might not be at compile time but at run-time damaging your customer.

When adding a new langauge feature you add more complexity ontop of more complexity and you must keep backward compatiability! Why backward compatiability? Example: Python 3x isn't compatiable with Python 2x so how many developers ported there code over? Answer: Almost none, reason being that a programmer just don't have the time or resources to do a port, you can't tell the your boss/management to wait for a year for you to rewrite all the software (that can be millions lines of code) since business must go on... new products release, new customers, new features in the application etc. In the ISP world its a good example. So for C++ every new feature needs to be compatiable in different context together with other language features... its a difficult process, committee's fight about things for years... the new C++ 0x standard has been going on for over a decade now. So "0x" since you don't know when it will be release, it can be in 2020! that is why C++ has some many pitfalls and is so complex because of 30 years of history... languages like C# will go the same route or are already going the same route. The C++ standard committee just can't do what the Python guys did by "cleaning up C++" since millions of lines of code all over the world will break.

So to end this story... this the truth ladies + gentelman, don't dish something that you don't know the history about or ever even used before.


4 comments:

Forumtroll said...

I couldn't have said it better myself. Still, I'm not sure where you've heard people lash out against C++; I've heard most languages been put down, but never C++ directly, allthough I've head c++ being called pointers on viagra..

Lennie De Villiers said...

Its more C# developers that say how bad Java and C++ is, I use C# myself but I also use Java and C++ so that is why am one that keep quiet..

Forumtroll said...

Heh, might be that C# is a lot easier than Java to comprehend the basics of, but I still find C# superior to Java on several aspects. Still, it should be noted that C++ cannot be measured up to either java or C#. It would be just as stupid as converting bananas to nuclear reactor fuel..

If I were to put down a language, I'd have to give PHP my worst..

Lennie De Villiers said...

In 1995 there was only C/C++ so Java came out and for years it was most popular language of course revolution came and C# is now. But remember that every language have pitfalls, bad/good points etc in different spaces. C/C++ is still good for OS or embedded development. Java for mobile (J2ME) etc.

PHP as well, its good in the web development space... I'll rather use PHP for web development then Perl (CGI). Point that am making: in every language you can have good/bad points, something in the language that you dislike or wish was different.