Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Star /prog/ Movies

Name: Anonymous 2009-10-17 7:27

So I heard that Lucas is producing some new movies, a kind of isomorphism against Star Wars. The titles are:

Ep.I: The Haskell Menance;
Ep.II: Attack of the Sussmans;
Ep.III: The revenge of Frozen Void;
Ep.IV: A New Troll;
Ep.V: Sepples strikes back;
Ep.VI The return of the Haxus.

...and here it seems we have a trailer for Episode V:
http://gigamonkeys.com/blog/2009/10/16/coders-c++.html

Name: Anonymous 2009-10-20 17:33

Let's take a random simple example from the Factor codebase1.

: find-last-integer ( n quot: ( i -- ? ) -- i )
    over 0 < [
        2drop f
    ] [
        [ call ] 2keep rot [
            drop
        ] [
            [ 1 - ] dip find-last-integer
        ] if
    ] if ; inline recursive


Even in this trivial case the stackrobatics are quite overwhelming. Now let's try this with cond and locals.

:: find-last-integer ( n pred: ( i -- ? ) -- i )
    { { [ n 0 < ] [ f ] }
      { [ n pred call ] [ n ] }
        [ n 1 - pred find-last-integer ] }
    cond ;


That's a whole lot clearer. For some reason Factor coders seem to avoid this style, maybe because they might just as well use a Lisp?

(define (find-last-integer n pred?)
  (cond
    ((< n 0) #f)
    ((pred? n) n)
    (else (find-last-integer (- n 1) pred?))))


I gave Factor a fair chance; I even submitted a small patch to the implementation. But idiomatic Factor code is hard to read and hard to modify. Pointless style is great if you're a wanker like Slava, but if you want to quickly write some readable code, just use some variables.


1 http://gitweb.factorcode.org/gitweb.cgi?p=factor/.git;a=blob;f=core/math/math.factor;h=8ef4f38f9aeac470ed8f69aac54d00092b4730c8;hb=HEAD#l172

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List