A problem of language

I try to stay out of language wars these days. I find the whole endeavour incredibly tedious. I don’t really feel like arguing whether OCaml is better than Ruby is better than Scala is better than brainfuck is better than C. I like them all (ok maybe not brainfuck), and there are valid arguments for and against each of them.

But one thing I have a lot of trouble with is bad arguments. Not “arguments I disagree with”, but arguments which are simply outright bad.

Robert Fischer has a post on his blog: Scala is not a functional language. It’s not the first time this idea has come up. It’s not an idea entirely without merit. Scala’s functional features are certainly not as seamless to use as one might hope.

The problem is that while it is not an idea without merit, its presentation is certainly one without content. As per usual, every time this comes up, no one is actually willing to say what on earth they mean by “functional programming language”. This problem is ubiquitous. Consider the following wikipedia entry:

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state. Functional programming has its roots in the lambda calculus, a formal system developed in the 1930s to investigate function definition, function application, and recursion. Many functional programming languages can be viewed as embellishments to the lambda calculus.

Notice the bait and switch there? It defines “functional programming” and then talks about “functional programming languages“. Everyone does this. The only unambiguous definition you find which includes the term “functional programming language” is that of Purely functional language. This is much less ambiguous, but it’s also the case that the vast majority of people arguing about whether Scala (or other language of choice) is functional are comparing it to a decidedly impure language. Certainly neither Clojure nor OCaml are purely functional.

On the other hand, if you choose “functional programming language” to simply mean “supports functional programming” then suddenly you have to acknowledge various languages like Ruby as functional and for some reason this makes people uncomfortable. So instead we end up with all sorts of hand waving and mumbling and no one is able to have a useful discussion because everyone is too busy making assertions which can’t be argued with because they don’t mean anything.

So no one defines the term, but everyone seems to “know what it means”. And what it inevitably means is “shares features with this language which I use and like and consider to be a functional language”.

For a particular extreme example, consider the following conversation on reddit from the last time this subject came up:

vagif:
Well, here’s my understanding of this disagreement.
I think many people (me included) do not feel that Scala is functional enough. It is not because of the mutable variables. It all boils down to simple syntax. That’s why completely imperative and old fashioned language CL (i use sbcl) feels to me much more functional than Scala will ever be with its modern functional features like pattern matching, type inference and list comprehensions.
“Functional” for me means simple small core of orthogonal features.
“Functional” for me means – List processing.
“Functional” for me means no premature optimization (deciding to use arrays instead of lists because they are faster etc.)
Obviously, trying to accommodate java OO model, makes Scala way to complicated, arcane, baroque in its syntax, to feel functional enough.

DRMacIver:
I enjoy the fact that the word “function” does not appear in your definition of functional…

vagif:
And for a good reason. Functions are part of any imperative language. That does not make them more functional. It is all that infrastructure, that allows for easy juggling those functions, that makes a language functional. Passing them as parameters and return values, anonymous functions, closures, polymorphic functions (be it a result of type inference or dynamic nature of language). It is this small core of orthogonal features, all geared up for list processing, that truly creates a functional feeling in a programmer.

This sort of woolly thinking is endemic in these arguments. Please try to avoid it. If you’re not willing to define “functional programming language” in a way that is at least moderately unambiguous and doesn’t involve arguments about “feelings” or simply feature comparisons with some language which you state as an example of functional programming, don’t bother making arguments about whether a language is functional or not.

Of course, once you start defining the term people will start arguing about the definitions. This is pretty tedious, I know. But as tedious as arguing about definitions is, it can’t hold a candle to arguing without definitions.

This entry was posted in programming and tagged , , on by .

