Let's Retire C and C++

DN Staff

October 20, 2003

3 Min Read
Let's Retire C and C++

C and C++ are old and tiredlanguages that have outlived their usefulness. For programmers, there are more productive ways to develop software. The odds of getting engineers a reliable program to use are significantly better with C#. While C and C++ are expressive and powerful languages, letting anyone but very experienced programmers use them is like greasing the floors and letting your programmers run across it with knives. The most likely victims will be schedules and/or code reliability.

Productivity is significantly influenced by a language's ease of use and the time it takes to debug and fix problems. Any language that requires a book like "C++ Gotchas", which describes 99 common C++ programming mistakes, has serious usability issues. For instance, who really has a handle on how to decipher C type declarations like:

char *(*(*a[5])())();

Don't get me started on the myriad string data types and APIs you have to deal with: ASCII char*, multi-byte char*, wchar_t, CString, BSTR, CComBstr, _bstr_t and basic_string&>. Come on! How many different ways of dealing with a string do we need?

By far the biggest productivity killer is the vast potential for writing buggy C or C++ code. Dynamic memory management and the pointers typically used in conjunction with them get more programmers into trouble than any other feature of C or C++. If you don't remember to explicitly free memory you have memory leaks. If you access memory that has been freed, your program may crash or behave unexpectedly. Indices used to access arrays are not validated in C or C++. As a result, an "off by one" error can cause undetected memory stomps that in turn can cause your program to crash somewhere completely different than where the stomp occurred.

C# leaves C and C++ in the dust when it comes to programmer productivity. C# and the underlying Microsoft .NET platform put to good use the exponential improvement in computing power that has occurred in the 30 years since C was created. The extra compute capacity is used to provide automatic garbage collection, which eliminates memory leaks and freed memory reads altogether. Array accesses are always checked at runtime to verify the index is valid; this eliminates one source of memory stomps. Since C# doesn't require the use of pointers, another class of memory stomps are eliminated. While these services require a little extra computing power, the way I look at it is that hardware is cheap, software development time is not.

Many C/C++ programmers are concerned about standards and performance. C# has been standardized by both ECMA and ISO. C# performance is not only better than Java and Visual Basic, it also isn't too far off the performance of C/C++. Furthermore, most instrumentation automation programs are performance limited not by the development language but by instrument I/O.

It is very easy to get started using C#. You can download the Microsoft .NET Framework SDK for free at: http://msdn.microsoft.com/netframework/downloads/howtoget.aspx.

The SDK comes with the C# command line compiler as well as many sample programs. I predict that you will be pleasantly surprised at how far your C or C++ skill set can take you with C# and how much more productive you will be.

Sign up for the Design News Daily newsletter.

You May Also Like