Wednesday, October 20, 2010

Inching towards functional programming

My recent work has been in object-oriented programming, but I'm interested in functional programming. I've read about it, talked with people about it, and I think it has a lot of promise. But working on it is tricky. The "regular work" during the day is in object-oriented programming, due to the tools, existing code, and talent of the rest of the team.

Despite the limitations, I can take some aspects of functional programming and use them in plain object-oriented code. Today I worked on the aspect of immutable objects. I've been designing (and re-designing) some classes, and I have been designing them to use immutable objects. The exercise has been enlightening, and I have gotten a better design out of it too.

So my recent efforts have been, effectively, to gradually transition from object-oriented programming to functional programming.

I followed a similar strategy when I moved from procedural to object-oriented programming. At the time, I was working in C. The client's shop was heavily regulated (by internal folks, not the government) and the corporate standards group strictly controlled the software installed on their PCs. (They still strictly govern software.) This was also prior to the great revolution of the internet, the web, and the open source movement. Acquiring software was harder (and more expensive) in those days.

I started my move from procedural code to object-oriented code by doing three things: reading about it, attending conferences, and programming in the style of object-oriented programming with the tools we were allowed to use. I didn't create anything as elaborate as the cfront compiler. Instead, I designed function calls that worked like object-oriented code. I called it "thing-oriented programming", and it was somewhere in between procedural programming and true object-oriented programming. Like today's efforts, it was enlightening and gave me better designs.

I'm excited about the future of functional programming. And with the internet and open source efforts, I should be able to try some real functional languages at home. The biggest challenge there will be time.



No comments:

Post a Comment