The Rise of Functional Languages

Functional Languages seem to be pushing for the title of the next cool thing. Talks and tutorials about them are starting to show up in conferences and conventions, books about them are hitting the shelves, people are even asking about talking about them in blogs and mailing lists devoted to some of the current hot languages.

Does this mean you’ll be using one next year? Maybe, but probably not. Does it mean you might want to spend some time learning one? Absolutely. Brief description of functional languages. Dave Thomas and Andy Hunt the Pragmatic Programmers recommend learning a new language every year, calling it a LOTY (Language of the Year). In his book ‘My Job Went To India’, Chad Fowler complains about programmers who say things like: ‘No I haven’t been given the opportunity to work with language Foo, or framework Bar.’ This is a great chance to look at something that’s very different from the way you’re programming today, something that could change the way you think about programming challenges.

So, what are functional programming languages? At the core, they’re languages that carefully follow mathematical concepts. Variables aren’t, at least not as most programmers think of them They’re more like a variable in algebra—once you’ve found the value of X in a problem, it’s not going to change on you.

Functional languages also avoid ‘side effects’. That is, if you pass a value into a function it will not be changed and the function will not cause other changes somewhere else in your data (there’s a formal method for getting around this to do things like output … I’m not planning on getting into that here though).

Meta-programming, lazy evaluation, and type safety are much more common idioms in the functional languages I’ve seen too.

These differences mean that doing simple things like iterating over a loop and incrementing a counter as you do just don’t work in functional programming. Recursion, list mapping, accumulation, and the like are much more common in the functional world.

This might sound a little strange—I mean, how can you program without loops, or variables that can vary? In truth, functional programmers seem to be doing very well. They seem to be over-represented in the top finishers in programming competitions. Their code tremendously terse, and often scarily efficient. It’s just not mainstream (yet).

Functional Languages seem to get a lot more traction in Europe and academia right now. Over the last couple of years, they’ve been making up ground in that group Tim O’Reilly likes to call ‘the Alpha-geeks’. Whether or not functional languages are poised to take the next step into wide spread adoption is anybody’s guess, but it’s certainly a possibility.

Recently, three different publishers have release books about different functional programming languages. First, Apress put out Practical OCaml, which didn’t go over very well in the community—I know they’re looking at what they can do to ‘get back on the horse’ and get a really successful functional language book out the door.

Next up was Cambridge University Press was next with Programming in Haskell. This looks like a very solid book, and I’ve heard other people say good things about it too. I have to admit that I’m put off by the use of special characters in program listings, where the actual code would use a normal ascii symbol (for example, the greek lambda character in place of an /).

Most recently, the Pragmatic Programmers have launched a beta of Programming Erlang by Joe Armstrong (the creator of Erlang). While this isn’t done yet, It looks wonderful, and everyone I know is raving about it—even my local Ruby brigade is going to start working through the book one night a month.

I’ve been buried under a huge load so far this year, so I’m coming late to my LOTY for 2007, but I’ve settled on Erlang. The combination of functional programming, a tremendous level of concurrency baked into the language, and a great book from Joe Armstrong and the prags has sold me. I’m looking forward to starting in the second half of May.

______________________

-- -pate http://on-ruby.blogspot.com

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

It's already here

Andrew W's picture

Functional paradigms offer some innovative solutions to long standing Web development problems :-

1. Continuations fix the inversion of control problem caused by the stateless nature of HTTP. With continuations you can start a function and define some variables you can then 'call out' to the user i.e. send them a page. When the user responds, your function continues where it left off with all the variables still in scope. This means no need for hidden variables, sessions packed with transient data etc. Imagine now that your entire business process is now captured in one easy to read function, not spread over numerous java classes with varied XML structures.

2. Concurrency problems with poorly defined static variables leaking confidential data to the wrong customers are a thing of the past. Everything is passed on the stack as function arguments - there is no mutating state shared between requests. This also makes the application highly scaleable.

3. Security - the continuations approach means that the only way to link one page to another is via a continuation which is unique to each user. This means that data-driven attacks i.e. manipulating keys in forms to get access to data won't work - you can only access data within your continuation.

Try it with SISCWeb - a Scheme continuations based framework that runs on top of J2EE. This allows you to reuse all of your Java libraries and business components but benefit from a functional presentation layer. Also being Scheme based, it offers an embedded 'REPL' so you can build and change your application on the fly without restarting Tomcat or losing existing application state.

It's even better than Ruby on Rails but don't tell anyone - they'll all be using it and I'll have some competition !

