[erlang-questions] Similarities between web programming and functional programming
Wed Jun 16 04:35:43 CEST 2010
I see the resemblance with HTTP GET type request and pure function but what about HTTP POST and the side-effects?
On Jun 12, 2010, at 4:37 PM, Jesper Louis Andersen wrote:
> On Sat, Jun 12, 2010 at 10:19 PM, Nilanjan Raychaudhuri
> <> wrote:
>> Hi all,
>> As a newbie into functional programming I am curious to know how functional programming style fits into building web applications? And how it
>> compares to building web apps in Ruby or Java.
>> Any pointer to article/literature will be helpful.
> Look at the following function:
> handle(Request) ->
> X = ...,
> Template = ...,
> render_response(?HTTP_OK, X, Template).
> It has the specification contract
> -spec handle(request()) -> response().
> That is, handling incoming web requests are (sometimes pure) functions
> from request() objects to response() objects. At this point, we are
> essentially done. There isn't much more to it. Of course, we have only
> defined a rough skeleton of how to do it, and a lot of the fleshy
> details have been omitted. What makes it easy is that the web is
> essentially stateless: All needed information is in the request()
> object. If we store data locally, there will be some kind of token()
> object (a cookie, say) in the request() object allowing us to get hold
> of our server-side state. One could imagine calling another process to
> get hold of this data (it is not much different from Ruby, Python or
> Java calling into an SQL database for their data).
> In general web-server handling is very amenable to the functional
> programming paradigm. You may regard the above as being unnecessarily
> low level, but it is very easy to use a couple of wrapper functions to
> peel off layers of complexity so you end up with the innards of a web
> framework such as Rails, Django or Pylons.
> Erlang gives you an insane amount of tools to manipulate
> web-applications. It seems that much of the heightened interest in
> Erlang as of late is channeled towards building web-tools and webapps
> in general. So not only will you have an excellent language for doing
> web application development; you will also enjoy standing on the
> shoulders of giants.
More information about the erlang-questions