Java and C
Written by Mike James   
Tuesday, 05 April 2011
Article Index
Java and C
C++ and C#

 

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

 

Look out for Part Two of our State of the Languages survey and vote for your favourite language in our poll.

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 )