Flickr Badge

Friday, September 03, 2004

How to Design Programs - MIT Press

Yesterday I had blogged about the books I couldnt find in Bangalore (Programming Pearls and The Practise of Programming). Today I'm going to blog about one of the books I did find (the rest will be in subsequent posts).

That book is "How to Design Programs" from MIT Press. I had been looking out for the book, having read a part of the online version of the book (available here). Little did I expect that it would be available in India. Well, surprise of surprises, I ran into a single copy of the low cost reprint of the book, and didnt hesitate in snapping it up.

The book is interesting because it uses PLT-Scheme to discuss program design. For those unfamiliar with Scheme, it is one of the Lisp derivatives. Teaching program design in a functional language leads to some interesting approaches. For example, you might expect material on variables and how to use them to appear in the first couple of chapters. In fact, variables are introduced right at the end of the book well after the discussion on recursion, graphs, algorithm analysis and data structures. This is because functional languages, being optimised for recursion and function calling, can often use a function call instead of using variables.

To give an example take the following java snippet -


public int func(int a, int b) {
a = 4+3;
b = 3*a + 7;
return a+b;
}


the equivalent structure using the standard scheme design will be -


private int calcA() {
return 4+3;
}

provate int calcB() {
return 3*calcA() + 7;
}

public int func() {
return calcA() + calcB();
}


Notice the lack of variable use. One of the big advantages of such a design is that the program readability - provided you use good function names - is vastly improved. Its an interesting way of thinking which is not apparant to someone who does not have experience with functional languages. Overall, it is an interesting book, and well worth reading. Since the whole book is available online for free, no one should miss out.

Which brings me to my next point. Every programmer should have at least a passing introduction to the four main programming paradigms - imperative programming, object-oriented programming, functional programming and logic programming. This provides a broad scope with which to solve problems, as often solutions can be applied between paradigms; object-oriented design for C programs being a classic example.

It is a pity that Indian universities often teach only what is required by the software companies. This usually means Java with a touch of C by the side. The end result is that the graduate can do his job, but it is rarely creative. Standard formulae are applied to standard solutions by a mass of programmers (quantity over quality?) resulting in something that works, but is rarely innovative. I would like to say more on this, but thats a topic for another post.

In any case, the point I am trying to make is to urge you to go and read the book online, for free, as a good foundation in functional programming does help a lot.

2 comments:

Sachin said...

well said K. :)

I was looking for this book Code Complete 2 ed. in Delhi and god what kinda city this is. Either I donot know where to look or this city just sucks when it comes to finding good books on Software (no and I am not talking about books like "how to ... in 21 days")

what else going on ?
Sachin (sachin.sharma@gmail.com)

Siddhi said...

Actually Code Complete 2 is not yet out in India. The low price edition has not yet been printed, and will most likely not be printed for a while. I'm reading the import edition which I got in Singapore. If you're really desperate, I suppose you can ask the bookshop to import the book, they will probably do it for you.