views:

2077

answers:

9

Hi,

1) Are functional languages suited for web applications development ?

2) Are functional languages suited for business/erp/crm type of applications ?

+7  A: 

Functional languages are well suited for webapp development, scala in particular.

Have a look at the Lift framework for more info.

gabor
+1 for Lift ...
missingfaktor
+8  A: 

Functional Languages are good for anything you would like to use them for.

However, developing applications these days are not as simple as using a programming language. The advantage of Java and C# etc is that they come with large libraries of code and other environment niceties that are absolutely required when you build business software. Most functional languages does not have that great support (as yet?).

F# might be promising since its in the .NET environment and can take advantage of the tools available there (correct me if I'm wrong).

This article describes how Lisp - an early functional language - was used to create a web based application successfully.

Vincent Ramdhanie
F# can indeed use all .NET libraries thanks to seamless interop. However, having used both OCaml and F# in industry for many years, I have to say that OCaml's libraries are far superior to .NETs. The advantage of F# is not that you have access to great libraries (you do not) but that you can sell great libraries.
Jon Harrop
+1 for Graham article
DVK
+2  A: 

While I wouldn't say that any particular functional languages are tailored for doing web-development, I also wouldn't say that you can't do web development with a functional language. I think that depends entirely on what web frameworks may be available for the language you choose and whether or not there are any web servers that will support the language.

For instance, I'm sure that you can use F# along with ASP.Net on IIS to do web development. I doubt there's support for F# in the templating engine, but you can definitely write business logic in F#.

Similarly, there's mod_haskell for Apache, which should make it relatively easy to have dynamic output with haskell. Although, I've never personally used it. At the same time, if there's a mod_(erlang or scala) for Apache, it would be similarly easy for those languages.

Ultimately, I think that the stateless nature of functional languages should make it well suited for a stateless, MVC style web framework. However, I think it really comes down to what tools and frameworks are available to make your life easier when working with these languages. For example, Ruby wasn't really popular for web development until rails got popular, and I didn't really like doing anything webby with Python until I found django.

