ETOOMUCHMAGIC
Posted: Fri, 12 December 2008 | permalink | No comments
I'm a fairly big fan of the Rails web development framework; it uses a programming language I quite enjoy using, and deals with the "bureaucratic" overhead of writing a web application with minimal fuss, leaving me to think about the things that matter -- my application's functionality.
To achieve this wonderous feat[1], Rails has a healthy injection of magic in the codebase, to do all sorts of interesting things, like autoload missing constants, and make intelligent guesses about what I want to happen in various situations.
The problem comes when you want to reuse this magical code for something
else. I'm working on a project at the moment where a bunch of the utility
functions that are in the ActiveSupport gemlibrary would
come in real handy. Well, that's OK, it's a separate
gemlibrary from the rest of Rails, I'll just load it into
my app, and I'm away.
Or... not.
The problem is that it would appear that a lot of the magic in the library is mandatory. Regardless of whether I want your constant autoloading magic, I've got it. I also can't just easily pick-and-mix the parts of the ActiveSupport library that I want, because there's all sorts of dependencies between the different chunks of the code that aren't expressed the "right way" -- everything gets loaded in the top-level active_support.rb, rather than being depended on by the files that need the classes. This is arguably a bug in ActiveSupport, but it's not something that's likely to be real high on anyone's annoyance list (since in practice ActiveSupport is a part of Rails, and when you use it in Rails it works Just Fine).
So, to all programmers: magic is great, but be careful about excessive magic. In particular, don't make magic happen in places that the user didn't ask for, and allow people to turn off your magic when it's counter-productive to their purposes.
[1] This feat becomes
more and more wonderous to me every time I look at the other available web
development frameworks out there, especially ones in other languages.
Despite having Rails to rip offtake inspiration from,
they still seem to require a lot of boilerplate to achieve their
goals. While there's a limited amount of boilerplate stripping you could
do for a C program, Python people keep telling me that their language is
just as powerful as Ruby -- and yet all the Python web framework usage I
see is chock full of unnecessary cruft.
Post a comment
All comments are held for moderation; markdown formatting accepted.