the blog for developers

No future for functional programming in 2008 – Scala, F# and Nu

On Lambda the ultimte there is a recent post with a language prediction for 2008, which mainly predicts the rise of functional programming and the rise of Scala in particular: “My prediction is a little bit more conservative, but I predict Scala will gain momentum, and at least one high visibility project will use Scala”. Brandon chimes in with “The most important thing to emerge from the discussion is the larger role functional programming will play. It seems like a safe bet.” A safe bet, really? I more sceptical, as written in my post about Qi4j and Scala.

The blogosphere is full of functional programming language advocates and the coming rise of functional programming in application development. But has anything changed since Lisp was invented in 1958? Functional programming languages have existed for more than 50 years now, and didn’t make any inroads into application development. What happend to the acclaimed golden age of functional programing, about which Peter Christensen writes? Will it come back? I dispute in a comment to that post that there ever was a golden age of functional programming, it was a fringe language from the beginning. There was a golden age of Fortran.

John McCarthy – no not THAT McCarthy – invented Lisp back in 1958. From there functional programming gained much appeal to programmers because of it’s clean and consistent style. Everything in Lisp is a list. Even the program itself. Because good programmers have a feel for aesthetics in programming style, they have a warm feeling for Lisp. Functional programming is also a powerful tool for software development. And developers like power. As Paul Graham writes in “Revenge of the Nerds” about power in languages with the aim to praise Lisp:

As an illustration of what I mean about the relative power of programming languages, consider the following problem. We want to write a function that generates accumulators– a function that takes a number n, and returns a function that takes another number i and returns n incremented by i.

He cites an example in Lisp, that implements an accumulator in a nice and pure way:

(defun foo (n) (lambda (i) (incf n i)))

Functional languages excel at mathematical and list processing problems. Most problems to solve in the enterprise are of a different type though. When moving to real problems then, functional programming languages get ugly as an ugly duck. With no swan in sight. Looking at examples from Implementing a blog in Common Lisp: Part 1, we see how ugly it can get. In Java land people a frustrated about XML, but see the brace chaos in Lisp, just to open a database:

