in reply to Re^8: Specializing Functions with Currying
in thread Specializing Functions with Currying
Something I've noticed in some of my own (brief) studies into functional programming is that it tends to make one think in algorithms that are not always the most efficient, and sometimes tail-recursion won't save you.
For instance, in a SoPW a while back, a poster wanted an efficient way to get the highest number in a list (or something along those lines). I posted this solution:
my $highest = pop sort { $a <=> $b } @list;
For some reason, my brain was convinced that this was the most efficient solution. While it may be a wonderful bit of functional code, it is not nearly as efficient as the iterative solution I knew quite well when I was a new C programmer:
my $highest = pop @list; foreach (@list) { $highest = $_ if $_ > $highest; }
Just what was I thinking?
I guess this is a warning not to rely on any one tool too much.
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^10: Specializing Functions with Currying
by tilly (Archbishop) on Aug 09, 2004 at 18:44 UTC | |
Re^10: Specializing Functions with Currying
by Aristotle (Chancellor) on Aug 09, 2004 at 13:19 UTC | |
Re^10: Specializing Functions with Currying
by adrianh (Chancellor) on Aug 09, 2004 at 13:28 UTC | |
Re^10: Specializing Functions with Currying
by BrowserUk (Patriarch) on Aug 09, 2004 at 13:50 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 14:12 UTC | |
by adrianh (Chancellor) on Aug 09, 2004 at 14:18 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 14:34 UTC | |
by adrianh (Chancellor) on Aug 09, 2004 at 16:19 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2004 at 14:28 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 14:39 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2004 at 15:07 UTC | |
|