Less Code and Less Bugs : with Functional Programming languages

With a FP language many problems can
be solved with elegantly less code and
less-code leads to less-bugs.

Functional Programming (FP) insider know that, because they have personally experienced it. This can be tweeted and blogged many times, but how can others believe this? How do you prove it?

That problem inspired me to do some investigation. We need facts. What I’ve found so far are two studies that show this from a data analysis side. There is some evidence that both is true, according to these newer papers from 2014, based on data analysis of source code and its history from Github and from Rosetta Code :

Functional languages have a smaller relationship to defects than other language classes where as procedural languages”
– [1] A Large Scale Study of Programming Languages and Code Quality in Github
Functional and scripting languages provide significantly more concise code than procedural and object-oriented languages.”
– [2] A Comparative Study of Programming Languages in Rosetta Code


In [2] the data analysis covers 8 widely used languages representing the major programming paradigms
- procedural: C and Go;
- object-oriented: C# and Java;
- functionalF#  and  Haskell;  
- scripting:  Python  and  Ruby


I think the “less code” property is underestimated, because the too easy Lines of Code (LOC) counting is ridiculed. Looking beyond the LOC of the code base to the more important depending consequences :

less code  ->  less to read (more often than write!) and understand   -> 
less to review ->  less to communicate ->  less to refactor -> 
less to test  ->  less bugs  -> 
less to maintain  ->  less cost!!!

Btw. less code -> more time to think -> better solution -> more fun!


References

Other related analysis about software quality metrics, especially circular dependencies can be found here:
- “Comparing F# and C# with dependency networks
- “Cycles and modularity in the wild – Comparing some real-world metrics of C# and F# projects”

[1] A Large Scale Study of Programming Languages and Code Quality in Github
Baishakhi Ray, Daryl Posnett, Vladimir Filkov, Premkumar T Devanbu, Department of Computer Science, University of California, Davis, CA, 95616, USA
2014 http://dl.acm.org/citation.cfm?id=2635922


[2] A Comparative Study of Programming Languages in Rosetta Code
Sebastian Nanz, Carlo A. Furia, Department of Computer Science, ETH Zurich, Switzerland
2014 http://arxiv.org/abs/1409.0252