Re:Trampolines in JavaScript
by sluukkonen on Friday September 06, 2013 @12:58PM
(#6341386)
Small steps. Just using some simple functional constructs like `map` and `filter` will do wonders for your code. You don't have to start writing everything in a purely functional manner to benefit from it.
[ Parent
| on HN ]
Re:Trampolines in JavaScript
by crazygringo on Friday September 06, 2013 @01:04PM
(#6341424)
Oh, for sure -- I use map/filter/reduce/etc. whenever I can when they result in cleaner/shorter code. They're great.
I'm asking more about things like tail-call recursion/trampolining, function decoration -- making the "architecture" of your program more functional, rather than just a few lines here or there.
Recursion isn't really hard once you get used to it, and often leads to shorter/cleaner code. Map/filter/reduce are themselves very clearly expressed using recursion.
Indeed, I've started using many functional concepts in a Perl program I maintain.
Functional code isn't just good for concurrency, it also helps when trying to reason about lists and associative containers at a higher level.
For anyone interested in applying functional concepts to Perl, I highly recommend Mark Jason Dominus's Higher Order Perl[1], the full text of which is now available online for free.
It starts by teaching a reader moderately familiar with Perl functional concepts, and then it deep dives into these concepts and iteratively applies them to example programs to make them better.