The barbarism of the for loop

I’ve been reading Programming Erlang and also casually looking into Haskell. So yesterday when I tinkered with Processing just a little bit, code like this just looks barbaric:


  for(int i=0; i<width; i++) {
   doSomething(i);
  }

Compare to Erlang:


  % Closer to Java and PHP. Nearly, but not quite, tolerable
  lists:foreach(DoSomething, lists:seq(1, 50)).

  % More Ruby/Lisp like. I can dig it.
  lists:map(DoSomething, lists:seq(1, 50)).

  % List Comprehensions FTW
  [doSomething(I) || I <- lists:seq(1, 50)].

I mean, really. If you’re writing @for@ loops in 2008, don’t pass go, don’t collect $200. Or even 200 Euro.

The caveat is if you’re implementing a language or compiler. Then I’ll forgive you. But if you could work that out by 2009 or so, we’d all thank you.

Adam Keys @therealadam