Pinderkent

Pain and glory from the trenches of the IT world.

JavaScript cannot be considered a functional programming language.

Posted on Sunday, February 24, 2008 at 8:05 PM.

As both JavaScript and functional programming have gained traction over the past several years, one common misunderstanding that I've seen expressed more and more often is that JavaScript is somehow a functional programming language. Such an example of this can be found in this Reddit comment, where the author says, "I don't know much about functional programming other that what I've picked up hacking javascript, ..."

One of the main traits of functional programming languages is that of referential transparency. JavaScript is obviously nowhere near as purely functional as a language like Haskell. While it is possible in JavaScript to write functions in a way that minimizes or eliminates side effects, this is often not at all practical (especially when using JavaScript for Web development). Most JavaScript code heavily concerns itself with manipulating the mutable Web browser DOM.

Support for tail recursion is another hallmark of functional programming languages. JavaScript does not offer such support, by default. It is possible to get a hackish form of tail recursion working with JavaScript, but it clearly is not comparable to what is offered by Scheme implementations, Haskell, and other truly functional languages.

Having support for first-class functions does not make a language "functional". Functional programming is a much broader philosophy, and JavaScript does not subscribe to or exhibit many of its ideas. So we should not mistakenly think that by using JavaScript, we are partaking in functional programming using a functional language.

Permalink: http://pinderkent.phumblog.com/post/2008/02/javascript_cannot_be_considered_a_functional_programming_language
Share:
Feeds
  • RSS 2.0 Feed
  • Atom 2.0 Feed
Tags
Archives