Wednesday, October 27, 2010

Two more steps towards functional programming

I took two steps towards functional programming today.

First, I read a bit of "Pearls of Functional Algorithm Design", a book of essays on functional programming and modelled after Jon Bentley's "Programming Pearls" book. "PFAD" is written with examples in Haskell, and I have enough knowledge to follow the text but not enough for full comprehension. I'm not worried; my early experiences with object-oriented programming were similar. I plan to read up on Haskell a bit more, continue reading the text, and if I can find the time write some examples in Haskell myself.

Second, I continued my re-design of a program at the office, converting it to a modest form of functional programming. A very modest form. I call it "constructor programming", and attempt to push all code (well, all non-trivial code) into the constructor for objects. Using this techniques, I can use plain object-oriented languages (like C++ and C#) yet still get a feel for functional programming. (Or what I currently thing of as functional programming.)

The re-design work was helpful. It forced me to think about the classes and the true problem. I ended with a cleaner design, or so I like to think -- I have no measurements for complexity. (Come to think of it, I do have a utility to measure class interface complexity, and perhaps I should use that to measure my progress.)

I'm happy with the direction the code is taking. The code is clean and easy to understand. I think we could explain it to the business users and they would understand it. This is a big win, as the current system is quite opaque.


No comments:

Post a Comment