24 thoughts on “A problem of language

  1. fogus

    Functional has always been one of those terms that is meaningless to the practical programmer. Functional is the leader of a Rogues Gallery of misused computing terms: DSL, Combinator, Closure, Monad, and Immutability.

    -m

  2. david Post author

    I’ve not noticed “immutability” being abused, and “monad” abuses are at least a rarity (monad metaphors not so much). Definitely agreed on the rest (as I think we’ve discussed recently).

  3. fogus

    Monad is currently a petty thief on the rise… Immutability is more often abused in practice as many programmers think that by removing their setters they’ve conquered persistence; but maybe that’s just the people I’ve had the pleasure to work with.

    -m

  4. Pingback: -= Abused Computing Terms =-

  5. Josh Suereth

    My definition of functional programming language (which is the only possible correct definition, because it is mine): “A language that can be used to perform some task”. In this sense, brainfuck is purely functional for tasks such as:
    * Printing Hello World
    * Confusing Others
    * Confusing Yourself

    Whereas scala is functional in this sense:
    * Writing programs that do something.

    End of Argument.

  6. Daniel Spiewak

    Quite right, David! I’m as guilty of this debate as anyone else, but I agree that it’s silly to bicker about it without accepted definitions. I do think that Scala isn’t “functional enough”, but since I can’t define what that means, there is really no point in saying it.

    I think what everyone can agree to is the fact that Scala’s syntax for functional idioms (like currying) isn’t as clean as languages like ML (and friends) or Haskell. However, Scala also has a real module system, class inheritance and polymorphism, etc. I think that people are focusing on the wrong things. Sure, Scala doesn’t have some trademark functional features in a clean form, but the other things it brings far outweigh what it is missing.

  7. Robert Virding

    Strangely enough I think vagif’s second text block where he describes the infrastructure for handling functions is getting closer to what functional programming is about.

  8. Chris Rathman

    Lists, closures, optimization (laziness), lambda calculus, simplicity, etc… are not items that one can confine to functional programming. They are simply artifacts of languages that strive to be functional. The definition laid out in the original Functional Programming FAQ is about as good as any I’ve seen (and it hasn’t been updated in eons):

    Functional programming is a style of programming that emphasizes the evaluation of expressions, rather than execution of commands. The expressions in these language are formed by using functions to combine basic values. A functional language is a language that supports and encourages programming in a functional style.

    I think that the problem is that a true definition of functional programming requires a more in depth sense of what is a function in the mathematical sense, rather than what we call functions in the programming language sense. Of all the PL terms, referential integrity comes closest to capturing the essence of this drive to programs as mathematics. Even though purely functional programming languages like Haskell and Clean come closer to this ideal, that functions for these languages are not the same as functions in the mathematical sense.

    (And why all the hate for BrainF*ck).

  9. Daniel Sobral

    To me, a functional language is one which supports lambda calculus.

    I don’t mean syntax, to be very clear. Just that each thing that can be done with lambda calculus can also be done in the language.

    That also means that most languages augmented by a library can be functional. In that case, we would say that Language X with library Y is functional, not that language X is functional. After all, any language can be used to create a LISP interpreter. :-)

  10. Tracy Harms

    Rather than focusing on categories such as “functional language” that invite us to debate whether a given language fits inside that box, we could put our attention toward particular problems and classes of problems. We can then compare and contrast languages with regard to how easy or hard it is to formulate solutions, and which sorts of solutions are most natural in each.

  11. david Post author

    Tracy: No argument here. There’s a reason I try to stay out of these discussions. I just have a hard time ignoring bad arguments. :-)

  12. Fred

    The near impossibility of having sober conversation about these topics and the near inevitability of the conversations becoming emotional is dictated by two disheartening realities.

    Knowing a programming language well (let alone creating one) is a non-trivial undertaking both in time and intellectual effort. To see that effort diminished casually, whether correctly or not, is something we rebel against. Because of our efforts we see it as diminishing not just our choices, but ourselves. It’s certainly possible to move beyond this, but it’s not always easy. It is interesting to note that often the language creators themselves seem to have less ego wrapped in the language than others. There may be something to the notion that the expending the necessary effort to create enlightens one to the notion that worth comes from creating not creations.

    Second, the programming languages we defend and those we attack fit into the broader picture of the stories we tell ourselves about who we are. If we the utterances coming from the Ruby or the Haskell community are more how we picture ourselves, the more likely we are stand by them. If Dennis Ritchie and Rob Pike are our heroes, C it is. On the other hand if Paul Graham resonates, the answer to all questions is LISP did it first and LISP did it better. What makes this so sad is that these hardly rise to the height of religious wars, raging over fundamental beliefs. They’re not even like a spirited political debate. They are more like arguing in a bar about football teams (American or the other kind, take your pick).

  13. Jeff Heon

    I really do like this definition of functional programming as a programming style from http://java.ociweb.com/mark/clojure/article.html#FP

    Functional programming is a style of programming that emphasizes “first-class” functions that are “pure”. It was inspired by ideas from lambda calculus.

    “Pure functions” are functions that always return the same result when passed the same arguments, as opposed to depending on state that can change with time. This makes them much easier to understand, debug and test. They have no side effects such as changing global state or performing any kind of I/O, including file I/O and database updates. State is maintained in the values of function parameters saved on the stack (often placed there by recursive calls) rather than in global variables saved on the heap. This allows functions to be executed repeatedly without affecting global state (an important characteristic to consider when transactions are discussed later). It also opens the door for smart compilers to improve performance by automatically reordering and parallelizing code, although the latter is not yet common.

    In practice, applications need to have some side effects. Simon Peyton-Jones, creator of the functional programming language Haskell, said the following: “In the end, any program must manipulate state. A program that has no side effects whatsoever is a kind of black box. All you can tell is that the box gets hotter.” (http://oscon.blip.tv/file/324976) The key is to limit side effects, clearly identify them, and avoid scattering them throughout the code.

    Languages that support “first-class functions” allow functions to be held in variables, passed to other functions and returned from them. The ability to return a function supports selection of behavior to be executed later. Functions that accept other functions as arguments are called “higher-order functions”. In a sense, their operation is configured by the functions that are passed to them. The functions passed in can be executed any number of times, including not at all.

    Data in functional programming languages is typically immutable. This allows data to be accessed concurrently from multiple threads without locking. There’s no need to lock data that can’t be changed. With multicore processors becoming prevalent, this simplification of programming for concurrency is perhaps the biggest benefit of functional programming.

    If all of this sounds intriguing and you’re ready to try functional programming, be prepared for a sizable learning curve. Many claim that functional programming isn’t more difficult than object-oriented programming, it’s just different. Taking the time to learn this style of programming is a worthwhile investment in order to obtain the benefits described above.

    Popular functional programming languages include Clojure, Erlang, F#, Haskell, Lisp, ML, OCaml, Scheme and Scala. Of these, only Clojure, Scala and Kawa Scheme run on the Java Virtual Machine (JVM).

    As for what is a functional programming language, it does go back to the possible definition you gave: “if you choose “functional programming language” to simply mean “supports functional programming.””

    I happen to be one those not made uncomfortable by that definition 8)

    I do agree that staying out of language wars is a good thing. I think we can all choose to use the languages we like for different situations. It’s fine be enthusiastic about the ones we likes, as long as we don’t bash other languages or try to shove our choices down the throats of others. I find it a bit upsetting or sad when I read stuff like “Language X users are mindless drones.” These broad generalizations are tiresome. But I digress 8)

    Of course, I do like debating calmly the pros and cons of a language.

  14. Julian Morrison

    FP means referential transparency. No pure FP languages exist; they’d be useless because they could only interact by returning. FP subsets of languages exist. A language with a dominant FP subset is usually informally called a functional language. Data immutability is only a corollary of referential transparency; functions that must refer to externally mutable data can’t be transparent, and a language lacking a syntax for enforced immutable data can never be reliably transparent (eg: C, Ruby, Scheme). Higher-order functions are not needed for FP, but they substantially add to its usefulness. Lisp homoiconic structure is orthogonal to FP. Threading is not FP (time sensitivity in results) but immutable data makes it easier by limiting the parts of the program that aren’t FP.

  15. Brian Hurt

    I’d go farther: functional programming is programming in the lambda calculus- generally with some syntactic sugar and optimizations (you can implement integers in the lambda calculus, but they aren’t very efficient), but you’re not that far removed from the lambda calculus. So this leads to various sorts of standard “features”, like functions as first class objects, currying, and immutability. A functional programming language is then one whose primary or main way of programming is in the functional style (you can program procedurally in Java, I comment). Note that it’s not that other forms of programming aren’t allowed, even required, for some tasks (like IO), but again, this isn’t different for OO languages (consider Java.Math).

    Now, let’s put the shoe on the other foot for a moment. I contend that C is an OO programming language. Oh, sure, doing OO in C is a little bit clunky and a little bit error prone, but really, you don’t need to use weird languages like Java, Python, or Ruby to do OO. For those rare instances when you need to do OO. You can start your rebuttle to this statement with a clear and concise definition of what is an “Object Oriented Language”.

  16. david Post author

    I could. But I’m not going to. As I said up front, I’m not interested in language wars. I’m interested in not letting people perpetrate bad arguments.

  17. david Post author

    Actually, I *will* add a follow up comment as to why I’m not willing to take up your challenge.

    The point I am arguing is that Robert’s statement “Scala is not a functional programming language” is not well defined, because “functional programming language” is not well defined. I am not arguing that Scala *is* a functional programming language. I’m not even sure the term has a useful interpretation. The statement “C is not an object oriented language” is similarly ill defined, and as such is probably hard to have a useful discussion about.

    Robert’s implicit point, which is not at all what he wrote, is that functional programming in Scala is more painful than it needs to be. I don’t entirely disagree with that. However had that been what he actually written, I wouldn’t have bothered getting involved. Similarly, if someone wants to argue that object orientation in C is fun and easy, they’re welcome to. But I’m going to look at them funny and then go play elsewhere. :-)

  18. Pingback: links for 2009-05-18 « pabloidz

  19. Pingback: David R. MacIver » Blog Archive » Axioms, definitions and agreement

  20. Conal Elliott

    Hi David. I love this post. Thanks very much for bringing light to some commonly practiced forms of lousy argumentation. And I like your refinement of using necessary conditions, in Axioms, definitions and agreement.

    More effort in clarifying what people mean by terms like “functional” may spare all of us the common sort of argument in which vague language tricks people into thinking they’re disagreeing (or agreeing) when really they’re talking about different things.

    I wonder whether there is any basis (axiom) that people can agree on in these discussions of “Is X is a functional language?” Personally, I’m doubtful. I don’t subscribe to your particular claim of a necessary condition for functional programming, “A functional language must have a notion of function”. For me “functional” is an unfortunate misnomer. I take functional to mean that expressing/denoting immutable values. (Some of those values may be functions.) So I prefer the term “value-oriented” as a clearer replacement for “functional”. And a corresponding “pure” notion means one can only express/denote immutable values.

    However, rather than “value-oriented”, I greatly prefer Peter Landin’s recommended replacement “denotative”, which I understand in a much more precise way than “functional”. See the Landin quotes and ref and some comments at Is Haskell a purely functional language?. Landin’s notion of denotative sheds light for me on not only “impure” languages like C, Scala, and ML, but equally on Haskell’s (technically) “functional” IO. I teasingly poked at the latter in The C language is purely functional.

    Here’s a quote you might appreciate:

    The slovenliness of our language makes it easier for us to have foolish thoughts. The point is that the process is reversible.

    From George Orwell’s Politics and the English Language

    1. david Post author

      Hi Conal,

      I suspect you may be right that it’s very hard to come to an agreement as to a common meaning for this term. It’s much like the clasic “strongly typed” vs. “weakly typed” distinction which was so well taken apart in what to know before debating type systems. Perhaps I should put “This is a functional programming language” as a statement into The Right Tool and see what people come up with :-)

      I think the question of whether functions are necessary for functional programming is probably at the heart of why there’s so much disagreement on the subject: “functional programming” covers several different and nearly orthogonal concepts. For example, the notions of value oriented programming and programming with higher order functions are, while mutually supporting, not intrinsically connected (value oriented programming without higher order functions is a massive pain but certainly doable. higher order functions without value oriented programming are still pretty useful).

      I’m never entirely sure how important these issues really are. A rose by any other name, etc. But Orwell’s point about language is well taken, and the amount of woolly thinking that gets exposed in these arguments does tend to suggest that this is something we need to worry about.

      Maybe we should mandate that all discussions about programming languages occur in lojban. If nothing else that would cut down the volume. :-)

  21. angel

    for me functional lang is where the function are first class citizen and the language is focused in functions over other structures…scala is a great language, but it’s not a great functional language…I feel annoying compared to ocaml or even f#…oop is a perpendicular approach respect to functional ideas…..

  22. Pingback: Best of drmaciver.com | David R. MacIver

Comments are closed.