Swaroop C H

blog books about contact subscribe

Future of Programming is Functional Programming

14 Jan 2005

I was reading this interesting article on ACM Queue called Extensible Programming for the 21st Century - the author talks about the current state of languages, compilers and libraries and then he proposes a solution to solve most of the problems - write programs in XML format!

Before I pour my thinking on that, one particular paragraph did catch my attention:

Programming languages often grow by formalizing and generalizing the best practices of their day. Well-nested goto statements become structured programming's conditionals and loops; records that are accessed only through companion functions become objects; functions that are identical except for data types become generics, and so on.

Insightful.

Ok, believe me, I took quite a while to digest what that guy's saying about 'extensible programming' but its my understanding that it boils down to this - your program is always in a tree structure, you can imagine flowcharts to visualize this. So why not formalize it in the form of XML? Experienced guys will balk at this and say Lisp has been doing this for years! Yes, it has. So, why use XML? Because "S-expressions might have deserved to win, but XML has."

Its kind of really hard to imagine writing programs in XML, somehow I imagine I would never use such a language. I'm having a tough time just writing in DocBook XML! .... but still let me not jump to conclusions - the tutorial for the O:XML language looks interesting. You can program in O:XML like this:


[xml] never! 0">always! [/xml]

Hmmm.

I think I should really learn a functional language before making any judgements on this. I'll probably take a look at Scheme or Haskell in future. Any ideas on which is the best FP (Functional Programming) language to start off with?

Just yesterday, Avinash was explaining to me about doing FP kind of programming in Python and how it is one of the reasons that Python is here to stay.

All this has got me interested in exploring the FP part of Python - rest assured, I'll write about them in my book as well.

By the way, a good read is Paul Graham's essay "Beating the Averages". He explains why Lisp was an advantage to him when building ViaWeb (which was later sold to Yahoo!).

Please do leave comments on your experiences with FP. I would be interested to hear about it.

Comments

Ken Rawlings says:

I concur with the endorsements of SICP -- it's an overwhelming book at times, but full of deep wisdom about functional programming as well as programming in general.

I've spent quite a bit of time with Scheme and Objective Caml, and feel that it's worth exploring both. For me, Scheme is a great language for experimentation, and Objective Caml is a great language for application development. I also wrote a small summary of my positive and negative experiences with Objective Caml on my weblog a while back that might be worth looking at.

Ken Rawlings says:

Not sure what happened with the formatting above. Here's the raw URL to the link I posted:
http://www.kenrawlings.com/archives/2004/09/28/objective-caml-a-pythonic-diversion/

Swaroop C H says:

Thanks Ken! I'll take a look

Gordon Weakliem says:

I'm partial to Scheme, especially PLT, though I have no experience with Haskell. Common Lisp would be my 2nd recommendation, though it's hard to find a good free distribution for Windows. And honestly, Javascript can do some pretty cool FP-type things, E4X (works with Rhino) makes XML a native datatype in Javascript.

Swaroop C H says:

Thanks Gordon! I will look into Scheme. I am not much of a Java and Javascript guy but I read some info about E4X recently and it sounded pretty cool.

Premshree says:

I've worked with OCaml and Scheme in the past. I haven't used either of them for implementing anything big, nor do I know them well enough for me to be able to choose one.

However, there's one thing that you might want to consider before choosing one: OCaml consists of object-oriented concepts, Scheme -- most implementations -- doesn't. And *maybe* if you don't want to feel comfortable right away, you should go for Scheme. :)

Swaroop C H says:

Oh yeah, OCaml is supposed to be a very good FP. There are too many names to go through here - Lisp, Scheme, OCaml, Haskell, and even [F#](http://research.microsoft.com/projects/ilx/fsharp.aspx) (which by the way is now at 1.0 stage) and [Nemerle](http://nemerle.org/) (which runs on Mono)!

Pramode says:

Best way to start out in FP is with Scheme and the textbook
`Structure and Interpretation of Computer Programs' - I have
taught a bit of it in class (whatever little I understood) and
find it to be really great for intellectual nourishment. Most of
the Scheme stuff can be translated to straightforward Python
(http://linuxgazette.net/109/pramode.html).

Swaroop C H says:

Wow, Pramode, thanks a lot, your article is really useful! :)

Sriram says:

Have you seen this blog post from me? http://dotnetjunkies.com/WebLog/sriram/archive/2004/10/14/28543.aspx . Read SICP - but learn Haskell too..probably the cleanest implementation of FP

Swaroop C H says:

Cool! Sriram, you have written a post on FP long ago :)

Looks like I'm just late to the party :|

Anyway, I'll be reading your blog post soon, thanks!

Eugene Wallingford says:

I second recommendations above for Scheme, SICP, and Haskell. All will teach you much. Back when I dove deeper into functional programming, I found this article to be really useful:

http://www.md.chalmers.se/~rjmh/Papers/whyfp.html

You'll have to work your way through it slowly, but there are a lot of neat ideas there.

Feedback

There's no comment box, but please do email me or tweet me your thoughts and criticisms, and I will publish the relevant ones here.