News for hackers. Stuff that matters.
Re:Why the Latest Rails Exploit Is Indicative of a Bigger Pr... by vidarh on Thursday February 14, 2013 @02:47PM (#5221668)
First of all let me make it clear that I'm not against all "magic", but let me address this:

> But isn't this the whole point of a framework? That stuff gets done for you so you don't have to write everything from the ground up?

There is a vast difference between a framework that does stuff for you when you explicitly ask it to, and where what happens is fairly transparent, and a framework that does stuff for you because of code that without knowledge of the framework looks fairly "inert".

E.g. calling methods to define attributes and attribute-accessors on a class that maps to a database is not magic (though depending on how extensive, you might argue parts of what a specific ORM does in that case is): The code makes it plain that something will happen, and unless the naming of the method is atrocious, a developer will have a good shot at guessing roughly what from the code itself. You can make a framework that does a lot for a developer while still being explicit like this.

Automatically defining attributes pulled from the database based just on including a module, or inheritance, on the other hand, is well into "magic" territory: Not only might it not be clear it's going to be pulling stuff from the database and define lots of attributes for you, you don't know what it will define at all without looking at a schema that might not even be available together with the code, and that might change independent of the code.

It's not an either-or, but a sliding scale, and what is magic to some will be plain and obvious to others (the Arthur C. Clarke quote springs to mind). E.g. "everyone" who knows Active Record will know at least the basics of what Active Record will do to your class, and so won't be surprised by most of the method that to another seemingly magically materialize on it.

The trade-off is how far you go before the surprises to your target audience become too many.

There are no comments on this comment yet.