Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've recently gotten into learning about functional programming. I've been coding in Scala most of this past year and am just now starting to fully grasp the power of a functional language.

I want to build a data-driven website from scratch using functional techniques. I'm having trouble wrapping my head around how to start thinking about this. I've done this many times over using standard Java OO techniques. I usually think about the end product, build my object model off of that, then build my DB CRUD layer, then my services layer (business logic), then my web/ui layer.

My question is: how can I reason about/design a large, data-driven web application in a functional manner?

EDIT: Good points made so far. How about this:

In a data-driven web application (database, MVC, HTML forms, etc.) where does it make sense to use FP?

I'm still working on getting a good understanding of exactly what FP is, so please bear with me in my questions.

share|improve this question

closed as too broad by MichaelT, JB King, Snowman Dec 4 '15 at 18:19

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

When all you have is a hammer...

Look the simple answer is the most truthful, you don't have to make it ALL functional. It has its purpose, use it in the right place!

share|improve this answer
This is one of those answers I wish I could upvote more than once... – Mason Wheeler Mar 29 '11 at 22:10
I give you my vote then... but then again, I too want to vote on it !! arg ! – Newtopian Mar 30 '11 at 5:06
This didn't really answer the OP's question. This answer is true but it is not an answer to the question of how to "How can I reason about/design a large, data-driven web application in a functional manner?" – Guido Anselmi Jun 18 '14 at 14:59

My question is: how can I reason about/design a large, data-driven web application in a functional manner?

Um... It's hard to answer, but, you design it functionally. As a function

web_site( request ) -> response

A web site is just a function that maps requests to responses. Usually it uses HTTP, so it's really

web_site( HTTPRequest ) -> HTTPResponse

And an HTTP response is Headers and Content that follows the headers.

The web_site as a function is really a pipeline composed of several functions:

template( content( authentication( request ) ) ) -> HTTPResponse

And you can break template filling, content creation and authentication down into functions.

You also have a master function, url_dispatch( request ), which chooses among a variety of content/template compositions based on parsing the URI.

share|improve this answer

Why do you need to build the whole thing in it?

There are places where functional programming comes into it's own. This is mainly where you have a domain problem, often where a decision needs to be made in one form or another.

Most website calls are just to serve up things in the DB.

Taking a .Net example (sorry...), you can use F# assemblies which are refernced by C# assemblies. The C# does all the data serving and the F# can do the "thinking" where data needs to be processed. My guess is there is something that can hook between your languages.

share|improve this answer
Good point. Maybe I should re-phrase my question to something like "in a data-driven web application, where is it useful to use FP?" – three-cups Mar 29 '11 at 22:40
Will depend on your domain. What are you planning to work on? – burnt_hand Mar 30 '11 at 8:43
This is my "play" site: It's basically college football statistics. I'm planning on either re-writing it or adding new functionality in a functional manner. – three-cups Mar 30 '11 at 21:12
Looks cool. Stats would be a good place to start, maybe using the functional language to generate on the fly graph data (using a web service perhaps) or player vs player comparissons (im sure you have thought of these already). And be wary about rewriting old things. There's always more to it than you can usually remember. – burnt_hand Mar 31 '11 at 9:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.