27
  1. Are functional languages suited for web applications development?
  2. Are functional languages suited for business/ERP/CRM type of applications?
Software Engineer
  • 15,457
  • 7
  • 74
  • 102
Michael Ellick Ang
  • 1,128
  • 1
  • 9
  • 18

10 Answers10

30

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 4400 (in 2010 2012) 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
  • 137,316
  • 36
  • 365
  • 468
17

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, C#, etc. is that they come with large libraries and other environment niceties that are absolutely required when you build business software. Most functional languages do not have that great support (as yet?).

F# might be promising since it's 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
  • 5
    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. – J D May 12 '09 at 19:02
  • Can you provide an example of a library that is superior to it's .Net equivalent @JD? Do you think that still applies today? – julealgon Mar 03 '21 at 14:09
11

Functional languages are well suited for web application development, Scala in particular.

Have a look at the Lift framework for more information.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gabor
  • 1,030
  • 3
  • 12
  • 23
9

2) Are functional languages suited for business/ERP/CRM type of applications?

To address the second point about business/ERP/CRM apps: personally I wouldn't implement these in a "pure" functional language like Haskell, or a dynamic functional language like Clojure. On the other hand, I am currently implementing an ERP in Scala, which of course is hybrid OOP/FP and statically compiled.

The reason I say this is that a business app like an ERP is fundamentally record-oriented: there is a data schema expressing the different record types and the app logic is then designed almost wholly around CRUDing those records and applying custom business workflows to them. And fundamentally, I don't believe that these sorts of data-centric business apps are a great fit for the functional model.

People can talk about the OOP-relational mismatch all they like but ultimately both OOP and databases are record-oriented: an OOP language with a good ORM lets you map those different data models into your code and then attach the code to handle each of the models. And having this statically typed (ideally with a strongly-typed ORM like Scala's squeryl) massively reduces the chances of a runtime error or e.g. a change to one of the data models not being properly applied through the code.

Don't get me wrong - I'm a big fan of FP (I'm doing more and more of my systems programming in Haskell), but for me the record-oriented approach of OOP makes more sense than the function-oriented approach of FP for wrangling the data objects of a business ERP or similar. (Scala is a nice exception to the rule because you get to use the OOP paradigm with quality ORMs for the record manipulation, but also the FP goodness for your general app programming.)

Alex Dean
  • 15,575
  • 13
  • 63
  • 74
8
  1. Yes, Nitrogen is a good example of a functional web framework. It scales also.

http://nitrogenproject.com/

Flinkman
  • 17,732
  • 8
  • 32
  • 53
4

Yaws is a fantastic web server for Erlang.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Richard
  • 10,122
  • 10
  • 42
  • 61
3

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
  • 5,755
  • 2
  • 27
  • 34
  • 2
    It seems like Erlang is more often hosted on native Erlang servers like YAWS (http://yaws.hyber.org/). – Chuck May 04 '09 at 18:07
  • 1
    And a scala webapp would be hosted in a servlet container such as Tomcat. – Blake Pettersson May 04 '09 at 18:22
  • 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 May 04 '09 at 18:32
  • 3
    F# actually works fine in ASP.NET pages (aspx). We're doing ASP.NET MVC, with zero C# at all, anywhere. – MichaelGG May 04 '09 at 20:20
  • @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 May 04 '09 at 20:27
  • 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 May 04 '09 at 22:55
  • 1
    "I wouldn't say that any particular functional languages are tailored for doing web-development". Javascript? :-) – J D Feb 18 '11 at 09:25
3

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
  • 19,422
  • 10
  • 54
  • 67
3

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
  • 31,473
  • 17
  • 86
  • 101
-2

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
  • 15,173
  • 4
  • 37
  • 39
  • 11
    They bring the advantages they normally bring: code is easier to read, less buggy, and faster to write. – MichaelGG May 04 '09 at 20:21
  • 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 May 04 '09 at 20:40
  • 3
    have to agree with clint, i think most developers have an easier time reading OO code. – Michael Ellick Ang May 04 '09 at 22:58
  • 1
    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 May 05 '09 at 10:08
  • 7
    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 May 06 '09 at 14:51
  • 3
    "Faster to write" - Don't get me wrong I love functional programming but thinking functional is just slower – igorgue May 06 '09 at 15:09
  • 1
    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 May 06 '09 at 23:53
  • 1
    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 May 08 '09 at 03:27
  • @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... – J D May 12 '09 at 19:16
  • 1
    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 May 13 '09 at 04:08
  • 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 Jun 14 '10 at 15:57
  • 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 Jun 14 '10 at 15:58
  • 1
    "I think the overwhelming majority of developers in industry right now would disagree". Look at the uptake of lambdas in the .NET world for an obvious counter example. – J D Feb 18 '11 at 09:31
  • "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)". You realise **Lisp is a functional language**? – J D Feb 18 '11 at 09:32
  • "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". If you ask elsewhere, be sure to clarify that you are talking about *purely* functional programming. – J D Feb 18 '11 at 09:36
  • 1
    If you really want to simplify what happens on the web, you have a `Request -> Response`. That's really just a transformation of a request into a response, a simple function. Everything else is preference on how you add the additional layers of complexity. Building up additional functions to compose the rest is one (very nice) way. Check out [WebSharper](http://websharper.com/) for a very nice example. –  Sep 10 '11 at 08:19