; Open the store where our data is stored
(defvar *elephant-store*
    (open-store '(:clsql (:sqlite3 "/tmp/blog.db"))))

And defining a blog domain object doesn’t look very readable either:

(defclass blog-post ()
  ((title :initarg :title
          :accessor title)
   (body :initarg :body
         :accessor body)
   (timestamp :initarg :timestamp
              :accessor timestamp
              :initform (get-universal-time)))
  (:metaclass persistent-metaclass))

compared to a Groovy example:

@Entity
class BlogPost {
  String title
  String body
  TimeStamp timeStamp = now
}

or a Java one in Qi4j:

public class BlogPost {
   Property<String> title;
   Property<String> body;
   Property<TimeStamp> timeStamp = now();
}

Another example from nu, the rising functional star for Macos X. This time with the famous Currency converter example which creates a window:

(set @window ((NSWindow alloc)
               initWithContentRect:'(125 513 383 175)
               styleMask:(+ NSTitledWindowMask NSClosableWindowMask NSMiniaturizableWindowMask)
               backing:NSBackingStoreBuffered
               defer:0))
(@window setTitle:"Currency Converter")

With an equivalent example in Groovy to build a Swing UI:

def frame =
  swing.frame(title:'Frame', size:[300,300]) {
    borderLayout()
    textlabel = label(text:"Clicked ${count} time(s).",
                      constraints: BorderLayout.NORTH)
    button(text:'Click Me',
              actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."; println "clicked"},
              constraints:BorderLayout.SOUTH)
}

Mostly equivalent with the Groovy example which is still slightly easier to read and understand, even by someone who doesn’t know Groovy. Mainly because Groovy is more expressive and not everything has to be pressed into a list (though the nu example contains more than lists as nu aims for object orientation).

In a discussion about Arc, a functional language, stevecooperorg writes about Lisp and the use of Emacs/Slime:

I’d like to write the next Viaweb, and I’d like to write it in Lisp. But if the basic language is inviting, the rest of the environment is sorta hostile; a shangri-la in a swamp.

That’s another problem of most fringe languages. People – the enterprise? – need to know too much beside the language. Using a fringe editor which most people abandoned in the 80s and “a decent knowledge of system administration” is too high a barrier.

Power is a good thing it seems. From my experience most developers can’t handle power. They misuse it. If your development team is less than 5 developers the chance is high that all of them are alpha developers. And your interviewing process was rigorous of course. Above ten and the chances are high that there won’t be only alpha coders. Power is a dangerous feature of a language then.

Do powerful languages scale? Do dynamical type reference languages, which most functional languages are, scale? Scaling in time and organisation? Does it scale from 6 months to 10 years and does it scale from 2 people to 50? I have my doubts for years and still ask anyone to show me how those languages scale. I really want to know. Others too. Manageability writes about Python and Chandler:

What I find interesting is that Chandler started as a Python project with bold claims such as “Python programs are both concise and readable, this makes it excellent for rapid development by a distributed team” and “Chandler design goals: … design a platform that supports an extensible modular architecture”. I was hoping to see this project as a testament to Python’s viability to large scale development.

The jury is still out, but I wouldn’t bet on scalability. As a project manager during the 90s two of my projects didn’t scale and had to be rewritten, one in Python and one in Perl. But it could just be me.

What happend to Haskell and Erlang, the functional hypes of 2006 and 2007? The Blogosphere has mainly lost interest in those lately. Scala and F# seem to be en vogue in our days. Arc perhaps is next in line to be en vogue. Certainly after Scala, which is next the next thing after Java as Bruce Eckel claims. What has changed from the days of Lisp 50 years ago I asked. Scala and F# are different from Haskell, Erlang – and Lisp. They build on an a proven plattform, on libraries that people know. Scala mostly on the JDK and Java ecosphere, F# on the Microsoft universe and .NET. They both are the most promising functional candidates when it gets to momentum. The transit for C# and Java developers seems to be easiest compared to other languages. Will that be enough for them breaking through into the mainstream?

Will the release of Arc, written as a pet project by Paul Graham the greatest functional rock star, help with functional programming? No, certainly not. Arc lost it’s appeal even before it was released. While waiting for the Arc blessing, people moved on to Scala, Erlang or F#.

Don’t kid yourself. There will be no rise for application and especially enterprise development in functional programming (See what happens when you use a Perl script to do your billing, not that I haven’t screwed up in the past with Java ;-) Which doesn’t mean to stop using functional programming languages. It’s fun, keep going.

Thanks for listening.

You can leave a Reply here. Of course, you should follow me on twitter here.

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

About the author: Stephan Schmidt has more than 15 years of internet technology experience and 10 years experience in agile. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own.
Leave a reply.

Comments

Hi Stephan!

I stumpled upon your blog recently. How small the world is. I’m working as a .NET developer freelancer these days, so I’m not that much into Java , but I share your interest in architecture, dynamic languages etc.
So, I think you’re right that pure functional languages are not particularly suited for real world issues. But do you realize that the new version of C# (and even VB, ugh) has a full blown Haskell machinery built in called LINQ?
So, at least some functional language concepts have definitely made it into the (.NET) mainstream already.
One of the benefits of functional languages (or functional constructs) is that sideeffects are under control. IMO that’s becoming important because it allows to scale execution to multicore easily.
Erlang seems to gain some popularity recently because of its additional support for concurrency. Some people even think it will be the next Ruby (http://www.pragprog.com/titles/jaerlang).

cheers
Florian

I stopped reading at the Lisp example that focussed on parentheses. You don’t know Lisp if you still notice parentheses.

Justin Henzie

Interesting points, its true that every man and his dog seems to have jumped on the functional programming language bandwagon, but something has changed since LISP; Even with the advent of STM, it is going to be incredibly difficult for most imperative programmers to effectively leverage the multi-core architectures of today and many-core architectures of tomorrow.

While functional programming languages can appear terse and confusing, it pales in comparison with the machinations necessary to make Java / C# / Obj-C and C scale effectively.

I admire functional languages because they appeal to me from a logical and aesthetic perspective. I use an imperative programming language because I need a paycheck, if the many-core revolution becomes a reality, perhaps I wont need that paycheck.

stephan

No, you’ve missed the point of the post. It’s not about me, but language usability in the enterprise. Which involves more than the power of a language, e.g. programmer capabilities. I did quite some Lisp many years ago.

stephan

@Florian: Indeed the world is a small one! I’m really still amazed how you wrote games in machine code on the Z80 without an assembler. I often tell the story to others as an act of heroism.

“So, at least some functional language concepts have definitely made it into the (.NET) mainstream already.”

Yes, but I’m not sure if you could call C# a functional language. Or is it a OO, C-Type language with functional elements. So most of the application is written OO style by people using OO features, with some alpha coders using the functional elements. Groovy has lots of functional elements too, as has Scala, but people do use mainly OO elements.

“IMO that’s becoming important because it allows to scale execution to multicore easily.”

1. I don’t believe so
2. I’m sure Actor models can be added to Java too (Have a base class with an input queue where method calls are dispatched. Erland concurrency has nothing to do with functional programming, neither has the Scala feature.)
3. I can write functional style in Java just fine. Because scalability is not about functions but statelessness. Stateless methods and classes scale. And functions scale because they are stateless, not because they are functions.

“Erlang seems to gain some popularity recently because of its additional support for concurrency.”

See above, concurrancy has nothing to do with functions. The actor model can be implemented on top of methods. I guess I have to write an actor model for Java to show this once and for all ;-)

stephan

@Justin: This is a myth.

“Even with the advent of STM, it is going to be incredibly difficult for most imperative programmers to effectively leverage the multi-core architectures of today and many-core architectures of tomorrow.”

As replied to Florian, Java can scale with Actors too, this has nothing to do with Erlang.

And people would scale in Java with Map/Reduce and Fork/Join ( http://www.infoq.com/news/2007/07/concurrency-java-se-7 ) which are on an higher, and more productive, abstraction level than Erlang actors.

Fork/Join from Doug Lea scales much better than the Erlang model for problems which can be expressed as Fork/Join problems (e.g. because of threads stealing tasks if they don’t have enough to do).

@Florian: “What happend to Haskell and Erlang, the functional hypes of 2006 and 2007? The Blogosphere has mainly lost interest in those lately.” I know about Erlang, the Armstrong book is here beside me.

Stephan, I have to agree with your basic tenets. Functional programming has been around for over 50 years, and it’s always been “the coming thing”. Like you said, nothing has really changed.

The thing is, imperative programming works. Virtually every program ever written that actually does something valuable (valuable for anyone other than computer nerds, that is) has been written in an imperative language.

After half a century, functional programming still cannot demonstrate any real practical improvement over imperative programming. Theoretical improvement, yes. Practical, no.

The FP proponents go on and on about “ability to reason about programs” as if anyone would actually reason about a non-trivial program. If people really cared, they’d already be using Design by Contract, which not only helps people to reason about their programs but has clear practical benefits as well. Although DbC has been around for over 20 years it has been roundly ignored by both developers and language designers. Nobody wants to reason about actual applications.

I especially like your point on scalability: what happens when the team size scales up, and the team starts to include those who aren’t programming rockstars. Bulls-eye.

stephan

God point, I’ve been thinking about why DbC didn’t make it for some years too. I was a DbC proponent for some time, I was waiting for a good DbC implementation for Java when it was the next big thing. But in the end, it didn’t pay off to use it for application development. Because Eifel didn’t take off, Betrand is still angry at Java I guess.

Michael

Dear Stephan,

You say: “FP languages have existed for more than 50 years now, and didn’t make any inroads into application development”. I can give you more thrilling example: classical and folk music both exist for centuries, and still didn’t make any inroads into MTV charts. And never will. Does it mean they have no future?

stephan

@Michael: Well, nobody claims that folk music will be the next big thing. Contrary to FP languages which a lot of people claim will be the next big thing. “Does it mean they have no future? ” Classical straw man.

“The most important thing to emerge from the discussion is the larger role functional programming will play. It seems like a safe bet.” A safe bet, really? I more sceptical, as written in my post about Qi4j and Scala.

I think you misinterpret the quote: Brandon is not saying that a functional language will sweep the enterprise, just that functional programming will play a role. This has already happened in 2006/2007 (MapReduce?), I don’t see why it would stop in 2008. Maybe we’ll even get closures in java.

Neither of these examples are functional languages, but they both are functional constructs. As Florian points out, functional programming is about controlling state: MapReduce is useless if your mapping function depends on side effects. Parallelism in general is all about eliminating side-effects. I don’t doubt an Actor framework can be (has been?) written in Java, but how does it deal with mutability? Erlang prevents reassignment.

OOP didn’t replace imperative programming, and I doubt FP will either. But it will probably have an effect.

PS: you can add lots of things to lots of languages, but will they blend in seamlessly? That seems to be the thing that Lispers (which I’m not) think is cool. It might be interestng to take a look at their Erlang emulator: Termite on Scheme.

Michael

Ok, so we see that more appropriate questions are “Why so many people still blindly claim that FP is the next big thing?” and “If not FP, what will be the NBT?”. The first is a good point for the next blog article and figuring out the answer to the second can make you a millionaire ;)

stephan

The first might be a new blog article, the second one: There is no NBT. I wrote an article that Java fits the backend enterprise niche perfectly . So there needs to be a big shift in the industry to a new way to develop and deploy applications. Then there will be an NBT. But Java won’t have a successor in it’s niche I predict.

stephan

@Dave:

“[...] but how does it deal with mutability? Erlang prevents reassignment.”

I don’t know how fluent you are in Java

final val = 3;

should do the trick since Java 1.0. And there is lots of discussion about immutable objects in Java (which I do value a lot).

I hope we do not get closures in Java, they will make Java as magic as Ruby. Which – in the enterprise – is a bad thing. I hope for CICE. 90% of the power, 10% of the weight.

http://crazybob.org/2006/10/java-closure-spectrum.html

If someone shows me a big Lisp/Scala/… application which models a business domain, then I’m really interested.

@Stephan:

IANAJavaExpert, but I do know how to final variables :) What I meant was that how does a Java Actor framework deal with the code a user passes to your framework? If it is to help make concurrency easier, you can’t expect the callers code to show up threadsafe. I ask because I’m genuinely curious.

Similarly, MapReduce is only useful if the mapping function is side-effect free. Otherwise when you parallelize you’re going to have tons of race conditions.

I’m not saying a language that enforces immutability is necessary–I mean, I mainly use Python, there’s not a whole lot it does enforce. But I am saying that thinking in terms of immutable functions that are combined by map, reduce, etc. let’s you program in a way that allows for more parallelism.

In typing this I realize I basically just restated something Joel said in 2006.

jimbokun

You notably leave out the most popular functional programming language of all.

Javascript.

Very much a functional language, and probably more popular than Java.

Also, you seem to be implying that failing in the enterprise means that functional languages have failed, period. Of course, if you go to news.ycombinator.com you will find that, in their view, if you are writing “enterprise” software you have already failed, period. If you were any good, you would have a startup. So failing as an “enterprise” language certainly does not mean failing as a language.

Another thing:

“Functional languages excel at mathematical and list processing problems.”

Viaweb was not in any way a mathematical or a list processing problem. Javascript does not primarily excel at mathematical and list processing problems.

“Everything in Lisp is a list.”

This is not even remotely close to being an approximation of the truth.

“As a project manager during the 90s two of my projects didn’t scale and had to be rewritten, one in Python and one in Perl. But it could just be me.”

Reddit is written in Python. Was your project “bigger” than that (for some definition of “bigger)? If not, might just be you.

stephan

@jimbokun:

“Also, you seem to be implying that failing in the enterprise means that functional languages have failed, period.”

No.

“[...], if you are writing “enterprise” software you have already failed, period. ”

Yes, I know. Well, the small company I work for makes 75M $ a year on a Java platform. But I know how Grahams followers define failed. Period.

“Viaweb was not in any way a mathematical or a list processing problem.”

Viaweb was an application – as far as I know – which had to be rewritten to be maintainable (enterprise developers, see my comments about alpha coders) and lastly failed as an application against Amazon and Ebay. So, for everyone, except PG, Viaweb failed. The “success” of Viaweb depends more on the stupidity of Yahoo and the first mover advantage than on being written in Lisp.

“This is not even remotely close to being an approximation of the truth.”

It is.

“Reddit is written in Python.”

Reddit is big? I thought it was an app that lists urls with comments. Something my students could write on a weekend. So yes, the apps were a lot bigger than that.

Funny that you mention Reddit, a site which was rewritten from Lisp because Lisp failed as an application language.

http://www.aaronsw.com/weblog/rewritingreddit

stephan

@Dave: Yes I can see a possible big future for JS, on the server replacing other dynamic type reference languages.

http://stephan.reposita.org/archives/2007/07/23/comparing-helma-and-grails/

[...] No future for functional in 2008 The blogosphere is full of functional programming language advocates and the coming rise of functional programming in application development. But has anything changed since Lisp was invented in 1958? [...]

Stephan, why did you not show how the BlogPost class looks like in Scala? Was it because it
is shorter and more elegant than Groovy and Qi4j? You see, your arguments against functional
languages don’t work against Scala, since it is a functional AND object oriented language. There
is hardly anything you can do in Groovy that you can’t do in Scala.

Also, your claim that multi-core programming can be done better with Java’s fork/join is just
not true! Is that how plain vanilla programmers are going to whip 32 cores into their willing?
No, the only way that many cores can be forced into massive work is if the VM itself can do it
for us. That is where Scala’s immutable objects and Actors comes into play. Doing this in Java?
You can’t be serious?

amontymouse

Yeah it’s almost always the same with these functional programming types.
What really gets me aside from their superior and one-size-fits-all attitudes (if you don’t like it it’s because you don’t understand it) is the shear conradicted-by-real-life nature of their claims.

If purity of functional programming really cut it (in terms of cost/speed/quality of development), then by now a large portion of industrical projects would be written in, for example, common lisp. These projects would be massively out-competing their million line legacy imperative code projects, with their relatively bug free nature and much improved time to market with new features.

Nope… instead all we get is the “Paul Graham told us how wonderful his shop application that he managed to sell to Yahoo at the height of the dot-com boom, this proves how great it is in real life”. Er, no it doesn’t really does it ? Only academics get sucked in by such anecdotal evidence and appeals to vanity (again, if you don’t like it it’s because you don’t understand it), which not coincidentally is where you find many of the proponents. If functional programming was so great he’d be repeating the trick many times over, producing applications of astonishing quality and rapid feature growth. It just doesn’t happen though.

“Using a fringe editor which most people abandoned in the 80s”

I use emacs (mostly Ruby on Rails and JavaScript) and didn’t start working with it until 2001.

And I don’t write any lisp at all

I don’t think my experience is unique, either.

So, what did you code with in the 90’s? Visual Studio? Homesite? Textpad? BBEdit?

meek

http://whydoeseverythingsuck.com/2008/01/mitch-kapors-weekend-at-bernies.html

Citing one application as a representation of the failure of a language is pretty weak. What if I pointed to 20 examples of applications written in dynamic languages that have been successful, will you be convinced?

@stephan:
> If someone shows me a big Lisp/Scala/… application
> which models a business domain, then I’m really
> interested.

Here is a job opening for a huge airplane reservation system written in Lisp:

http://www.itasoftware.com/careers/jlisting.html?jid=37

For my taste you are mixing a bit too many things in one blog posting, I just want to comment on the Scala part:

- Scala is both functional and object-oriented.
- Scala can be easily integrated with an existing Java codebase by replacing one library at a time.
- Scala is statically typed (absolutely required for big projects, in my opinion)
- Scala is portable to every place that Java goes.
- Scala can be easily extended (as is common for functional languages).
- Scala provides multiple advanced concepts for concurrency.

You can of course write message passing with Java. If you want to pass state that you hold in regular objects, you will have a hard time doing so without the cost for synchronized/lock thread context switching to make sure you read what you write. Possibly you could convert the “data” part of your objects to data holder classes that use AtomicReference/AtomicInteger and maybe you can even automate the conversion part using bytecode generation.

Hey, but if you are smart enough to do that, why not just take Scala for message passing and invest your precious time for a problem that the world has not solved yet?

In my opinion Scala is not hyped because it’s the latest trend. It’s hyped because it’s good.

Nick

I think you complaining that Lisp is too hard because it has all those parens instead of a typical C-like syntax is like a native English speaker complaining that the Korean language is too hard because it has all those funny symbols instead of a typical Latin-style alphabet. Sure its hard to read if you are new to it, but that doesn’t mean its fundamentally hard to read. It just means it is different from what you are used to.

And how is Michael’s classical music example a straw man? You claimed in the very title of this blog entry that you don’t think functional programming has a future in 2008, not just that its not going to be the “Next Big Thing” (whatever that is supposed to mean). If anything, your argument is the strawman, as most advocates of functional languages (including the ones you cite) are not arguing that fp will take over the world but instead just gain momentum. You are picking out an extreme version of that argument and using evidence for it as evidence against the more conservative argument, that functional programming will gain momentum and play a larger role in software development. Thats actually a pretty good example of a strawman argument.

stephan

@Mats: I didn’t use Scala because the blog definition in Scala would look much different from the one in Groovy and is mainly about the OO Scala features, not the functional Scala features. So I don’t think Scala helps in this argument for functional languages if you cite it’s OO features.

“[..] just not true! Is that how plain vanilla programmers are going to whip 32 cores into their willing”

I guess it is, because fork/join does task stealing, therefore has a much better core usage than naive algorithms.

“Doing this in Java? You can’t be serious?”

I’m serious, Actors can be developed in Java in much the same way they are implemented in Scala. You don’t
need functions for implementing Actors.

@Joe: “So, what did you code with in the 90’s? Visual Studio? Homesite? Textpad? BBEdit?”

Several editors on the Amiga, e.g. Cygnus Editor, Vim on most other platforms.
A lot of my professional work during the 90s was done in Delphi.

@Carl: I’ll take a look, thanks.

“You can of course write message passing with Java. If you want to pass state that you hold in regular objects, [...]”

Not sure what does prevent you from using immutable objects in Java.

“Hey, but if you are smart enough to do that, why not just take Scala for message passing and invest your precious time for a problem that the world has not solved yet?”

Because I feel that Scala is a ghetto – sorry for that ;-) and I would be much more comfortable when I could easily use Scala from Java.
Otherwise the problems with enterprise developers remains with Scala.

@Nick: “And how is Michael’s classical music example a straw man? You claimed in the very title of this blog entry that you don’t think functional programming has a future in 2008, not just that its not going to be the “Next Big Thing” (whatever that is supposed to mean).”

And the first paragraph was explaining what I meant with future. Mainly the discussion on LtU about the breakthrough of functional languages in 2008 – as I also wrote in the title.

“[...] world but instead just gain momentum.”

That’s the point of the first paragraph, there will be no momentum. The arguments for that claim are in the blog post.

Nick

But the guys on LtU that you cite are not claiming that FP languages are going to replace Java and C# as the most popular enterprise level language. Their claims are more moderate, that FP will have a larger role in the upcoming year than they have had in past years. And they have reasons to back that up, such as the emerging importance of concurrency and SOA, both of which FP handles pretty well. Furthermore you do see a growing awareness of FP among developers, and awareness often precipitates influence. There certainly are arguments out there that support the idea that FP will grow in its importance, and your arguments don’t address any of them. Instead you go on about its history, how it is an old paradigm and how it hasn’t been that big in the last half century, and whine about the syntax of a few languages often associated with functional programming (which really doesn’t do a damn thing to support your claim that the paradigm has no future). But something doesn’t have to be new or currently hot in order to have a future. Just as the classical music example shows.