Learn Scala

Sergiu Rata's picture

It looks like Scala draws on lots of good features from Erlang, however implemented on top of JVM and you can reuse lots of "old" Java code, hence you get to preserve the investment. And along with FP, it's OO as well.

We are using TCL - 500,000 lines of it...

Frank Bergmann's picture

Did you know that TCL is a functional language? Basicly, it's a kind of LISP with a sytax that looks a bit like Basic...

Just to stress the point that functional language are alive and kicking: We've got some 500kLoC at http://www.project-open.org/, and with more then 1000 pages it's probably the largest open-source web application around...

Cheers,
Frank

Lisp and Scheme

Anonymous's picture

books:
Practical Common Lisp - Peter Seibel
On Lisp - Paul Graham
ANSI Common Lisp - Paul Graham
The Little Schemer - ?
The Seasoned Schemer - ?
Structure and Interpretation of Computer Programs (Scheme) - Abelson and Sussman

lisp isnt Pure functional language, but still is a functional language. and much easier to learn and more powerful than any other language (any, meaning, ANY language).

LISP?

Anonymous's picture

LISP?

OCaml for Scientists

Jon Harrop's picture

The book "OCaml for Scientists" received fantastic reviews.

Cheers,
Jon.

Funny looking characters in code listings

kirstin's picture

Quite a few haskell programmers use a literate programming system. In fact, one is built right into ghc. After the source code is prepared by latex into a document, the code listing does in fact show use an actual lambda for a '\' as well as an actual arrow for a '->'.

There is a reason that mathematicians use their funny notations, and don't write papers with only ascii characters. I imagine it's confusing if you've never done much with predicate or lambda calculus, but the lambda came first, and the backslash is just the best ascii representation we have. It's not supposed to be a bashslash. It's a lambda.

lots more comments

Pat Eyler's picture

I hate to point elsewhere, but there are a lot of good comments about this article over at programming.reddit.com.

--
-pate
http://on-ruby.blogspot.com

Tools for the job.

Anonymous's picture

Tools for the job. Functional languages are best suited to certain applications such as parser and compiler construction. Things where a formal syntax is needed that evaluates to a known good state i.e. the main function returns true. I don't think we're going to see functional languages used to write web applications etc.

Next buzzword please.

I'm not to sure.

Wellingj's picture

Ruby is a functional language... I've heard it's doing quite well with web apps.
And our AI teacher allowed us to use Ruby instead of CLISP on some assignments.
Ruby was way more enjoyable....

Real-world apps -

Anonymous's picture

YAWS is a web server written in Erlang.
eJabberd is a XMPP/Jabber server written in Erlang
(by very skilled Russians! :>).
MLDonkey is a eDonkey GUI client written in Ocaml.
There are quite nontrivial packages/libraries for web application development for Common Lisp and Scheme, heavily relying on features of these languages (closures, continuations, etc).

FPLs are coming. Into mainstream and out of obscurity.
Now you don't have to search much to find that they are used indeed.

What about XML and XSLT

elarson's picture

XSLT is essentially a functional language. The popular jQuery javascript toolkit also has some functional qualities. Python's WSGI also is rather functional in nature. Sure, we may not see the web written in Erlang or Haskell any time soon, but the patterns found in functional languages provides a great framework for asynchronous communication, which is what built the web

The right tool for concurrency

Anonymous's picture

FP also works a hell of a lot better than most paradigms when it comes to dealing with concurrency. This reason alone is why you are going to see FP take off in a big way over the next couple of years.

web development

Sean McEligot's picture

With functional languages most errors are found at compile. You can even write XHTML in a functional language and the compiler won't let you violate the spec or forget to close a tag. This saves a lot of time in web development where compile-test-run can be a slow process.

hmm, this would seem to say

Pat Eyler's picture

hmm, this would seem to say that at least some people are writing web frameworks in erlang. And, this
seems to say some people are writing web apps in erlang.

Sure, use the right tool for the job, but don't turn up your nose
at something just because it's new. Sometimes there are some cool tricks hiding in that new programming language.

--
-pate
http://on-ruby.blogspot.com

Is it "something new"?

IsaacKuo's picture

Functional languages have been around a long time; they predate "object oriented" languages. I was never much of a fan of "object oriented", so if "functional languages" take the spotlight from OO, then I'm all for it!

But obviously there are some new twists to this old idea going on. Functional languages were always really cool, but this is the first I've heard of them being used for web development. Of course, the last time I was using functional languages, HTML didn't even exist...so what do I know?

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix