35

Many functional language advocates make a few surprising assertions about them:

  • functional languages code is significantly less buggy than otherwise
  • functional languages code is significantly faster than otherwise in parallel scenarios
  • functional languages code is significantly cheaper to write than otherwise

I am only able to find a lot of speculation on the matter but I can't find hard data. Has anyone actually measured it?

I'd only like to see answers citing peer-reviewed material from reputable sources, such as IEEE or ACM. I am not interested in any logical or theoretical explanation, but only in rigorous measurements on real world projects/code bases.

Sklivvz
  • 78,578
  • 29
  • 321
  • 428
  • 3
    Why not link to [one of Paul Graham's essays](http://paulgraham.com/iflisp.html) for notability? – dmckee --- ex-moderator kitten Apr 14 '14 at 01:04
  • 3
    I think the "faster" argument might need to be clarified a bit, the way I have heard this only refers to functional programming being easier to run in parallel on many cores, not that they are intrinsically faster. – Mad Scientist Apr 14 '14 at 05:52
  • I've fixed the post accordingly – Sklivvz Apr 14 '14 at 08:51
  • 1
    *"significantly faster than otherwise in parallel scenarios"* is that really a claim? Doesn't make much sense, OTOH claim *"significantly faster to develop than otherwise in parallel scenarios"* could have some merit. – vartec Apr 14 '14 at 13:06
  • @vartec the parallel claims typically hinge around not using locks due to the thread safety of immutable data. – Sklivvz Apr 14 '14 at 13:07
  • 1
    @Sklivvz: I know, but as far as raw speed goes, any kind of high-level language can be replaced, using significant effort of course, with highly-optimized low-level code implementing same functionality. Take for example Scala, it's running on top of JVM, which is itself implemented in C++. – vartec Apr 14 '14 at 13:14
  • 2
    *"I'd only like to see answers citing peer-reviewed material from reputable sources, such as IEEE or ACM."* Nice requirement, however I don't think you'd get any relevant answers. First of all research lags behind marked by many years. Moreover I have impression that current fast moving companies aren't really interested in 80s style mega-corporation "productivity metrics", so I wouldn't expect much effort going to real life study of the question. – vartec Apr 14 '14 at 13:20
  • @vartec For example: ["Many statically-typed FunctionalLanguages can do things faster than C as well, especially in the absence of SideEffects."](http://c2.com/cgi/wiki?AsFastAsCee) – Sklivvz Apr 14 '14 at 13:24
  • 2
    @Sklivvz: that part is marked with [DemandForEvidence](http://c2.com/cgi/wiki?DemandForEvidence), logically you cannot really have a high-level language implemented in C (or C++ for that matter), be faster than C. It all comes down to *practicality* of doing low-level programming if you can implement it with enough speed (and ease) in higher level language. – vartec Apr 14 '14 at 13:37
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/13880/discussion-between-sklivvz-and-vartec) – Sklivvz Apr 14 '14 at 13:39
  • @Sklivvz How do you distinguish functional from non-functional languages? All languages sit on a spectrum of functional purity - where do you draw the line? – Dave Hillier Apr 14 '14 at 18:34
  • @DaveHillier I agree there is a continuum, but the claim can be proven right or wrong without a clear definition. For example, if one could show that a functional language is only performant when used in a procedural way, this would clearly negate the claim even though there could be a discussion on whether the language in question is purely functional or not. – Sklivvz Apr 14 '14 at 18:48
  • Not to unnecessarily extend the discussion, but I'm of the opinion that @vartec has the right of it. The claim that functional languages can be *faster* than procedural languages must be made very carefully; otherwise, taken literally, it's false almost by definition. – Patrick87 Apr 14 '14 at 22:46
  • @Patrick87 the discussion is if the claim has been made or not. Whether it is true or false -- we can leave that to the answers :-) – Sklivvz Apr 14 '14 at 22:52

1 Answers1

13

Pankratius, Schmidt, and Gareton, 2011 found:

Contrary to popular belief, the functional style does not lead to bad performance. Average Scala run-times are comparable to Java, lowest run-times are sometimes better, but Java scales better on parallel hardware. We confirm with statistical significance Scala’s claim that Scala code is more compact than Java code, but clearly refute other claims of Scala on lower programming effort and lower debugging effort.

As always with empirical studies of software development, one must be very cautious about generalizing. In the particular case of a study about Scala done in ~2010, one would certainly worry about:

  • language familiarity (Scala being far less popular than Java)
  • tool support (a problem that's still significant, but was acute in 2010)
  • use of immutable data structures

(Update: It's not clear to me that this study was ever peer-reviewed.)

Larry OBrien
  • 15,105
  • 2
  • 70
  • 97