3 ms·
> I tend to use the word magic for those situations when you can not easily examine the source code and follow the control flow. Reminds me of the quote “In Sm
by braythwayt 11y ago
> I tend to use the word magic for those situations when you can not easily examine the source code and follow the control flow.
Reminds me of the quote “In Smalltalk, everything happens somewhere else “—Adele Goldberg.
I call these kinds of things, “action-at-a-distance,” or if I’m feeling snide, “COMEFROM code.” The thing is, action-at-a-distance is exactly what I want when I’m trying to separate concerns.
In Rails, for example, you can decorate a controller method using `before` at the top of a controller. To the person unfamiliar with the spell, this makes perfect sense:
def index
authenticate_current_user
render something_or_other
end
But this is magic:
before authenticate_current_user, only: [:index]
# ...lots of code...
def index
render something_or_other
end
That is perfectly grep-able if you know to grep a method name, and if you have a small controller class it ought to stand out, &c. &c., so it rarely offends. But it’s still magic.
It’s a win if we want to make our index method as simple as possible.
And that goes for all of Rails, really. The very idea of “convention over configuration” is a wholesale embrace of magic. In Ember:
userService: service(),
How is it that if you write `service()` without naming a service, the function defaults to the name of the property it is bound to? That makes absolutely zero sense in JavaScript, and the more you know about JavaScript, the more magical this becomes.
There is, in fact, no way to find the code that does this unless somebody whispers in your ear that Ember does compile-time chicanery, and you aren’t really programming in JavaScript, you’re programming in Ember, a language that has a lot in common with JavaScript, and that compiles to JavaScript.
You can decide for yourself if this is a win. Lots of people like it.