And that’s not just some long-haired hippie’s opinion. Wednesday night we had a mini-geek night at work and we got onto the topic of whether or not (code) magic was good or bad. It was a great conversation and because Ade doesn’t have a blog (when are you going to get one?), I thought I’d write about it.
I struggled at first to work out what we meant by ‘magic’ and we somehow concluded at some point, for it to be ‘the unknown’. For instance, when you plug stuff into the Rails framework, there’s some sort of ‘magic’ going on to hook it all up. The focus of the discussion was really about whether or not we thought magic was good or not.
To actually substitute our other meaning, ‘the unknown’ for magic makes the question a very strange one – ‘Is the unknown good or bad?’
My attempt at answering this question was that the concept of magic is not good or bad, but whether or not the attempt at magic is good or bad. In general, I personally like magic because it makes my life easier. I shouldn’t have to understand how the compiler, for instance, turns code I write into bytecode every time I want to do something. I like the fact that it just works and that’s how it is. The abstraction or illusion holds true every time I run it and I can depend on it to work day in and out.
I consider magic good if it doesn’t require you to understand it. Bad magic on the other hand is bad because it forces you to work out how it works, and that need, let alone the experience, is generally traumatising. It’s like a magician’s illusion failing us because you have to go behind the scenes to understand all the little tricks that made it work. What can make it worse is if it is difficult to investigate how it works such as the source code not being available, or horrible code that’s hard to read, or an abstraction that just doesn’t work.
All of this is circumstantial and really depends on how well the magic was built. If the magic works all the time (and generally that’s because the abstraction is sound) and it does all the things that you need, then I think it’s a good thing.
Nice post, I have debated this one a number of times. Unfortunately I think there are an awful lot of bad magicians out there, so magic almost always causes some pain. The exceptions, like Rails, become famous very quickly.
Thanks for your comment. I agree that there are many bad magicians out there, but I think we should all strive to make them better instead of deem magic bad!
Its not what the magic does and how well it does it. But that it is repeatable and predictable and that the interface is good.
If the interface to the compiler is that you can javac , and you get errors and warnings that point you to the problem so you can fix it, then the amount of magic you understand is just enough to converse with the interface to do the job you want to do. You can find out exactly what the error means, you can jump to compiler docs quickly.
Similarly, with an API that provides you with some magic, is the interface consistent? Does it suit your needs? I am more concerned with the interface in the case of the magical. Although to be honest my favourite kind of magic is the kind that is self-explainatory, what I mean is that while it does magic for you, if you want to understand it, you only have to look closer. For me this means having available source code. So JIDE is bad because I cant read the source, whereas Hiberante or Acegi is good because I can. Not that the Hibernate interface is perfect but the gist is the same.
Magic needs to do something predictably, provide a flexible and SUITABLE interface, and be transparent (should you need to lift the hood).