stephan

@Nick:

“Their claims are more moderate, that FP will have a larger role in the upcoming year than they have had in past years. ”

I wrote “On Lambda the ultimate there is a recent post with a language prediction for 2008, which mainly predicts the rise of functional programming and the rise of Scala in particular”. If you go back to the post, I wrote that I don’t believe in the rise. Perhaps Scala, F#, Erlang and the others have peaked already. Read the post.

“And they have reasons to back that up, such as the emerging importance of concurrency and SOA, both of which FP handles pretty well.”

I’ve discussed the myth with concurrency in the comments above.

SOA is a pretty good argument for FP. What I see in SOA discussions are two things. There really isn’t that much SOA going on. SOA can be easily developed with functional (or better procedural, no need for higher order functions or passing functions around) facades for the service and OO backend implementations. Beside that, I do not see much usage of functional languages in SOA projects. Perhaps the LtU or YCombinator or usenet Lisp communities have a deeper insight into such projects though.

stephan, this is what you wrote:

“Functional languages excel at mathematical and list processing problems. Most problems to solve in the enterprise are of a different type though. When moving to real problems then, functional programming languages get ugly as an ugly duck. With no swan in sight.”

You then went on and showed how ugly Lisp is, and how nice Groovy is. So, how valid is that claim (“no swan in sight”) when the BlogPost class is very elegant in the FUNCTIONAL language Scala?

Why can’t you be honest and admit that Scala might be the swan?

stephan

“You then went on and showed how ugly Lisp is, and how nice Groovy is. So, how valid is that claim (”no swan in sight”) when the BlogPost class is very elegant in the FUNCTIONAL language Scala?”

So you want to prove the beauty of functional languages with the OO syntax of Scala? You’ve lost me I guess.

stephan
class BlogPost(title: String, body: String) {
   def title() = title
   def body() = body
   def timeStamp() = now
}

We can discuss if the Scala or the Groovy version is nicer. Nevertheless, most of the Scala syntax is it’s OO syntax, not it’s functional features.

For me OO is the collection of methods and state into one structure with a name.
For me functional programming is using functions without state that can take arguments and return values which are functions themselves.

“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 with the imperative programming style that emphasizes changes in state.” -Wikipedia

So in which way does the Scala class above show Scala as a beautiful functional language?

manning

“The most important thing to emerge from the discussion is the larger role functional programming will play. ” A safe bet, really?

Larger. That means bigger in 2008 than it was in 2007. That is a fairly, IMHO extremely, conservative. If any functional language anywhere gains one additional user, if any one concept from functional programming gains even an ounce of mindshare, then it is larger. Is that a safe bet? Sure it is. Look at the trends of computing for the past few years and extrapolate that to the next one. I’d take anyone up on that bet.

stephan

@Manning: Then perhaps we define “playing a bigger role” in a different way. Perhaps more people in 2008 are interested in FPs. (though I have the feeling that interest in Haskell and Erlang declined recently again). Do they play a bigger role though meaning more projects? Just gaining a larger mindset isn’t enough to play a bigger role. Some bloggers toying with Scala? With – as mentioned above – the mostly OO features of Scala?

But we’ll see in one year from now, how much they have gained momentum.

Robert Virding

“Don’t kid yourself. There will be no rise for application and especially enterprise development in functional programming (See what happens when you use a Perl script to do your billing, not that I haven’t screwed up in the past with Java ;-)”

I *LOVE* your grouping Perl in with the functional languages. Perl is many things, to many people, but functional is not one of them. Ifvthis is an indication of the level of your comprehension of what functional languages are then it doesn’t say much for the rest of your arguments.

stephan

@Manning: Don’t you think that Erlang, Haskell and Scala have peaked in 2007? I’m sure for Erlang and Haskell, as I wrote in the post. There seems to be some interest in Scala, but as long as I can’t use Scala in an easy way from Java, there will be no uptake. All people who wanted to depart with Java went for Rails/Ruby or Grails/Groovy. Others moved to Haskell and Erlang before, those won’t increase the FP uptake. Where shouuld the enterprise development uptake 2008 come from?

