Live data from Hacker News

Is functional programming relevant to web development?

stackoverflow.com

1–10 of 27 posts

Re: Is functional programming relevant to web development?

#3
The reason why functional programming is popular with web programming is that it explicits shared and changing state and allows the programmer to express the purely functional parts as pure functions. Pure functions have the advantage of being very simple to run in parallel - as they have no side-effects.

At least that's my reason.

Re: Is functional programming relevant to web development?

#4
There are various interesting things in the various functional worlds in the very early phases of being interesting, but unless you are the sort of web programmer who routinely just programs up their own frameworks I couldn't really recommend any of them right now if you're not already a pretty good functional programmer and you're actively interested in participating in such early experiments.

Possible exceptions would include Seaside, which I've never used but has been around for a while and from what I can see has a genuinely different approach to web development that actually does exploit Scheme, and Erlyweb (and to some extent the Erlang frameworks in general), which naturally exploit being on the Erlang VM which has interesting consequences for certain types of web apps. I suspect neither would look particularly mature next to Ruby on Rails, but if you happen to have a need that matches those they may still be a win.

Re: Is functional programming relevant to web development?

#5
post #3

The reason why functional programming is popular with web programming is that it explicits shared and changing state and allows the programmer to express the purely functional parts as pure functions. Pure functions have the advantage of being very simple to run in parallel - as they have no side-effects. At least that's my reason.

... but it's not popular? ...

Re: Is functional programming relevant to web development?

#7
post #4

There are various interesting things in the various functional worlds in the very early phases of being interesting, but unless you are the sort of web programmer who routinely just programs up their own frameworks I couldn't really recommend any of them right now if you're not already a pretty good functional programmer and you're actively interested in participating in such early experiments. Possible exceptions wo…

"Possible exceptions would include Seaside, which I've never used but has been around for a while and from what I can see has a genuinely different approach to web development that actually does exploit Scheme."

Unless we are talking 'bout a different framework, Seaside is Smalltalk.

Re: Is functional programming relevant to web development?

#8
Functional programming best matches web development because the web page is basically a static container that sends messages back and forth to a farm of servers. The server that gets the message may know nothing about what the web page is doing.

FP fits nicely because in FP you're always "threading the state" -- keeping everything you need around to make the program work. Functions can sit on a server, or on a million servers, and seamlessly process messages from clients. This is easily being done in the OOP-world, but on the FP side it's trivial, whereas with OOP there can be a lot of hoops to jump through.

WebSharper is very cool -- takes F# and makes it run as javascript. So you write one script module, annotating methods as running either on the client, server, or both, and then you just code as if all the methods were in the same spot. It figures out how to write the javascript and how the methods can talk to each other.

I'm also seeing some cool stuff with functional-reactive programming, which, if taken to its logical extreme, could rewrite large parts of the web server stack. In my opinion, because of the architectural nature of the web, in a lot of ways, functional code maps much more closely with web operations than OOP does.

Having said all of that, programming is programming, and if you know what you're doing, you can make things happen. Choice of languages and brands can be vastly overrated. The important part is knowing how to use the tools.

Re: Is functional programming relevant to web development?

#9
post #2

Just make sure you don't pointlessly store continuations when you don't need to, like on Hacker News.

Indeed. The language of implementation does not matter much, what matters is what sort of data structure you use. When you can just read a piece of text from a database, it makes little sense to create an opaque state-carrying object dependent on the memory space of one process. news.arc is about as far from "functional programming" as you can get.

People often use Darcs as an example of why functional programming is a bad idea "for industry". But the irony is that Darcs has a state-heavy mutable data storage model. This is what makes it slow, not Haskell.

Compare Darcs to Git's completely immutable model, and you'll notice that you get fast Git clients even if you implement it in a language like Ruby.

The "takeaway" from functional programming is that immutability scales, no matter what syntax you implement the pure data structures in.

Since starting with Haskell many years ago, I don't think I've written any application that's been dependent on a mutable datastore. With nearly every business application requiring auditing and historical data retention, doing things right even gets you bullet-point features for free!

Post reply on HN