Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
add comment

3 Answers

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
1  
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 at 14:59
add comment

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: cfreference.net. 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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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