in reply to a better fibonacci subroutine

It's a matter of taste of course, but I can see no ugliness in the "Haskell guy's" version. It's clean, understandable perl code. I'd advise against the use of $a and $a for other things than sorting, though. That would be my only critic (and it applies to your code, too).

As of which is better - yours is recursive, his is iterative. You need to use Memoize, he doesn't. You are spending more resources than he is.

The other way round - what makes your version better, apart from "prettiness" (whatever that means)?

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: a better fibonacci subroutine
by apotheon (Deacon) on Dec 15, 2006 at 09:04 UTC

    One thing that strikes me immediately about his version is that it almost requires one-letter, or at least greatly abbreviated, variable names to keep line lengths manageable. I also tend to find that reducing the number of variables scattered throughout a snippet of code pretties things up and makes them easier to reason through, thus enhancing that ephemeral quality "readability". Further, the complexity of the code in general is greater in the iterative version, as measured in discrete syntactic elements, which strikes me as (all else being equal) a usually useful metric of pleasant succinctness of code.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    CopyWrite Chad Perrin