Programming Language Comparison

Programming Language Comparison

Robbert Haarman



This is a simple comparison of programming languages. The aim of the comparison is not to make any claims as to which language is better, but rather to show how common tasks (like performing an operation on every element of a sequence) are performed in various languages. To this end, a number of programs are written in each language, each program showing different aspects of programming.

Just for fun, a few numbers will also be extracted from each program. For now, this is the number of words in the program, as counted by the wc command of Unix. This provides a very rough approximation of how much code is in the program. Counting words, rather than counting lines, as is more commonly done, avoids the problem that different coding styles and identifier length might yield different values, even though the program is actually the same.


This is the classical "Hello, World!" example, in a slightly more original form. It serves as a test of how much boilerplate is required to write a minimal program.


This program asks the user to enter their name, and then prints out a greeting. It demonstrates reading a line from standard input and writing a mixture of hard-coded and user-supplied values to standard output.


This program prints out the command line arguments that were given to it. It shows how to access command line arguments and demonstrates iteration over all members of a sequence.


This program implements Euclid's algorithm for determining the greatest common divisor of two natural numbers. It demonstrates function definitions, early returns, and some integer arithmetic. The algorithm is implemeted recursively in languages that are properly tail-recursive1, and iteratively in other languages.


This program implements the quicksort algorithm for integers. It demonstrates recursion, allocating sequences, iterating over sequences, and concatenating sequences.


This program copies a file. It shows how to open files and ensure that they are closed afterwards, and it shows haw to do binary I/O.


This program transforms a formula from some internal representation into a string representation in infix form. It shows decissions being made based on tags in the data, a useful technique for various tasks, such as symbolic computation and interpretation.

1 A properly tail-recursive language is one that optimizes tail-recursive algorithms so that the recursion doesn't cause them to run out of space. An algorithm is tail-recursive when the recursive calls happen in tail position. This means that the function that performs the recursive call will immediately return the value returned by the recursive call, without doing anything else. Euclid's algorithm is an example of a tail recursive algorithm.

Valid XHTML 1.1! Valid CSS! Viewable with Any Browser