<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Important Shock]]></provider_name><provider_url><![CDATA[https://importantshock.wordpress.com]]></provider_url><author_name><![CDATA[Patrick Thomson]]></author_name><author_url><![CDATA[https://importantshock.wordpress.com/author/importantshock/]]></author_url><title><![CDATA[Blocks != Functional&nbsp;Programming]]></title><type><![CDATA[link]]></type><html><![CDATA[<p><a href="http://www.joelonsoftware.com/">Joel Spolsky</a> is one of my heroes. He has a <a href="http://www.joelonsoftware.com/articles/Unicode.html">vast</a> <a href="http://www.joelonsoftware.com/articles/fog0000000069.html">amount</a> <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">of</a> <a href="http://www.joelonsoftware.com/items/2006/06/16.html">insightful</a> <a href="http://www.joelonsoftware.com/articles/APIWar.html">articles</a> that rank among the clearest and most relevant software writing today, and his blog gets more hits in a day than mine ever will. (Speaking of which, I hit 2000 visitors yesterday &#8211; around 10x more than I ever thought I&#8217;d get.) He&#8217;s a very smart cookie, and when he speaks, people listen. But last week, while browsing the top Reddit articles of all time, I was surprised to see his article <a href="http://www.joelonsoftware.com/items/2006/08/01.html">Can Your Programming Language Do This?</a> at #4. While it&#8217;s a good primer on Javascript abstraction, I don&#8217;t think it deserves as many points as it recieved. I spent the next few days thinking about why this article bothered me so much &#8211; Joel certainly didn&#8217;t say anything untrue, attack any favorite language of mine, or make some outlandish claim. But then I realized that Joel&#8217;s article fit together in a pattern of recent articles, all of which bothered me slightly.</p>
<p>Here&#8217;s what I realized: it seems that every language under the sun is being evangelized as an excellent functional programming language simply because it supports a few paradigms from FP.</p>
<p>Or, restated: <em>Anonymous functions do not a functional language make.</em></p>
<p>The most egregious example of a pundit claiming a language is functional when it&#8217;s clearly not is Eric Kidd&#8217;s well-known <a href="http://www.randomhacks.net/articles/2005/12/03/why-ruby-is-an-acceptable-lisp">Why Ruby is an acceptable Lisp</a>. Kidd tells us explicitly that Ruby is a denser functional language than Lisp &#8211; and I&#8217;ll be the first one to admit that if I were to debate the &#8220;denser&#8221; part of that sentence, I wouldn&#8217;t know what I was talking about.</p>
<p>But Ruby is not functional &#8211; Wikipedia <a href="http://en.wikipedia.org/wiki/Ruby_%28programming_language%29">calls it</a> a reflective, object-oriented programming language, and I agree with them. Yes, you can have block arguments to methods, continuations, generators, reflection, and metaprogramming &#8211; but it isn&#8217;t functional, for two reasons.</p>
<p>1. It&#8217;s hard to carry around functions as objects.</p>
<p>I really don&#8217;t know why Ruby hates parentheses so much &#8211; it&#8217;s probably part of its Perl heritage. In Ruby, you can call methods without sticking superfluous parentheses in there &#8211; take a look at this Python code:<br />
<code><br />
"  I'll write about Cocoa soon; disaster struck the app I was writing ".strip().lower().split()<br />
</code><br />
Now take a look at the equivalent Ruby code:<br />
<code><br />
"  Apple's releasing a tool </code><code>with XCode 3</code><code> which completely supersedes my Cocoa app - so I'm very depressed right now         ".strip.downcase.split<br />
</code><br />
Though you could put parentheses in front of <code>strip</code>, <code>downcase</code>, and <code>split</code>, Ruby will work just fine without them. Now, this feature makes for far fewer parentheses, thereby making code significantly more readable. But what if I want a previously-declared function as an argument? If I type in the name, Ruby will just evaluate the function. Sure, I could use the kludge that is Symbol.to_proc, but that&#8217;s ugly &#8211; and it wraps the function inside a Proc object, which has to be called with the <code>call(*args)</code> method. And that&#8217;s just ugly. In Python, all you need to do is type the function&#8217;s name to use it as an object, and append a pair of parentheses if you need to call it.</p>
<p>2. Variables are.</p>
<p>A purely functional language only has immutable variables. Ruby doesn&#8217;t. (Yes, I know LISP isn&#8217;t purely functional. But it adheres to so many other FP paradigms that we can overlook that.)</p>
<p>But I&#8217;m getting distracted, so I&#8217;ll cut the above point short.</p>
<p>Anyway, what I wanted to say was this &#8211; just because your pet language has support for anonymous functions/closures doesn&#8217;t make it a functional language. Sure, Python has <code>lambda</code> and list comprehensions (which are taken from Haskell, a purely functional language) &#8211; but it&#8217;s not functional, it&#8217;s object-oriented. Yes, Ruby has blocks (even if you do have to wrap them in Procs), but it&#8217;s not functional. Javascript may have support for anonymous functions, but its syntax can be traced back to Algol and the birth of imperative programming language. Hell, even Objective-C has blocks if you include the <a href="http://www.fscript.org/">F-Script</a> framework, and it&#8217;s the farthest thing from functional there is.</p>
<p>In conclusion, don&#8217;t say your language is a functional one just because you borrowed a few ideas from Lisp. If you want a real functional language, try OCaml, Haskell, ML, or Scheme. Calling imperative/OOP languages functional just makes the term meaningless.</p>
]]></html></oembed>