5 ms·
Is functional programming relevant to web development?
- bhiggins 16y agoJust make sure you don't pointlessly store continuations when you don't need to, like on Hacker News.
- jrockway 16y agoIndeed. 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!
- silentbicycle 16y agoYou know what would knock the planet's socks flat on their asses? If the Haskell and Erlang people got together. I definitely fall on the Erlang side, but (especially if you shrug off the fanatic outliers) the differences are actually quite minor.
- bhiggins 16y agoLike strict vs. lazy evaluation by default...?
- jrockway 16y agoThis is not really an insurmountable issue. $ is the lazy function application operator. $! is the strict function application operator. Use the one you mean and it will all work out.
- thesz 16y agoCommunicating Haskell Processes? http://hackage.haskell.org/package/chp http://hackage.haskell.org/package/chp
- rbanffy 16y agoThe 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.
- jerf 16y agoThere 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.
- ohyes 16y ago"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.
- jerf 16y agoOops, sorry, thinko. Too late to edit now.
- FluidDjango 16y agoAnyone find this comment (in a suggested answer) strange: >Yahoo! Store was written by Paul Graham, who is a big Lisp advocate. He also wrote Hacker News, which is, effectively, a Reddit clone.
- irahul 16y agoStrange, yes but it's kinda true. I saw somewhere Reddit's founder saying that pg came to them and asked if a sub-reddit where he has the full control is possible. When they said that model wasn't possible, he wrote hacker news. That, and using it as an arc showcase. That being said, saying that different applications by same programmer doesn't count(as the SO comment implies) is ridiculous.
- DanielBMarkham 16y agoFunctional 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.
- jrockway 16y agoYes. The HTTP lifecycle is a perfect example of purely functional interaction. You get a request object. You produce a response object. Done.
- bobfunk 16y agoIf it was a purely functional interaction, shouldn't the same request always get the same response? In reality a lot of non-pure IO stuff tend to be the main part of what goes on in-between the request and the response in most web-apps...
- jrockway 16y agoIf it was a purely functional interaction, shouldn't the same request always get the same response? Yes. This is why things like Rail's "flash" breaks the Internet... or at least your web app.
- bobfunk 16y agoWell, each time I go to twitter.com I hope to see something slightly different than last time and that's not part of the internet being broken.
- gattone 16y agoYes, but each time you go, the input data (like the microsecond since 1970) is different.
- jrockway 16y agoNo. If Twitter were purely funtional, which it is not, twitter.com would be a pointer to twitter.com/<state>, where twitter.com/<state> changed every time someone tweeted. twitter.com/234987kdsjlhfsad would always be the same page. It's the auto-redirect to the current state that makes twitter.com appear to change. If you use git, it's like the HEAD reference. It's a pointer to the immutable commit. The reference itself is mutable.
- narrator 16y agoYou can already do functional web programming with Scala/Lift. Be prepared for a real mind-bender of a web framework though. For instance, each form field specifies an in-line closure that gets called when the form is submitted. When you define an ajax button that is inserted into a form, clicking on that button invokes a server-side closure that's provided with the definition. There aren't any servlets, json parsing, ajax client library or anything like that in between. It's really quite nice. Just really really different.
- loup-vaillant 16y agoKnowing that it's a good idea to avoid or isolate the assignment statement and other (side) effects¹, Id' say there's not many fields where functional programming is not relevant. [1] http://www.loup-vaillant.fr/articles/assignment http://www.loup-vaillant.fr/articles/assignment