Written by Mike James  

Tuesday, 05 April 2011 00:00

Java / C / C++ / C#

 

 

This is Part 1 of the I Programmer State of the Languages 2011 Report and it coincides with this month's poll question to discover our readers' choice of language, based on the latest TIOBE ranking.

 

As you will probably already know (and if not see Language of the Year) the TIOBE index is a longstanding attempt to measure  language use and "importance". It is certainly valuable to developers to know which languages are currently important and in this part of the I Programmer survey we look at characteristics of the languages ranked 1 to 4.

 

The top four languages in the TIOBE survey at the start of 2011 are remarkably similar. This isn't surprising as C++ is an extension to C, Java is modelled on C++ and C# is modelled on C++ and Java. There is nothing wrong with this - as Picasso is so often quoted as saying "all art is theft" and all languages are either improvements or reactions to other existing languages.

 

What is surprising is that the top four languages are so narrow in their approach to syntax - all four use C's for loop construct for example - and paradigm - they are all procedural/imperative and three are object-oriented. It seems that we have voted for a single approach to the problem of creating programs and if you want real innovation you have to look further down the list.

 

So how do the top four compare and what are their essential characteristics?

 

 

Java

 

Java is now a middle aged language and what was once cutting edge and new is now just part of the establishment and wondering where to go next. Java also has something of a political crisis on its hands in the from of its new owner Oracle. Java has been free to use since it was first created by a team at Sun Microsystems in 1995 but its status as an open source language has long been confused. Now Oracle has control of the language and much of its infrastructure and this is not reassuring to its user base.

 

Java is a class-based, object-oriented language modeled on C/C++ but designed to be easier to use and safer. Another key feature is that it runs using a Virtual Machine (VM) rather than being compiled to a native machine code. This means that as long there is a Java VM for the platform all of the Java tools and code with just work. Of course in practice this isn't quite the case because machine specific considerations always find a way into the mix. Notice that Java may use a VM but it is a compiled language and it is strongly typed.

 

Java started out as just a language but since then it has acquired many frameworks and many variations that allow it to be used in different ways - Applets allow it to be embedded in web pages, JSP provide a way of creating web apps, It is even the main language used in many Smartphone implementations - Android, WebOS and Symbian.

 

It can even be argued that Java now has so many frameworks around it that it is more than a language and has to be judged as an ecosystem. This is true but it is also one of the criticisms leveled against it - so much to learn so many conventions and legacy baggage! There is point that Java has been slow to develop. It added type safe generics in 2004 but this was the last big language feature to be introduced. The next version of Java, Java 7 will have some new language features but the long waited extras are delayed until Java 8.

 

Java is a good programming language but it is suffering from being middle aged. It no longer has anything new or innovative to offer but in the matter of languages stability is often more important. Overtime it has collected many additional technologies and lots of well designed support tools. Programmers may grow bored with it and play with new languages but Java has proved that it can do the job. Ironically with Oracle in charge of its direction its technical future looks good even if its credentials as an open source language are starting to look tarnished.

 

Key Facts

    * Imperative procedural

    * Object-Oriented

    * Class-based

    * Static strongly typed

    * Automatic memory management

    * Compiled to byte code

 

 

 

C

 

If Java is middle aged then C, developed around 1969,  should be a pensioner. However this is not the case and C still occupies an important position in the programming universe. It is also arguably the most influential of languages because most of the modern languages derive from it or are modeled on it.

 

C is different from the other languages described here because it has different objectives. C is best characterized as a machine independent assembler. Rather than abstracting away from the underlying machine architecture it says as close as possible without building in anything that is too machine specific.

 

Created in a time before objects were the standard approach to programming C is a well structured procedural language that uses functions to organise the code. It made popular the almost universal form of the for statement for(initializer,condition,incrementer) as opposed to the Fortran/Basic form For var= start To finish. It also introduced the idea of dividing code into header, i.e. definition, and main files.

 

As a modern language its key difference is that it is weakly typed - although not being object oriented the range of types is limited. Although compilers are designed to spot type conversion errors the programmer can override these warnings and basically treat the data as raw bits. This approach is further encouraged by the availability of a pointer type which is an explicit pointer to a memory location. That is in C pointers contain machine addresses.

 

These and other similar features make C ideal for writing code that is reasonably high level and yet can still work with the hardware. This ability and the fact that it creates compact and efficient programs make it a good choice for systems and embedded programming.

 

However C is generally considered not to be a good choice for large projects that don't interact with the hardware directly. The reasons are that lacks a good way e.g. objects, to organise code at a higher level and it doesn't protect the programmer from making errors that can bring the entire system down.

 

