Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If functional languages are really concise, why don't they have a better rank in the language shootout game?

I compared the languages at the language shootout game by their code size only. Here is a summary of what I got (shortest first, grouped by similar score).

  1. Python, Ruby, JavaScript, Perl, Lua, PHP, Mozart/OZ
  2. OCaml, Erlang, Racket, Go, Scala, F#, Smalltalk
  3. Pascal, Clean, Haskell, Common Lisp, C#, Java, C
  4. C++, Ada, ATS

I wonder why. The winners seem to be plain old dynamic languages. Erlang, Racket (née PLT Scheme), and F# are doing OK. Haskell and Common Lisp don't look more concise than claimed-to-be-verbose Java.

UPDATE:

I've found an insightful post on this topic with charts. I also found a similar comparison of languages for a larger program (a simple ray tracer). Altogether, I wouldn't say I got "the" answer, but I got some food for thought.

like image 997
Adam Schmideg Avatar asked Aug 26 '10 21:08

Adam Schmideg


People also ask

Why functional languages are not popular?

The real problem is state. Functional languages don't have global state. Most industrial problems require state at the large scale (how do you represent a ledger or a set of transaction) even if some functions at the small scale do not actually require it (processing a ledger).

Is functional programming really better?

It all comes down to your needs. If your application is supposed to be stateless, then functional programming is the way to go. But if your solution is stateful and requires state management, applying a functional approach will look unnatural. In the end, it is another great tool for solving specific problems.

Why functional programming is not mainstream?

> Functional programming is less popular because no major successful platform has adopted a functional language as the preferred language.

Why are functional languages slower?

Functional languages will seem slower because you'll only ever see benchmarks comparing code that is easy enough to write well in C and you'll never see benchmarks comparing meatier tasks where functional languages start to excel.


1 Answers

If functional languages are really concise...

1 - Programming in the large is different than programming in the small.

Nothing about those tiny benchmarks game programs should be taken as an example of how the abstractions and modularisation provided by each language would apply to programming in the large.

2 - Most of what you see in the benchmarks game summary pages only refers to the fastest programs contributed for each language implementation (slower programs are usually removed from the website after a while - when and which slower programs are removed is mostly arbitrary).

{edit: Adam, as you don't wish to take my word for it that the summary pages only refer to the fastest programs - look at the script that filters data rows for the "Which programming language is best?" page. Look at line 80 and line 82 in function ValidRowsAndMins in lib_scorecard.php - Alioth issue their own security certificate so your browser will complain.}

So to take Haskell as an example, you're looking at code size of the fastest Haskell programs that have been contributed.

3 - None of the meteor-contest programs have been removed, and meteor-contest is a programming contest without restriction - the smallest meteor-contest Haskell program is the slowest meteor-contest Haskell program.

like image 163
igouy Avatar answered Sep 22 '22 19:09

igouy