AND whatever people say, Scala in the end is no functional language. It’s an OO language with functions (e.g. see

http://www.scala-lang.org/docu/files/api/scala/Function1.html

and “Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. It is also fully interoperable with Java.”

@Robert: Cute, isn’t it. Glad you lioke it. Where did I write I consider Perl a functional language? Perhaps there are other traits in Perl that make it similaer to most FP languages? Did you consider that before you jumped to your conclusion?

Nick

“If you go back to the post, I wrote that I don’t believe in the rise. Perhaps Scala, F#, Erlang and the others have peaked already. Read the post.”

The problem isn’t that I don’t believe that you don’t believe in the rise. The problem is nothing you write supports that claim, and is easily refuted by the classical music example that you erroneously labeled a strawman.

And nothing you write even comes close to supporting the stronger claim in your title, that functional programming “has no future”. And of course we all know you didn’t just pick a controversial title for the sake of pissing people off as that would make you a troll.

“I’ve discussed the myth with concurrency in the comments above.”

Again, the fact that you didn’t even address it in the post shows you are not that familiar with the issue. And no, the fact that you can imitate some functional programming concepts in an object oriented language does not make the fact that functional programming is good at concurrency a myth. In fact, all it does is strengthen that claim. Programming without state or side effects comes naturally in functional programming, while in OO it feels very hacked.

stephan

@Nick: “The problem isn’t that I don’t believe that you don’t believe in the rise. The problem is nothing you write supports that claim, and is easily refuted by the classical music example that you erroneously labeled a strawman.”

No, the problem is, that the original post on LtU is just wishful thinking with nothing that supports it’s claim.

And if you read the post, there are several reasons why FP will not make it into the enterprise or application development in 2008 (readability, alpha coders, not able to do traditional domain modelling et.c)

“Again, the fact that you didn’t even address it in the post shows you are not that familiar with the issue. And no, the fact that you can imitate some functional programming concepts in an object oriented language does not make the fact that functional programming is good at concurrency a myth.”

I didn’t write, if you read my comments, that FP concurrency is bad, but the myth that it’s somehow inherently better than concurrency in OO languages. Which it just isn’t.

“[...] that functional programming “has no future”.

Reading the title and ignoring the post. FP has no significant past, no present and there will be no uptake in 2008 like the LtU post claims. So there is no future for FP. I’m standing to my opinion.

You get 25 USD per PayPal if Lisp,Scheme,Haskell,Scala,Erlang,OCaml rises to the Top 10 of the TIOBE index in 2008, rises above 1% or a major project (Rails dimension) is written in one of the languages, as does Mats.

The phrase “functional language” means at least two things. The first is a pure language with no side effects or very tightly controlled side effects. Haskell is the most well known but there are several used by the research community. But, importantly, by this definition none of the well known Lisp variants qualify – certainly neither Scheme nor CL qualify. Scala and F# don’t either.

The other definition is that a functional language is one where functions can be used as values. Lisps certainly qualify, but so do a large number of pretty popular languages: Javascript, Python, Ruby, C# (more in 3.0 than previous), and maybe Java 7. F#, Scala, Groovy, and Erlang also fall under this definition.

“Functional programming” similarly has at least two meanings: programming without side effects vs programming with functions as values.

So I’m left with a strange conclusion. If you include Scala in your definition of “functional language” and functional programming has no future then Javascript has no future. Or, if you mean that Javascript has a future but won’t be used functionally, then why won’t, say, Scala have a future since you can use it without its functional features but still get good benefits: mixin inheritance, higher kinded types, explicit self types, type members, uniform access to properties, type inference, etc.

Anyway, you said that functional programming excels at list processing (and math) but then said that enterprise software doesn’t need that. Show me an enterprise code base that isn’t littered with loops for working with lists (and other collections). Given the metric crapload of boilerplate that goes into list processing in enterprise apps, wouldn’t your argument support at least some use of functional programming in the enterprise? Just maybe a little bit of foreach and map, maybe? Oh, and filter, definitely filter.

stephan

“The other definition is that a functional language is one where functions can be used as values.”

Like in Java:

myObject.doWith(Method method) ?

“Show me an enterprise code base that isn’t littered with loops for working with lists (and other collections). ”

Every code I have seen in the last 15 years of enterprise development. There is very little work with collections. And I didn’t write iterating but processing. If you need list processing in Java, see

http://stephan.reposita.org/archives/2007/10/17/creating-a-fluent-interface-for-google-collections/

> myObject.doWith(Method method) ?

Sure, there’s a way to encode the concepts in Java. As a form of perversity I once encoded the S,K, and I combinators in Java. But if you want to include any arbitrary encoding of one concept from one language into another language you’ve just jumped into the Turing tar pit and have lost the ability to compare languages meaningfully.

>Every code I have seen in the last 15 years of enterprise development. There is very little work with collections.

Yeah, you’re right. Collections are hardly used in the enterprise. Large organizations always have exactly one of every thing. No, wait, I think some organizations have 2 of some things. Maybe some of the really big ones have 3. It’s a good thing they have such a small upper bound. Otherwise they would need collections every time they do a search or show a master/detail view or create a report or do a bulk update/reconciliation or any of that other businessy stuff. Oracle sure bilks a lot of money out of those suckers to manage their very small, non-collection-like data based on the relational algebra – related collections (sets to be specific) of tuples.

>And I didn’t write iterating but processing

I’m flummoxed as to why you want to make a distinction between iterating over lists and processing lists since why would you do the former other than to do the later? Perhaps you like to iterate over lists and do no nothing with the elements? That’s a novel way to make your CPU hot – but wouldn’t it be easier just to put it in the oven?

Hmm, I can’t help but notice that you entirely skipped my point about a bunch of popular languages being functional in the same way that Scala and F# are.

stephan

What I meant with very litte work with collections is that in most applications I worked for, the selection/filtering/mapping is done in the ESB,DB,distributed memory etc. layer. What you don’t do usually, is get all “things” and then select the relevant things in a collection. You usually retrieve only the relevant things in the beginning, because otherwise your application won’t scale.

“Hmm, I can’t help but notice that you entirely skipped my point about a bunch of popular languages being functional in the same way that Scala and F# are.”

I skip points just as I like. And the discussion on how to categorize languages – is JS functional or prototype-oo – will not result in anything satisfying, not for you and not for me. But because you insist:

“The other definition is that a functional language is one where functions can be used as values. Lisps certainly qualify, but so do a large number of pretty popular languages: Javascript, Python, Ruby, C.”

Every language has different language features and no language is pure OO, functional, procedural, logical etc. There was such a big discussion going on about what makes a language OO. Does prototype-OO qualify? Inheritance? Traits? The same goes for functional languages. More important is the usage of the language. I clearly think Haskell and Lisp are used functional (which means the problem and solution space is mostly modelled functional), I’m not sure about JS, Scala is mostly used OO (the problem and solution space is modelled with objects) and so on.

The title said:

“No future for functional programming in 2008 – Scala, F# and Nu”

That’s the main point, functional programming will not make it into the mainstream in 2008.

>What I meant with very litte work with collections is that in most applications I worked
> for, the selection/filtering/mapping is done in the ESB,DB,distributed memory etc.
> layer.

Two points. First, under some circumstances you’ll get better scalability working with lists outside of your “ESB,DB,distributed memory, etc” For instance, it might make sense to manipulate a list inside a web browser or fat client rather than go back over the network every time the user clicks something. And in high transaction processing situations it often makes sense to distribute work load away from centralized systems when reading from DBs (filtering only sometimes, mapping quite often).

Second, nodes hanging off an ESB frequently need to process the objects (which may be collections) that come through the bus. The logic for doing that kind of work can often become too complicated for the DSLs typically used to drive the ESB. If an ESB did have a language sophisticated enough to do any arbitrary form of processing then, by definition, it would be Turing complete and we can once again discuss the utility of it being a functional language.

The same reasoning applies to DBs where SQL/OQL/whatever or are typically (deliberately) limited. For instance, in straight up ANSI SQL there’s no way to turn a set of results into a tree. There are extensions that can do so, but for any extension to SQL I can find something that can’t be done using your newly defined language up until you’ve defined a Turing complete language. And then, once again, I might ask about the utility of making it functional.

> And the discussion on how to categorize languages – is

I just wanted to understand what you mean by “functional programming” since the phrase has several common meanings. I don’t care too much which one you pick as long as it’s semi-reasonable and we can have a common referent. Otherwise we’ll just talk past each other.

> Every language has different language features and no language is pure OO,
> functional, procedural, logical etc.

Here’s an example of where we need to clarify meanings. The word “pure” typically has a very specific meaning when applied to functional and logical languages. By this definition pure languages are those languages where side effects are forbidden – the program as a whole might have side effects but no function or predicate other than the main one may. By that definition, Haskell98 and Mercury are pure. Standard ML and Prolog are not. I’m not aware of any OO languages that meet this definition, but there’s nothing in principle to prevent it.

But in the paragraph above you probably don’t mean the “side effect free” version of the word “pure.” You mean something like “consists solely of.” I might quibble with your statement here a bit by pointing out that, for instance, Smalltalk is nothing but OO and Scala is very nearly so (yes, in Scala, even functions are objects in the OO sense), but it’s a quibble and irrelevant to the heart of our discussion.

> More important is the usage of the language.

I try to avoid definitions based on usage as much as possible because it’s murky water. How often does a language have to be used functionally for it to be functional? Is CL an OO language since many CL projects use CLOS or is it not an OO language since many CL projects don’t – is there even a way to know the percentages with any confidence?

> Scala is mostly used OO (the problem and solution space is modelled with objects)

I think you’re implying a false dichotomy. Like a language must either be OO or functional. In fact, in Scala just about everything is an OO object, even functions. So Scala is “almost entirely used OO” is much more correct than “mostly used OO.” Further, in Scala classes are quite frequently defined functionally for some definition of the word: they’re immutable and have no other side effects, or they have methods that take or return function values, or both. The Scala standard library is written using these concepts throughout. The largest application I know of in Scala, lift, is written based on heavy use of functional concepts – and heavy use of OO concepts. So for most reasonable definitions of the terms, Scala is both OO and functional.

> That’s the main point, functional programming will not make it into the mainstream

By some definitions that’s already false, maybe even by your usage definition. For instance Ruby, Groovy, and Python hackers use filters and maps and eaches with reckless abandon. Javascripters define event handlers using functional values and several popular JS libraries also add things like filter and map and each. I have every confidence that many of C# 3’s functional features (like LINQ) will be quite popular as well.

> No future for functional programming in 2008 – Scala, F# and Nu

And then there’s this: why did you mention Scala, F#, and Nu specifically? The impression given is that those particular languages have no future specifically because of their functional programming aspect.

If you are saying “functional programming has no future in 2008 EVEN IN Scala, F#, and Nu” then that’s a pretty different point. I think it’s false, but at least it’s interesting: you’d be saying that people might use use these powerful languages but will use them for features other than their functional aspects.

Or “Scala, F#, and Nu won’t be mainstream in 2008 because people perceive them as primarily functional and that scares them.” Now this is an interesting thought that may well even be true. If so, then the answer would be for the community to market them as OO languages for doing OO things well and with functional features for doing things that functional stuff is good at. Maybe then functional programming will have a future.

stephan

Thanks for the lengthy post. I’ll consider all your points, although I think we will not understand each other.

Just one little remark

“For instance Ruby, Groovy, and Python hackers use filters and maps and eaches with reckless abandon.”

If I use:

List names = with(persons).filter(“$it.age > 3″).map( “$it.name” )

(which could be written in around 15 minutes, or see Quaere or Qi4J querying)

does that make Java a functional language? Has FP arrived in the mainstream then?

If you declare victory for FP because some people use “each” in JS, then you’re goal was very low. It won’t help to just declare everything which has to do with collection processing as being FP. Well, it’s not. See the example above. Or as you say

“Further, in Scala classes are quite frequently defined functionally for some definition of the word: they’re immutable and have no other side effects, [...]”

If you declare some programming style (which I use most often in Java – with objects – myself) like side effect free methods, immutability or state lessness to make a functional language, then you will spot FP everywhere. But you watered the meaning of FP so much down that it doesn’t mean anything any longer. And your view of what makes a good programming language ends much nearer to mine than to PGs.

> If I use:
> List names = with(persons).filter(”$it.age > 3″).map( “$it.name” )
> does that make Java a functional language?

Nope. Because the semantics of passing functions as arguments are not defined in the Java language. As a language, Java is not functional by any definition of “functional language” that I know of (actually, not quite true, one guy on LtU suggested that a language was functional if it could macro-express the simply typed lambda calculus and I’m pretty sure Java could, like I say I build the S,K, and I combinators that way once. But his definition isn’t widely used).

> Has FP arrived in the mainstream then?

If the mainstream uses techniques like that, then yes, FP has arrived. Not dominated perhaps, but arrived. Anyway, that would seem imply that you can do functional programming in a language that is not functional if you can build the right meta-programming facilities. Interesting, eh? Arguably that’s because meta-programming allows you to extend the language. Specifically, you’ve given language semantics to some strings (“$it.age > 3″). So while Java isn’t a functional language, Java your library are. Now you see why people like meta-programming. Unfortunately, you’ve also lost static typing (you could also write “$it.age > ‘potatoes’”) which is one of the big trade-offs in the never-ending debate over typing vs meta-programming etc etc.

>If you declare victory for FP because some people use “each” in JS, then you’re goal
> was very low.

To be fair, I did say also say map and filter and did say Ruby, Python, and Groovy. But be that as it may there are two ways to see “victory” here. One is that FP is widely used. The other is that it’s the dominant technique. By no means is the later satisfied right now. But maybe, just maybe, it’s reasonable to say its widely used in at least the languages under discussion and since they have some claim on the mainstream mind, it’s not totally unreasonable to say some FP has entered the mainstream. Now, the average mainstream programmer might not know a combinator if it bit him in the ass…I certainly won’t argue that the mainstream really gets functional programming on that level.

> It won’t help to just declare everything which has to do with collection processing as
> being FP. Well, it’s not. See the example above. Or as you say

Of course not. If you use an external iterator and use a bunch of destructive mutations then there’s no definition of FP that I know of that fits. If you use functional values passed to transforming/filtering functions and methods then there are widely used definitions that fit.

> “Further, in Scala classes are quite frequently defined functionally for some
> definition of the word: they’re immutable and have no other side effects, […]”
> If you declare some programming style (which I use most often in Java – with
> objects – myself). But you watered the meaning of FP so much down that it doesn’t
> mean anything any longer.

The terminology is not my invention. See “Purely Functional Data Structures” http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf. I told you right at the beginning that there were at least two definitions of the word “functional.” I’m not watering the word down. It’s been watered down for a long, long time.

> And your view of what makes a good programming language ends
> much nearer to mine than to PGs.

We haven’t talked about what I think is good. So far we’ve just going around in circles trying to pin you down on what you mean by “no future for functional programming 2008 – Scala, F#, Nu.” Anyway, PG has made it very clear what he wants in a programming language: functional abstraction, first class functions, dynamic typing, dynamic meta-programming, impure side-effects, garbage collection, and syntactic abstraction (macros). Scala, F#, and Nu qualify under several of those points but not all. Clearly none of these 3 languages are going to be PG’s first choice – he’s going to pick a Lisp variant like CL, Scheme, or Arc. The three languages you focused on in your title are definitely not Lisps.

Haskell98, which is purely functional, also doesn’t qualify for PG under most of those points. In fact, it qualifies under FEWER of those points than Scala, F#, and Nu. Haskell would likely irritate the hell out of PG. I can only guess, but I suspect he’d rather use Python or Ruby than Haskell. Haskell is definitely not his “Hackers and Painters” ideal.

stephan

“Nope. Because the semantics of passing functions as arguments are not defined in the Java language.”

Yes, because there is no difference in (person.age >3) and “$it.age >3″. They are both functions, the second one in a string representation.

“Java is not functional by any definition of “functional language” that I know of [...]”

Well you have been lowering the criteria for functional languages, not me. And cited several examples for languages being “functional” because they support each or map.

“Specifically, you’ve given language semantics to some strings (”$it.age > 3″).”

Which would mean very strong meta programming abilities in Java? It’s in a library but not the language, when the library is written in that language? Doesn’t make sense to me.

“Unfortunately, you’ve also lost static typing.”

Just like Ruby lost it I guess. Or Tcl. Or isn’t Tcl a real language because it uses strings?

“[...] certainly won’t argue that the mainstream really gets functional programming on that level.”

So there are different levels of FP? If I use each I’m doing FP0, when using higher order functions I’m doing FP1 and when using ycombinators I’m doing FP2? And FP has hit the mainstream when a significant amount of developers will use FP0 techniques? See my last comment, your aiming too low.

“If you use functional values passed to transforming/filtering functions and methods then there are widely used definitions that fit.”

So myCollection.select(ageSelector); is FP with ageSelector being a functional, non-destructive value?

I have the feeling you can’t nail FP and you can’t nail when FP hits the mainstream. You try to falsify my points but use them yourself if it suits you. One certainly can claim writing side effect free and stateless code means writing FP code, but then it’s hard to divide it from most other languages.

(Looking at http://en.wikipedia.org/wiki/Purely_functional (shallow content for shallow minds): Reading that definition it seems clear that Java can be used as a pure functional language which – again – would make it a FP language. Not a very satisfying definition at least to me, because it flies in the face of common developer understanding).

Something completely different. 20 years ago when I was moving memory blocks with code around in machine language, which could themselves deal with other code, move it around and execute it, did I do functional programming?

stephan

And of course before you mention it, “$it.age >3″ is not Java but JUEL and I need a JUEL compiler written in Java to program in JUEL. But then one could argue that I can’t write code in Tcl at all, and Rails is not Ruby but Rails with a compiler written in Ruby. And meta-programming in Lisp will spawn endless new languages, but programming in Lisp is not useful at all (only in the spawned meta-derived languages).

> Yes, because there is no difference in (person.age >3) and “$it.age >3″. They are
> both functions, the second one in a string representation.

Yes, but your question was “is Java a functional language?” The answer is no by the most common definition: the Java language has no semantics for functions as values. If you use metaprogramming to embed a functions as values inside your Java programs then you have defined another language – which is okay by me, just saying that you haven’t updated the Java Language Specification in so doing. Or, let’s put it another way, Java is not a database query language. The JLS says nothing about databases. But you can certainly do database querying with JDBC or some other library and with a bit of metaprogramming you can tie your queries to your objects to create something like Hibernate or whatever. But doing all that doesn’t make Java as defined by Sun et al a database query language. It arguably does make your Java libraries metaprogramming a database query language.

> Well you have been lowering the criteria for functional languages, not me. And cited
> several examples for languages being “functional” because they support each

I have two possible definitions right up front. Both were reasonably crisp (not formalisms, you understand, but reasonably crisp). I’m happy to entertain a third. Just, to be consistent with your article, it needs to cover Haskell, various Lisps, Scala, Nu, and F#. It’s surprisingly hard to do. The only one I could come up with was: functions are values.

> So there are different levels of FP? If I use each I’m doing FP0, when using higher
> order functions I’m doing FP1 and when using ycombinators I’m doing FP2?

Well, okay, if you want that definition. But interestingly, programmers using Scala and Haskell can never reach FP2 because you can’t directly encode the Y combinator in either of them due to explosion of types. You can’t encode it in the simply typed lambda calculus either – stlc isn’t Turing complete. Statically typed functional languages get around this by adding names to allow recursion – and also to be practical :-). I’m not sure about Nu and F#, but probably not possible in them either. You can encode the Y combinator in most Lisps since they’re dynamically typed, just like the untyped lambda calculus.

And”each” IS a higher order function. It takes a function as an argument (sorry, that’s the only definition of higher order function that I know – a function that takes as a parameter or returns a function as a result). So your definitions of FP0 and FP1 are the same thing as far as I can tell.

> And FP has hit the mainstream when a significant amount of developers will use FP0 techniques?

Yup, since FP0 and FP1 are the same, I’d say so. I don’t insist on FP2 because that eliminates most statically typed languages. But of course, we could agree to do so, and then I’d have to agree that the mainstream is definitely not at FP2 and nobody who uses Haskell is practicing FP2.

> See my last comment, your aiming too low.

Not aiming anywhere in particular, just trying to understand what you mean by “No Future for Functional Programming in 2008 – Scala, F# Nu.”

> I have the feeling you can’t nail FP and you can’t nail when FP hits the mainstream.

The former is a challenge in some ways since there are so many definitions. Let’s just come up with a definition that’s reasonably crisp. I had two: using functions as values and programming without side effects. We can pick one or the other or both. Or even another one altogether: I’ll agree to most anything reasonable that’s consistent with your article. As for nailing down when FP hits mainstream we have to first agree on what FP is but then we’ve got a challenge dealing with sampling error. I promise to try to be reasonable given whatever definition we come up with for FP.

> You try to falsify my points but use them yourself if it suits you. One certainly can

I’ve really striven hard to be consistent – right at the beginning I mentioned the multiple definitions of functional regarding both languages and programming. I apologize if I’ve changed my story in some way. If so it was inadvertent.

> claim writing side effect free and stateless code means writing FP code, but then it’s
> hard to divide it from most other languages.

Actually, you can. Any language might allow you to write side effect free code within limits (you probably want to do IO at some point, otherwise you’re just making the CPU hot), but a pure language requires that you not use side effects in your program. Also, FP stands for “functional programming” – it’s not a language but a technique – or actually, several different techniques with the same name – see all the discussion about side effects, functional values, etc. Depending on what definitions you use, it might be possible to do FP in a non functional language or do non functional programming in a functional language. We just gotta pick good definition.

> Reading that definition it seems clear that Java can be used as a pure functional
> language which – again – would make it a FP language.

You are beginning to see why I pointed out the multiple definitions right up front and tried to get you to tell me what yours is. You can create purely functional data structures in Java by the only definition I know of for purely functional data structures (immutable structures). But Java is not a functional language by the most common definition (functions as values). I’m really not making this up. It’s genuinely this confusing.

You know, I just remembered I’ve seen a third definition of functional programming language – one where the function is the fundamental unit of abstraction. Interestingly, Haskell and Standard ML qualify, but Scala and Nu do not. F# is kinda iffy because classes and functions are both fundamental units of abstraction. Lisps qualify with the caveat that syntactic abstraction is pretty important too. Anyway, this definition includes a language called Joy. It’s sometimes called a first order functional language – it’s “pure” (no side effects) and functions are the core unit of abstraction, but you can’t use functions as values or pass them as arguments to each other. I seem to remember you have to use only the built in combinators to compose functions. Kinda weird eh?

So maybe here is your definition for FP: using functions as the fundamental unit of code abstraction. And here we’ll totally agree. It ain’t happening in 2008 to any huge extent in the mainstream.

Oops! I just realized I made a mistake. In Scala you can directly encode the Y combinator by using casting – it just won’t be type safe. I’m not sure about F# and Nu, but given their background I suspect they can do the same thing. Haskell still can’t, though.

steve

I disagree about your inclusion of Nu in the list of “functional languages”. Actually programming in Nu over a period of time shows that LISP style functional constructs are mostly abandoned in favour of the Smalltalk/Objective-C infrastructure.

The list processing and other recursive type of features are replaced with Ruby style do-blocks, and there is a heavy emphasis on procedurally listing directives to objects because the underlying data structure in Nu is objects and not lists.

Nu is specifically designed and orientated towards incrementally shifting code between Objective C and Nu. So the overall effect of Nu is that of an imperative OO language very much like Ruby and Smalltalk, with the one specific low hanging fruit of LISP macros very powerfully plucked.

You’re totally right, yet totally wrong.

Nothing has changed yet that is going to cause the wide-scale adoption of functional languages, but we’re not too far off from something what will change: multicores and parallelism. Note that straight Hz computation has basically capped off at this point, and all new hardware increases are coming from increasing the number of cores in the system — we’re at 4~8 core server machines now, and Moore’s Law puts us within ks of cores within a decade.

The Mainstream concurrency model is broken (trust me, I know), and so if programs are going to start taking advantages of those performance gains, they’re going to need to start being smarter about concurrency. And, as of now, the only particularly smart approaches to concurrency seem to be in functional languages (see Erlang and JoCaml).

There’s a lot more on this over at my post on functional language adoption. My co-blogger Brian argues that It’s Not Just About Multicores, but I think your post does a good job of critiquing that approach.

stephan

@Robert: As written in some comments before, the Erlang concurrency model has nothing to do with functional programming or functions, but with statelessness (which obviously leads to no shared state). See Scala which does implement that style with objects. And as written before, it would be easy to write an Erlang-style library in Java.

Erlang concurrency is something I call concurrency 2.0. Which will be a very short success because domain driven concurrency will soon eclipse it. Fork/Join and Map/Reduce are two examples of domain driven concurrency which do scale better than Erlang concurrency.

OOP and imperative programming are both pretty stateful paradigms, so when you say “statelessness”, we’re half a step from functional programming (even if it’s got objects, like in Ocaml).

Got cite for Domain Concurrency? I’m curious about it.

I totally agree about Erlang. Its message-passing is only part of the solution, mostly useful for solving the problem of distributed/interprocess synchronization: the best intraprocess solution I’ve found is the join calculus stuff that JoCaml implemented. I’m actually wondering if that can be implemented in Factor, since it seems to have a lot of the necessary plumbing…

stephan

I think only I call it domain driven concurrency or concurrency 3.0. The idea is to have a concurrency framework which is domain driven. Because it knows more about your problem, it can solve it better (direct execute code or make it parallel, intelligent work stealing strategies etc).

Fork/Join by Doug Lea is

http://gee.cs.oswego.edu/dl/papers/fj.pdf

Map/Reduce is another one.

It’s less general than 2.0 (Erlang style) and 1.0 (Thread style), but what you lose in generalism you gain in performance and easyness.

For a transparent solution in Java see Spin ( http://spin.sourceforge.net/solution.html ) which could be implemented with message inboxes and add Erlang style concurrency to Java.

Check out join calculus concurrency: I’d suggest JoCaml for an implementation. From what I’m understanding, your “domain driven concurrency” is really just a special case of that.

http://moscova.inria.fr/join/index.shtml

Troy Taillefer

This is an amazing blog.

I am a big fan of functional programmming I absolutely love the haskell language (especially its type system) unfortunately the Haskell platform (tools, libs, books, community support, etc) sucks.

Also as a software professional I would have no one else to talk too if I didn’t know C/C /Java. Building useful software is about people writting software in some esoteric language that no one knows is guaranteed to shorten its useful life considerably. Viaweb is the famous example of how to create a cool app that has to be re written to be maintained.

Who cares if you speak the best language in the world if there is no one else to talk too.

English(C/C /Java/C#) isn’t perfect but it is familar and in widespread use so there for it serves as a good medium of communication. You could learn a better language like Esperanto(Haskell) but you wouldn’t have many people to talk too.

I could never diss LISP its contributions to our field are massive but you don’t see tons of useful apps being cranked out in LISP.

Also LISP may permit a functional style but there is far more imperative lisp programs and that is the way most lispers code. The same goes for scheme(although probably more FP’ers in scheme than in LISP).

Functional programming has made very useful contributions to our field and will continue to do so but I doubt it will be the next big thing. OO is embedded into our field it is what we all know it will take a long time to move onto a new paradigm.

I will probably buy the Scala book when it comes out it looks realy cool but I doubt I will ever use it for anything real.

The reason esoteric languages never catch on is because the platform is more important then the language itself and people matter they don’t want to learn new things because getting things done is more important

Scala only addresses the first problem by running on and using the java platform the second problem is just as important. You can still find C developers who don’t want to make the jump to Java or C# despite all its obvious productivity advantages.

Troy

stephan

I’ll probably buy the Scala book too, the PDF version is too much hazzle to buy (I tried twice).

Esperanto. I learned that too for some time, but forgot everything. Sigh.

“OO is embedded into our field it is what we all know it will take a long time to move onto a new paradigm.”

The comments too this post have made me think a lot. I suspect OO is successful because it makes modeling reality easier (but you can easily go wrong, see the DDD book). But I’m not sure yet. We’ll see.

Ben

You guys seem to be mostly in the Java world, not in the Microsoft world.
So you may have overlooked a non-technical factor which will probably override all the arguments I read here: namely that Microsoft have decided to ‘adopt’ F# and upgrade it from MS research to a ‘real’ .Net language.

They’re pushing it hard, and functional programming in general too.

They have LOTS of money for evangelisation.

I’m not sure I buy that Microsoft’s support of F# will translate into a major evangelism. It strikes me mainly as them hedging their bet.

stephan

MS didn’t even push C# enough, they are still C people I guess. So I don’t think their “support” F# will change anything. Should VB people who haven’t switched or understood C# no develop in F#?

A little bird

Stephan, You seem to be confused. Expressions in (eg) Lisp aren’t lists.
Assuming no sharing, they’re trees. With sharing, they’re graphs.

On a somewhat related note, Trees in Haskell:

—————————————————————————————
module Tree where

data Tree a = Node
{ rootLabel :: a
, subForest :: Forest a }

type Forest a = [Tree a]

flatten :: Tree a -> [a]
flatten t = squish t []
where squish (Node x ts) xs = x : foldr squish xs ts

levels :: Tree a -> [[a]]
levels t = map (map rootLabel) $
takeWhile (not . null) $
iterate (concatMap subForest) [t]
—————————————————————————————

stephan

@Little Bird: I’m easily confused, perhaps even more because the Lisp name was derived from List Processing Language.

hiho

stephan,

little bird means that the s-expressions in lisp are the nodes of its AST. coding in lisp is the same as coding up its AST. as an example, one can consider the first element of a list as the parent with each additional element thereafter as its children. this is similar to xml in that they both exhibit tree-like structure. the following link goes into detail: http://www.defmacro.org/ramblings/lisp.html

Erlang:

Facebook: Chat System
Delicious: Backend
Powerset: Fuzed
Motorola, Ericsson: Telecom switches

2008 looked pretty nice to me for FP, especially in the concurrency space where it seems to excel.

Cheers!

AMontyMouse: fallacy of biassed sample. The reason it seems like “all those functional programming types are that way” is because the ones who aren’t you don’t notice, and probably aren’t aware of.

ABUSERNAME

Nice article, I have been programming in functional languages in my spare time for nearly a year now, and over the summer I was in an internship for a small company that works on data translations. Mostly, all I had to do was make slight alterations to the existing java source. Halfway through, I decided to write the entire project over in haskell(with no intention to release it to the company) When I was done, I changed my mind and showed it to my manager. He tested it and timed it against the current java-based application, and then asked me if I could have done it like this in java. I said no. Then he said,”you should have found a way, we would have payed you for it.”
Procedural languages will always be dominant, but eventually they will gain functional “tools”.

@ABUSERNAME: Thanks.

Design Pattern

Just for the fun of it:
“when using ycombinators I’m doing FP2″

Ken Shirriff does Y combinators in Java:
http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html

“Ironically, the Java code starts to look like Lisp code, except with a bunch of }}} instead of ))).”

Kevin Wright

The words and the examples here just aren’t matching up. Although you’re seeking to demonstrate how unreadable you think FP languages are, you’ve then gone on to demonstrate this point by choosing languages not because they’re FP, but because they’re non-OO.

The two concepts (FP/OO) are not mutually exclusive, it does’t even make sense to compare them. The true comparison should be between imperative/declarative languages, where FP is just a large subset of declarative programming.

Seen from this perspective, OO is completely orthogonal to the declarative-imperative axis, and can be used alongside both paradigms.

Try stating your example again, but also in a declarative style using both JavaFX and Scala, I think you’ll find them both to be every bit as elegant as the Java solution.

Also, SQL is a good example of a declarative language, few would argue that it isn’t mainstream.

@Kevin:

If I write OO code in a functional/OO language, I no longer write functional code – obviously.

SQL is not a declarative language but an imperative/functional 4GL (depends on what features you use). Prolog is declarative, where you declare what you want. With SQL (joins,…) you tell SQL what to do.

“[...] where FP is just a large subset of declarative programming.”

Nope.

Leave a Reply

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?