Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If by the 'functional style' you mean the usage of concepts like 'map', 'apply', 'reduce', 'filter', lambda functions and list comprehensions, then it should be evident that code that has to deal with operations on lists is almost always more concise when written in the 'functional style'. But if you're mixing 'functional style' with imperative code in a mostly imperative language, it really is just a matter of style.</p> <p>In python for example, you can reimplement the Haskell qsort crackmigg posted like so:</p> <pre><code>def qsort(list): if list == []: return [] else: x = list[0]; xs = list[1:] return qsort(filter(lambda y: y&lt;x, xs)) + [x] + qsort(filter(lambda y: y&gt;= x, xs)) </code></pre> <p>Although writing the last line as</p> <pre><code>return qsort([y for y in xs if y&lt;x]) + [x] + qsort([y for y in xs if y&gt;=x]) </code></pre> <p>is arguably more 'pythonic'.</p> <p>But this is obviously more concise than the implementation here:</p> <p><a href="http://hetland.org/coding/python/quicksort.html" rel="nofollow noreferrer">http://hetland.org/coding/python/quicksort.html</a></p> <p>Which, incidentally, is how I would have thought about implementing it before I learned Haskell. </p> <p>The functional version is extremely clear <em>if</em> and <em>only if</em> you are acclimated to functional programming and grok what <code>filter</code> is going to do as easily as the well-worn C++ programmer groks a <code>for</code> loop without even having to think much about it. And that's clearly what the real issue at stake here: functional 'style' programming is a <em>completely different mindset</em>. If the people you work with aren't used to thinking recursively, and aren't the type to get excited about, not just a new technology, but a whole other way of thinking about solving their problems, then any amount of code comparisons isn't going to win them over.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload