DEV Community

Cover image for Where do you stand on "magic" within languages and frameworks?
Ben Halpern
Ben Halpern Subscriber

Posted on

Where do you stand on "magic" within languages and frameworks?

Let's discuss the concept of magic β€” what are your opinions?

In the context of computer programming, magic is an informal term for abstraction; it is used to describe code that handles complex tasks while hiding that complexity to present a simple interface. The term is somewhat tongue-in-cheek, and often carries bad connotations, implying that the true behavior of the code is not immediately apparent. For example, Perl's polymorphic typing and closure mechanisms are often called "magic".

Oldest comments (40)

Collapse
 
brunoj profile image
Bruno

I hate it when I'm new to a framework and love it when I'm experienced with it. πŸ˜…

Collapse
 
katafrakt profile image
PaweΕ‚ ŚwiΔ…tkowski

Interestingly, I could say exact opposite. When I'm new, I just love all the things being done that I don't have to do myself. When I start to work in larger codebases, it causes a lot of problems with refactoring and general headache that I'm not in control.

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard • Edited

My view is that abstractions are a good thing, the bread and butter of programming. You don't generate your HTML in C with printf(), do you? But we also need to be aware that they can be leaky.

Twenty years ago: The Law of Leaky Abstractions

Collapse
 
ravavyr profile image
Ravavyr • Edited

I'd say you shouldn't be using C to build websites at all, that there are much simpler ways to write your html these days :)

But you're right, abstractions are good thing, but not when someone creates an abstraction layer for HTML tags to where your write _br() instead of < br > literally typing more characters to use an abstraction because some old timey dev was utterly insane. [true story, old tag library i had to use years ago]

Collapse
 
cerchie profile image
Lucia Cerchie

I don't like the term. Reducing complexity is hard work, not magic. It also removes all the developers from the idea that they can control the outcomes.

Collapse
 
calinbaenen profile image
Calin Baenen

It's fine because it can enable really cool behavior.
Þink Rust's interior mutability pattern Rc/RefCell.

Collapse
 
wjplatformer profile image
Wj

thorn!

Collapse
 
calinbaenen profile image
Calin Baenen

Correct.
I also you ðe highly underrated eð. (Ðough it doesn't look good wiþ ðe low resolution of ðe font DEV uses.)

Collapse
 
armousness profile image
Sean Williams

I only like magic when it's fully expressible within the language itself. For example, Rust has a println! macro that lets you put terms in the format string, and the terms are typechecked. However, Rust's macro system is available to the programmer, so you could reimplement println! if you were so inclined.

I guess the broader point here is, languages should focus more on allowing robust metaprogramming. Nearly all magic is metaprogramming, but this means in most languages you're stuck with the magic the language developers/maintainers thought you deserve.

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard

A possible issue is that the "magic macros" can confuse the hell out of the developer tools from the IDE.

For example Scala is more powerful than Java or Kotlin, but its IDE support is worse because of that.

TL:DR developer tooling matters

Collapse
 
fjones profile image
FJones

Couple of weeks ago, we had an old toplink-then-eclipselink-then-custom magic inferrence that caused all of our enum values to be offset by 1, so __I'll remain firmly in the "magic is bad" camp.

Collapse
 
besworks profile image
Besworks

I like to use the term automagically especially when describing things like Web Components to people. It's not really automatic which I feel implies no effort, but rather it's so advanced as to seem like magic to someone who doesn't get the how the abstraction works.

Image description

Collapse
 
fish1 profile image
Jacob Enders

I tried using .NET core MVC, (for a day). The framework is able to detect the classes you defined, link them to the HTML, magically create routes, and probably much more that I never was exposed to.

Coming from a C/C++ and NodeJS background, this level of abstraction is just uncomfortable to me. I like defining my Classes, instantiating my Object and then passing it to the framework to be used.

Just being able to define a class and have a website popup feels like I'm creating configuration files, not programming.

But too be fair, I do tend to write a lot of the same boiler plate setup code on every Node application I build.

Collapse
 
polterguy profile image
Thomas Hansen • Edited

The less you need to know about the code's internals the better encapsulation you've got. More encapsulation is a good thing since it allows us to move further up and do more with less. I think it was Paul Graham who said; "Always use the highest possible level of abstraction, since it allows you to deliver more with less". I insanely agree with this thinking, to the point where I arguably built my entire career around it, in implementing Magic - Literally ...

Magic is a good thing, always, think about it - All the best languages have high levels of magic at its core; SQL, HTLML, CSS, etc. The reason why these languages are great, is because you don't need to understand how they do what they do, you can just trust them to always doing it ...

Collapse
 
jzombie profile image
jzombie

It's hard to put a lot of faith in something that doesn't provide unit tests and code coverage. What may work right now may not work tomorrow after it gets hacked on.