Despite its shortcomings, and it is worth noting that many features of later languages were added as a reaction to problems in C, it is difficult not to be impressed by the simplicity and elegance of the language.

 

 

 

Key Facts

    * Imperative procedural

    * Not Object-Oriented

    * Function-based

    * Weakly typed

    * Manual memory management

    * Compiled to machine code

 

 

 

C++

 

If C is simple and elegant, C++ is complex and elegant. Designed between 1979 and 1983, C++ aimed to add objects to C in a way that left the original language embedded within.

 

If you want to you can write C++ code that is, apart from some minor differences, pure C. However if you want to you can also use C++ in a wide variety of styles. The language is so flexible that it is possible to write a C++ program that is very difficult for another C++ programmer to understand. The language was explicitly designed to support procedural programming, object oriented programming, data abstraction and generic programing.

 

There is also the issue that because it includes the C language it has the potential to allow the expression of all of the same faults. In short in the wrong hands it can be misused but in the hands of a programmer who understands the dangers it can be a very productive environment.

 

As C++ is built on C its basic syntax is similar - the same conditionals, loops and functions. It introduces features such as Class, inheritance, virtual functions, operator overloading and later templates (generics) and exception handling.The most important aspect of C++ syntax is that it is so flexible that it allows the programmer to redefine operators, introduce macros and combine facilities in ways that make it look like a different language.

 

Inheritance in C++ can be multiple i.e. a single class can inherit from multiple classes and this is probably the single most criticised feature of C++ and most of the languages (notably Java and C#) that have based themselves on C++ have enforced single inheritance. C++ also doesn't have automatic memory management even though it is object oriented and would be greatly simplified by one.

 

When C++ was first implemented it was first converted to C using a preprocessor and then compiled. This had the advantage of making it almost immediately available on any machine that had a C compiler. Today's C++ compilers produce machine code without the need for a preprocessor. Currently it is one of the few fully object oriented languages that compiles down to machine code and so it has an advantage in any application that needs speed and efficiency. For this reason it is often used in system software, graphics and even embedded programming.

 

Key Facts

    * Imperative procedural

    * Object-Oriented

    * Class-based

    * Static typing

    * Manual memory management

    * Compiled to machine code

 

 

 

C#

 

C# is the newest of the top four languages and was introduced in 2002. Initially it was claimed that it was just a clone of Java but it could equally well have been described as a development of C++ just like Java. There have been 4 versions of C# to date - the latest being C# 4 released in 2010. What is remarkable about C# is the speed at which it has developed. It may have started out life as being similar to Java but while Java has developed slowly C# has evolved at a remarkable rate - perhaps too fast for some. C# has moved from being a youthful language to middle age spread in under ten years.

 

It is difficult to characterize the current version of C# simply because it has acquired so many features that make it a multi-paradigm language. Initially it was a strong statically typed language - almost restrictive in its approach to typing. It implemented single inheritance with the use of interfaces inheritance to deal with more complex situations. In many ways the early C# looked more like C with objects than Java. One big difference is that C#, as with all .NET languages, compiles to intermediate code which is then run by a virtual machine. However techniques like just in time compilation is claimed to make it reasonably fast.

 

The original version of the language had some innovative features. Delegates were introduced as a way of wrapping functions within an object. This allows a C# programmer to work with functions as first class objects without the danger inherent in function pointers.

 

Version 4 of C# has additional objectives to just being a statically typed classical object-oriented language. Possibly in response to the increasingly popular dynamic languages, it introduced dynamic typing, anonymous types, extension methods and type inference. The aim is to provide these facilities without giving up type checking at compile time. It is too early to say if these features knit together well enough to provide something new and worth having.

 

C# also has its own particular approach towards generics which is another on-going area of rapid development. The next version of the language is adding features for concurrent and asynchronous programming which is undeniably an increasingly important topic.

 

The big problem with C# is that it is proprietary. There is an ECMA/ISO standard for versions 1 and 2 but so far not for 3 and 4. It is in practice very nearly a Windows only system. The official Microsoft edition of C# only runs under Windows. There is a port to the Mac and Linux under the Mono project but this generally lags behind the official Microsoft version.  As a result the .NET system and C# in particular is not much favoured away from Windows and it lacks the universal status of Java, C++ or C.

 

Key Facts

    * Imperative procedural

    * Object-Oriented

    * Class-based

    * Static strong typing with type safe dynamic

    * Automatic memory management

    * Compiled to intermediate code

 

 

If you would like to be informed about new articles on I Programmer you can either follow us on Twitter or Facebook or you can subscribe to our weekly newsletter.

 

Last Updated ( Tuesday, 05 April 2011 16:20 )

Copyright © 2011 i-programmer.info. All Rights Reserved.