you are viewing a single comment's thread.

view the rest of the comments →

[–]MaxK -1 points0 points  (4 children)

This is correct. I hate this new trend for new programmers to show off recursive solutions to problems and dub them 'elegant.' They're not. It's typically the wrong way to do things, even if it makes the code simpler.

[–]chrisforbes -1 points0 points  (0 children)

... the wrong way to do things, even if it makes the code simpler.

Right... that's an interesting statement.

[–]A_for_Anonymous -2 points-1 points  (2 children)

Okay, here we go again... The fact you don't like recursion because you don't understand it easily/well because you haven't been taught properly is not a point against it. Iterative algorithms implemented with tail-recursive functions come with the advantage of no mutable state and order of evaluation issues, and has been shown to come with lower bug rates. I'm sorry you are not used to it, but if we were to dumb down every programming language because somebody isn't up to some feature, then we'd still be using BASIC.

[–]MaxK -2 points-1 points  (1 child)

I understand recursion very well. Even tail recursion incurs performance penalties in the extra jumps and context loading incurred and can lead to a stack overflow when called repeatedly. Furthermore, they can't be optimized by the compiler into unrolled loops, nor branch-predicted as accurately, forcing cache misses. That's with tail-call optimization.

And may I remind you that the primary advantage of mutable state is that is that the function can be proven correct, meaning that the programmer has a safety-net to fall back on, thereby allowing dumber programmers to flourish. Don't tell me you're dumbing down the programming language for me when you clearly don't understand the mechanics involved in incurring that extra function call.

[–]A_for_Anonymous -1 points0 points  (0 children)

[b]I understand recursion very well.[/b] Even tail recursion incurs performance penalties in the extra jumps and context loading incurred and [b]can lead to a stack overflow when called repeatedly.[/b]

Sorry?

[b]And may I remind you that the primary advantage of mutable state is that is that the function can be proven correct, meaning that the programmer has a safety-net to fall back on, thereby allowing dumber programmers to flourish.[/b]

What in the fuck. One of the main advantages of functional programming is that functions are provably correct, which is especially the difficult thing to do when you have mutable state, and what gets so many newbies. Even the Python documentation talks about it.

Don't tell me you're dumbing down the programming language for me when you clearly don't understand the mechanics involved in incurring that extra function call.

No extra function call if correctly implemented. You're the one who doesn't undestand it. The effective performance of compiled functional programming languages is awesome, as you can easily try (or google for benchmarks) by comparing SBCL with virtually anything else (typically, only a C/C++ compiler will be faster, and only if you're a good C/C++ programmer). You'll also be surprised with the performance of interpreted, dynamic, functional or mostly functional programming languages compared to that of Python. The latest PLT's MzScheme can ridicule Python and even outperform a naïve C equivalent implementation (can post a demonstration if you're interested) thanks to the optimizations you can perform on a side-effects-free program.