Sunday, February 10, 2008

The Set of All Truths

Boolean algebra is definitively out of fashion, really. Set theory returns wrapped in glory! Don't believe me? Let's see...

Everybody that I know outside of computer science tend to assume a lots of mathematics is involved while programming, when in reality we are doing algorythmics. Obviously we do some algrebra and in the past, there was a lot of boolean algebra but times are changing, for the better. What is the main use of boolean algebra?  Control flow, stop condition, exception etc... All things that procedural and OO use a lot.

Functional programming on the other end tends to have a lot less control flow instruction as there is usually a better separation of concerns between transforming an item and working on collections. This is even truer for lazy language since identity for series or stream can be used without polluting them with "stop condition". This separation of collection processing and single transformation is what brings back set theory to flavor of the day. (Just check C# 3.0 Linq if you are not convinced!)

In FP we tend to write our set of single instance transformers and our set of collection processing facilities. Most of the time I feel like I'm using tools from both palettes to assemble new solutions. Oftentimes I find myself playing with sets of data transforms with other sets, filtering, taking difference between sets etc.

And this is true both in Haskell or Common Lisp in my experience.

On the other hand there is usually so much boilerplate code to be repeatedly done and control flow in procedural programming that the "set" nature is not readily apparent.

I said to a friend lately that Haskell was nice but very hard to work with when one is tired compared to say C++. And it somehow make sense, you are rarely dealing with boilerplate or skeleton code in Haskell. It feels like you are always working in on the problem devoid of distraction. I guess you could say that's a nice aspect of C++ even tired you "feel" productive as there is so much banality to type to get to the essence of a problem :P

Cheers and brush up your set theory skills, the functional storm is coming :)

No comments: