The Great Programming Language Continuum; or why C++ is dying
The long term trends of TIOBE's programming language index tell a sad story for C++; it is on the decline. Once comparable to C in popularity, it has lost market share to a new breed of higher level languages. During the same period C's market share remained has retained its popularity. Why has such an old fashioned language thrived whilst C++, its more modern object oriented cousin, has begun to fade?
This is best explained by imagining that all programming languages live somewhere on a continuum between the lowest level language of all - Assembler - and what would be the highest level language of all if anyone could write an interpreter for it - Human speech. A small subset of the this Great Programming Language continuum ordered from low level to high level is
- Objective-C, Go
- Java, C#
- Python, Perl, Php, Ruby
- Human Speech: Chinese, Spanish, English, . . .
Many languages are missing from this list, but it paints the correct picture. As you descend the list, direct commands to the processor are replaced by conceptual abstractions and the source code will reflect the problem being solved more than it will the instructions the computer must execute to solve the problem. Code written in a higher level language tends to be easier to read, shorter and quicker to write than code in a lower level language, but the resulting program almost invariably runs more slowly. When choosing a language for a problem a programmer must balance the performance of the resulting software against the time it will take to write that code.
Law of lazy Coders: *Programmers will always code in the highest level language possible*
The higher level the language you write your software in, the fewer lines of source code you will write, and in most cases, the faster and cheaper it will be to build that program. For these reasons, real world time and cost constraints force the majority of programmers to choose the highest level language possible when starting a project.
C++ was popular for writing desktop software in the nineties, because the answer to the question what is the highest level language I can write a good spreadsheet in? was C++. During the noughties, advances in processor technology changed that answer to C# or Java, and programmers quickly migrated to friendlier, garbage collected languages with large standard libraries.
C has retained its popularity because the answer to the question what is the lowest level language I can code in without using assembly has always been C, and it is unlikely to change. For those who cannot afford any latency in their code, whatever the cost to the programmer, or who need to plug into the lowest levels of the operating system then C is, and will remain, their language of choice.
Haskell is interesting to me because it is tough to definitively place it on the continuum. Its native compilation and static typing make it low level when compared to its distant functional cousin, LISP. However, lazy evaluation, Algebraic data types are characteristics of a much higher level language. This is the magic of Haskell. Idiomatic Haskell knits together high level and low level aspects with Monads.
Take, for example, Parsec, a Haskell library for building parsers. Parsec itself handles low level string manipulation and wraps this in the high level Parsec monad to define a Domain Specific Language perfect for parsing. With this DSL defined, writing an actual parser is criminally easy. Take the following example of an if statement in BASIC. You can see how the
ifstatement parser is constructed naturally out of parsers for smaller elements of text.
ifstatement = do wspaces string "IF" wspaces cond <- condition wspaces string "THEN" wspaces eol blk <- block wspaces string "ENDIF" wspaces eol return (EIf cond blk)
C++'s decline will continue. Hardware advances will continue to make its efficiency redundant and Domain Specific Languages are nudging the principles of functional programming into the mainstream. Like world peace and lower taxes, we have learnt to distrust the promise that functional programming is about to spring into the software industry's cube farms. Nevertheless, even conservative programmers have come to trust Linq, a dataset DSL for C#.
Posted on 20 January 2013
Based on a work at http://slidetocode.com/blog
Slide to code blog is licensed under a Creative Commons Attribution 3.0 Unported License