Only if implemented using tail recursion so you don't end up with hellishly bloated stacks.

I like to use it also but often it's far more efficient to iterate.

Nothing beats recursion for tree walking though. But it is almost always better to use a cursor and a forever loop with a breakout clause. There's no hidden subroutines this way, your memory usage can be more easily bounded.

I'm of the opinion in general that the neatness of functional programming is not really suited to the hardware design, and the hardware design is the efficient way to implement execution.

If you go pure functional, you are copying everything at the function call boundary, which can be substantial overhead, and this tail recursion thing, effectively is adding a cursor and a forever loop with breakout in the background. In other words, the elegance is an illusion.

It's ok for small data sets, and if you stick to pass by value, it's concurrent safe, but it's a heluvalot more memory copy intensive. Once you blow up your L1 and L2 caches you see this convenience starts to become a curse.

Reply to this note

Please Login to reply.

Discussion

No replies yet.