[Haskell-cafe] Haskell performance (again)!
dagit at eecs.oregonstate.edu
Sun Oct 8 18:25:32 EDT 2006
On 10/8/06, ihope <ihope127 at gmail.com> wrote:
> On 10/8/06, Yang <hehx0sk02 at sneakemail.com> wrote:
> > And do most (experienced) Haskell
> > users sacrifice cleanliness for speed, or speed for cleanliness?
> Keep the internals of your code--that which will be looked at a
> lot--fast and ugly, while the rest can be clean. If you have a
> function that does something very simple, but the "pretty" way to do
> it takes a second to run while the ugly way is much, much faster, use
> the pretty one if it's only going to be needed once or twice. It's
> certainly not the kind of thing you want to fold your lists with: use
> the ugly version for that.
> Also, if you want, you can write both a pretty version and an ugly
> version, and put the pretty version in comments while the ugly version
> does all the real work.
Another good idea when you have a pretty version which is easy to
verify for correctness and an ugly version that is harder to verify is
to use QuickCheck or SmallCheck and define a property that says both
versions are equal for all inputs. Ugly code is notorious for holding
bugs, but doing this would help test the ugly code.
More information about the Haskell-Cafe