[erlang-questions] foldl vs foldr and ++

Wojciech Knapik <>
Fri May 11 10:06:59 CEST 2012


On Fri, May 11, 2012 at 02:02:41PM +1200, Richard O'Keefe wrote:

> This can be written more efficiently, but it's best of all
> just not to reverse the string in the first place.  Keep
> the code at a level where you can see what's going on well
> enough to spot the really _big_ efficiency gains.

Yeah, the way I see it, you should optimize for clarity in 90% of the
cases and for performance when a piece of code is run many times in the
course of the program's execution.

So in this case:

foo,
bar,
loop(
  loop(baz))

the efficiency of foo and bar doesn't really matter. Baz on the other
hand needs to be relatively efficient.

People get way too hung up on speed IMO. I'll take slower, but more
readable code, over fast and unreadable any day. And in any
"professional" setting it's cheaper to buy a faster machine and keep the
code clean if the performance is not satisfactory.

Of all the developers out there, those favouring declarative languages
should agree...

WK



More information about the erlang-questions mailing list