dustyburwell
It seems like Erlang is more often hosted on native Erlang servers like YAWS (http://yaws.hyber.org/).
Chuck
And a scala webapp would be hosted in a servlet container such as Tomcat.
Blake Pettersson
Good points fellas. I answered this question off the top of my head without the immediate knowledge that Scala was a JVM language and that Erlang had a native server. Good to know!
dustyburwell
F# actually works fine in ASP.NET pages (aspx). We're doing ASP.NET MVC, with zero C# at all, anywhere.
MichaelGG
@MichaelGG Awesome! I wish I could convince someone to let me try that while getting paid for it. Unfortunately, no one else around here has played with F#. Therefore, I'd be the only one who could maintain it. Job security, I guess.
dustyburwell
wow didn't know that you can code asp.net entirely using f#. are there any things we need to be aware of ?
Michael Ellick Ang
+13  A: 

Functional languages of the kind you describe are general purpose programming languages, they're used for all manner of things, including web apps and business apps. (I use Haskell).

As gabor implies, ultimately it comes down to libraries. Scala has a web framework: lift. Haskell has happstack, as well as 2100 (in 2010) libraries on Hackage for all manner of thiings.

It really isn't so much a question of the language, as the toolchain, when considering particular specialized domains.

Don Stewart
+6  A: 
  1. Yes, Nitrogen is a good example of a functional web framework. It scales also.

http://nitrogenproject.com/

Flinkman
thanks didn't know that erlang has a web framework
Michael Ellick Ang
There is also the Erlang Web framework: http://www.erlang-web.org/
Adam Lindberg
and about 10 or so more...
Amadiro
A: 

One of the biggest advantages claimed by proponents of functional languages is that they make it easier to write programs that can execute in parallel. But web applications typically don't have problems with parallelism. Typically, the web server/application server maintains a pool of threads, and each user request is assigned to a different thread, which can run on a different physical processor. So, you can take advantage of multiple processors without too much trouble. The trick is that web apps are characterized by large numbers of small requests, and threads and imperative languages work well there. Where imperative languages start to break down is when you have a small number of computationally expensive requests.

Another big advantage of functional languages is that since functions have no side effects, testing is easier. You test each function in isolation across a few of its inputs, and you know the system will work. But, there's a catch. If your operation involves input or output, you use a monad rather than a function, and you lose this testability benefit for that portion of your code.

But, typically web applications involve reading information from a request, making requests to a database, reading the response from the database, and formatting a response. That's lots and lots of IO, or monads, and very little opportunity for functions.

Given these characteristics of web applications, what benefits do functional languages bring to web application programming?

Clint Miller
They bring the advantages they normally bring: code is easier to read, less buggy, and faster to write.
MichaelGG
I've very confused. "Code is easier to read"... I think the overwhelming majority of developers in industry right now would disagree. "Less buggy"... isn't that normally a result of code without side effects, which applies to very little code in a web app? "Faster to write"... I've not seen that claimed as a benefit of functional coding (at least not relative to what I can do in, say, Python or Lisp). I'm pushing for specifics here because I'm trying to understand why I should switch my own web app development to a functional language, and I'm not seeing the benefits.
Clint Miller
have to agree with clint, i think most developers have an easier time reading OO code.
Michael Ellick Ang
Are you sure that you can't gain big advantage from functional language for web development? http://www.erlangatwork.com/2009/03/lies-damned-lies-and-benchmarks.html -- more than 16 thousand dynamic pages with reads and writes from shared database resource per second. Show me any classical technology which can beat it. Show me!
Hynek -Pichi- Vychodil
If you don't know a language, you're likely to not be able to read it. For instance, if you know Clojure, then reading Clojure code is a breeze. If you know Java, reading Java code is relatively easy. If you know Java, then SmallTalk wont be very easy to read will it? Your point is moot.
Rayne
"Faster to write" - Don't get me wrong I love functional programming but thinking functional is just slower
igorgue
rayne is correct that if you don't know a language, it is hard to read. but most programmers right now come from a Object Oriented / Procedural background, so code written in Functional languages are harder to understand.
Michael Ellick Ang
Depending on what language you use they can bring a lot of things to the table. Erlang brings highly scalable web servers you can plug easily into. Erlang and Haskell's Pattern Matching are also highly useful for Event Driven Frameworks if that's your cup of tea.As for offering very little opportunity for functions then you obviously haven't written much web functional languages. There is a lot of Business logic in there and all of it is candidate for functions with no IO required.
Jeremy Wall
-1 for being clueless. Parallelism is irrelevant. Most functional languages are not side-effect free (including three of the four listed in this question). Monads are irrelevant. You have a lot to learn. Start by learning what Erlang was specifically created for and why that is hugely relevant to web programming. Then learn how difficult people using imperative languages find concurrent programming and consider the benefits of Haskell's type system proving the correctness of aspects of your code.
Jon Harrop
@Michael Ellick Ang: do programmers struggle with Javascript, C# 3 and LINQ? No. Functional programming is easy, not hard. Anyone who has managed to learn OOP can pick up FP in five minutes...
Jon Harrop
Good Lord! I've unintentionally started a flame war and exposed some fanboys in the process! My original question was an honest question, and not meant as an attempt to shoot down FP. I'm an extremely accomplished web app developer who loves Python and Lisp and hates Java (but gets paid to do Java). I've wanted to get into pure functional languages, but have struggled to find their relevance to web programming, and I was hoping someone here could rationally explain what I'm missing. Perhaps I'll ask somewhere else.
Clint Miller
Parallelism is indeed important in web apps at scale. In a heavily used web application you need far more threads than CPUs available, hence the threading model in many functional languages is perfect. I have seen both Python and C++ web frameworks expend a lot of code to duplicate that kind functionality that just comes free with Haskell.
MtnViewMark
As for testing, just because either side of a web app is IO based (HTTP or DB), doesn't mean it isn't testable. Functional languages lead you to write the business logic of a web app in such a way that it is easily testable. And, there are easy ways to abstract the Monads away if you want to test those interfaces as well.
MtnViewMark
+4  A: 

Functional languages provides new kinds of abstractions which can be used for web development. Continuation based web servers are for example popular among functional languages. The PLT Scheme web server supports this kind of web application development. You can read more about continuations and their use in web development on wikipedia

Jonas
+4  A: 

yaws is a fantastic web server for erlang

Richard
+1  A: 

Most functional languages, namely the ones you included, are considered general purpose languages. For web development, I would deeply consider using Clojure, or Scala. They both have very good web frameworks, and they both run on the JVM. I can totally recommend Clojure and Scala, but not so much for the others.

Haskell has a web framework, but I have never used it.

Business applications? Sure, why not. Functional languages are great for just about anything.

Rayne