Thursday, June 26, 2008

FP + Rails

While extending a codebase for work today, it occurred to me that many of the annoyances I encounter while working in Rails are really just the result of incorrect abstraction choice. For instance, Rails has a theoretically very useful extension quote_value that throws quotes around the object that is passed to it. Unfortunately, this is not implemented as an extension to String or even Object, but to some moderately-difficult to access OO-abstraction. (think it might be Class) Were it just a globally available function, it would actually be useful all of the time, instead of when you're operating within the box.

Similarly, passing instance-level variables in models to class-level functions in the same model is very hard to do (as far as I could tell, impossible) without using the controller to function as a mediator that passes arguments.

This is really just an isolated aspect of a larger argument: OO sucks. Its suckage in this particular case is largely masked because Rails is very well designed for most tasks, but the suckage becomes quite apparent when you start breaking out of the standard Rails box.

Don't get me wrong: the Rails box is very nice. It is, however, still a box. It's possible that a concerted effort behind Arc could make something that is Rails-y by default while retaining the inherent flexibility of something written in a Lisp, but I'm not sure that it would be as useful as Rails is for web-dev. It seems like the hypothetical 'Arc on an Ark' platform would end up getting tweaked locally too much to actually be a meaningful standard, and I believe that to be a large part of the value of Rails: the silver lining on the box cloud.

In any event, I would argue that FP is the most useful of the various programming methodologies for a broad spectrum of use, probably in no small part because it encourages you to follow the (probably paraphrased/apocryphal) advice of Abraham Lincoln: "If you have four hours to cut down a tree, spend the first two sharpening your axe".

No comments: