5 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. For instance, you are in some par
by jerf 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. For instance, you are in some part of the code and you have a User object and you see the code calls the .babble() method on the object. You go to the User definition, and there's no babble method. You follow up the superclasses, and there's no babble method. Where did the babble method come from? Where is it going? Who created it? Where can I find the documentation for it (if any)? Even if I do find something that seems to implement it, can I be sure that some other code didn't fiddle with the babble method in another way?
Languages permit varying levels of this sort of magic, ranging from the Ruby extreme of dynamically rewriting classes and inheritance hierarchies on the fly, to the pretty-much-no-magic of C. (C qua C anyhow. Preprocessor can get fun.)
I think this is one of the worst sorts of magic, and I've generally tried to arrange my code so that even when I'm using a dash of magic, the pathway back to where everything came from is still fairly clear. (Usually this can be done just by dealing with the fact you may need to use a few more keystrokes to leave the breadcrumb trail back to the implementation. Sometimes simplifying a bit of functionality down to zero bytes in the source code is going a step too far.)
I'll also observe that having used a number of both high-magic and low-magic languages, in terms of costs/benefits, I am generally underwhelmed by the benefits of the magic, and find the cost generally go up more quickly than most people realize as source code size goes up. I generally prefer low-magic languages. With just a bit of thought, you can still get a huge amount of power without the costs. (For instance, believe it or not, Haskell is a nearly-zero-magic language by this definition. For all the crazy stuff it seems to be able to do, you can always see what's going on just by following back the symbol definitions, with the exception of just a finite bit of syntax sugar implemented by the compiler, the most important of which is generally tutorial-level.)
- beachstartup 11y agothe problem is when you use magic, you're deliberately being clever, and the only proper way to be clever is if you thoroughly document your cleverness with comments and diagrams and examples. the person you befuddle with how clever you are is probably yourself, 2 years from now.
- StavrosK 11y agoEh, try a month.
- MaulingMonkey 11y agoLater today: Wait, what was I doing again?
- StavrosK 11y agoWhat is this in reply to?
- andrewflnr 11y agoI think they were raising your "try a month" to "try 6 hours".
- MaulingMonkey 11y agoCorrect. Thanks!
- StavrosK 11y agoYes, and I was re-raising it to "five minutes" :( Apparently the joke wasn't very obvious.
- SixSigma 11y agosee - Lions' Commentary on UNIX 6th Edition, with Source Code [1] [1] https://en.wikipedia.org/wiki/Lions%27_Commentary_on_UNIX_6th_Edition,_with_Source_Code#.22You_are_not_expected_to_understand_this.22 https://en.wikipedia.org/wiki/Lions%27_Commentary_on_UNIX_6t... /* * If the new process paused because it was * swapped out, set the stack level to the last call * to savu(u_ssav). This means that the return * which is executed immediately after the call to aretu * actually returns from the last routine which did * the savu. * * You are not expected to understand this. */ if(rp->p_flag&SSWAP) { rp->p_flag =& ~SSWAP; aretu(u.u_ssav); }
- s_kilk 11y ago> you see the code calls the .babble() method on the object... Where did the babble method come from? I call it "grep-resistant programming"
- deleted 11y ago[deleted]
- rasur 11y agoSmalltalk would help with this kind of magic. The Smalltalk Method finder is (British-English School-yard definition of) Magic ;)
- 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.
- Justsignedup 11y agoExactly. I use the term a lot with fully dynamic code without extremely strong documentation every step of the way. With 10 layers of dynamic invocation (typical in Ruby on Rails) it is almost impossible to know without a debugger what code path your code will take.