November 14th, 2008
From C to C++, Java and C# - 0
A little trip through memory lane and how programming has changed. Starting with the birth of C through to C#. The software world has become that little more complicated since the time share ASCII teletype systems. Chinese input, Arabic display, USB devices and gigabytes of memory are standard these days.
Operating systems originally were coded in pure machine code to enable computers to run at maximum efficiency. With some exceptions that stayed so until C entered the world roughly around 1972. Developed by Dennis Ritchie at Bell Telephone it allowed the UNIX operating system to be rewritten in a “higher” level language instead of assembly language.
A good C compiler can generate code that is often as fast as hand coded assembly language, but offers the benefit that its much easier to read. C is still widely used today to write both low level system software and actual applications. C also came with a standard IO library; making it easier to port C programs from one platform to another.
Code Re-Use
Code re-use in C however can be quite hard, and in larger projects code becomes increasingly difficult to maintain.
At the end of 1970’s Bjarne Stroustrup while working at AT&T developed a language that would support large software development. He used ideas from one of the first Object Oriented Languages (Simula) dating back to the 1960’s and combined them with C into a new language C with Classes, later renamed C++. One of the main features of C++ is the Class, and the ability to derive a class allowing for more extensive code re-use.
C++ was designed to be compatible with C to allow for easy transistion. As the language grew it added its own standard library providing basic sorting algorithms and storage containers (Arrays, Lists) reducing the need to rewrite and debug these frequently used code elements. Because of its C heritage it is fast and efficient, and much system software, device drivers and applications are written in it.
Memory Management
But because of its C heritage memory management is still left to the programmer. This allows for great speed but also creates opportunities for hard to find bugs. Memory that is not properly handled can lead to both crashes and allows software to leak memory over time.
In 1995 Sun Microsystems released Java. Java is a C++ like language that doesn’t actually run directly on the CPU. It is compiled to an intermediate byte code stage that is interpreted by the Java Virtual Machine 9JVM). That allowed for another older concept to return, the garbage collector. Memory that isn’t actually being used by any part of the program is automatically released, freeing the programmer from having to worry too much about each allocated block. Access to memory is also restricted to basic types, the programmer no longer just allocates a block of memory and releases it when its no longer necessary. This allows also the JVM to catch any out of bound access, instantly killing the program rather than letting it continue with a corrupted memory map.
One of the major criticisms of Java initially was the speed (slowness) with which each program ran. Great progress was made however here as compilers became smarter, and Just-In-Time compilers converted often used byte-code blocks into actual machine code.
Exceptions
When writing a proper C program, it is important to check for the return value of each function to ensure that some error didn’t occur. Of course this leads to code that is hard to read, and often the checks were skipped completly to be able to quickly hammer out a piece of code. This leads to programs that hobble on despite being told earlier that a critical resource was not available.
Java and many other interpreted languages added exceptions. Sub routines no longer have to return an error code, if something goes awry they throw an exception. If the program is well written, it will catch it. If not, the virtual machine kills the program.
The world moved on
Much of yesterdays software lived in a simpler world. It often had the run of the machine, and if it had to report something it wrote a line to the terminal. During the 1990’s graphical user interfaces took off; and computers were networked. A basic computer nowadays has thousands of code libraries installed. Software for such a platform needs to handle everything from memory management, to graphics, networking, sound and a pletora of output and input devices in any of the worlds hundreds of languages.
Microsoft ran into this problem as its platform was becoming increasingly complicated. Its Visual Basic language lacked the expressiveness of C++, but allowed for quick development. At the same time its Visual C++ libraries were becoming overly complex ; and writing code was becoming increasingly hard, and debugging even harder.
Following the Microsoft-Sun Microsystems Java lawsuit (Microsoft licensed Java, but broke the agreement by making Microsofts implementation specific to Windows) Microsoft decided to start developing its own language, originally called Cool, later renamed C# (C-Sharp). C# principal designer at Microsoft is Anders Hejlsberg, who previously designed Visual J++ (Microsoft’s Java), Borland Delphi and Borland Turbo Pascal. He has stated that he was inspired by the flaws in C++, Java, Delphi and Smalltalk which led to the design of C#.
Microsoft also started work on its .NET framework, which integrated many of its seperate libraries into a single framework.
Java has collected a huge class library, allowing for platform independent coding and extensive re-use. C# does not have its own libraries, but it shares .NET with the other Microsoft languages. C# is not simply a clone of Java, although it is very similar in features (it used an intermediate stage, offers a garbage collector) — but as it was developed after Java reached maturity it has taken some things further.
From Assembly, C all the way through C++ to C#, at each step the language has become higher level, taking away responsibilities from the programmer. The price paid is in execution speed. In return development is speeded up, error checking is much more thorough and it has become possible to build complicated systems with less code because of code reuse.










Except where otherwise noted, content on this site is