optimization of list comprehensions

Mats Cronqvist mats.cronqvist@REDACTED
Thu Mar 9 15:01:10 CET 2006

Richard A. O'Keefe wrote:

 > If you have evidence to back this up, it's publishable.
 > Please publish it.  Some sort of survey analysing what kind of
 > programmers use what kind of language features would be most illuminating.

Ulf Wiger (AL/EAB) wrote:

> I think it's safe to say that even "average" industrial 
> programmers rather quickly learn to exploit the virtues
> of higher-order functions and iterators.

   not to be outdone by wiger (and since o'keefe said please), i ran a few greps 
on 1,748,162 lines of erlang sources (comments included). i estimate that some 
3-400 people have contributed to the code sample.
   i counted how many times each of the patterns below appeared per module.

         "[ (]fun[ (]"  "lists:fold" "lists:map" "lists:foreach"
never          64%            89%          84%          85%
<3 times       81%            97%          94%          94%

   36% of the modules defined at least one fun. however, 15% of all modules had 
at least one call to mnesia:transaction. so i feel pretty confident stating that 
  ~80% of all modules have no (non-mnesia related) funs.
   another observation is that although there were ~2 fun definition per module, 
4% of the modules accounts for 50% of the fun definitions.
   one possible interpretation is that most of this code was produced by 
programmers that rarely use funs if they don't have to. obviously, the 
methodology is much too weak to *prove* this. i'm not sure it can be proven, 
since there's no way to establish who wrote what. most modules have been touched 
by at least a handful of people, and everyone has worked on more than one module.
   note also that most of this code sample has been used for years in a very 
challenging environment, and is part of one of the most stable products in its 
   i does seem safe to say that one can write well working Erlang code while 
rarely, if ever, using funs (excluding mnesia use, as always).


More information about the erlang-questions mailing list