An expressive programming language allows developers to implement algorithms quickly, by using high-level concepts and leaving the details to the language implementation. The result is clearer, more maintainable code that can be created in less time. (Although shorter code isn't always better, especially when taken to extremes.)
So which programming languages use the least code, when compared on an apples-to-apples basis? At the WolframAlpha blog, Jon McLoon analysed the same algorithms (from the Rosetta Code project) implemented in 14 different languages, and compared the program sizes. Jon used the metrics of lines of code, characters of code, and token count (which ignores varying length of procedure names) to measure program size. According to Jon, the fairest comparison is character count for non-trivial algorithms ("large tasks"), and the results are shown below:
The shortest code on average is produced by programs written in Wolfram's Mathematica. The runner-up is Clojure, closely followed by the R language. For comparison, programs written in Python are more than twice the length of equivalent programs in R; programs in C++ are about 4x the length. Read the complete analysis at the link below.
Wolfram Blog: Code Length Measured in 14 Languages
I have absolutely no doubt that had this been tried in either APL or its successor, J, that either would have won, hands down. They are known for their extreme terseness and concision.
Posted by: David Smith | November 17, 2012 at 19:23
I don't think that table is Tufte-compliant. :-) . It's really hard to tell quickly what the relative order of the languages is. For example, start with the "R" row. It's short, so to find out the relationship between "R" and Matlab,Clojure.Haskell,Ruby,&Pascal, you have to jump around the previous rows. Can some enterprising coder take the source data and plot it better? Look: we all know Mathematica won, so put it as the first row, but order the columns in decreasing magnitude. Since "language A faster than lang B" is transitive, we really don't need any more than that one line to calculate all the ratios anyway, but for the casual reader, placing the rows in this new order will be a lot clearer, I think.
Posted by: Carl Witthoft | November 18, 2012 at 11:50
Actually, to present the data accurately, it is not transitive.
If all tasks were complete in all languages it would be possible to represent the data with a single row.
But because the tasks that are common between language A and B are not the same as between B and C or between A and C, it is possible for A>B>C>A to occur.
Posted by: Jon | December 21, 2012 at 06:30