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". The term implies that the hidden complexity is at least in principle understandable, in contrast to black magic and deep magic, which describe arcane techniques that are deliberately hidden or extremely difficult to understand. However, the term can also be applied endearingly, suggesting a "charm" about the code. The action of such abstractions is described as being done "automagically", a portmanteau of "automatically" and "magically".
Oldest comments (40)
I hate it when I'm new to a framework and love it when I'm experienced with it. 😅
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.
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
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]
I find that the most important feature of "magic" is that the tool needs powerful introspection. Emacs. has bonkers amount of magic available, and the introspection tools are top-notch. Similarly, Ruby has the ability to craft powerful magic (see Rails). Ruby also has powerful introspection.
So, if the tool uses magic, understand how to navigate the incantations. Those "magic macros" will save a lot of time.
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
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.
It's fine because it can enable really cool behavior.
Þink Rust's interior mutability pattern
Rc
/RefCell
.thorn!
Correct.
I also you ðe highly underrated eð. (Ðough it doesn't look good wiþ ðe low resolution of ðe font DEV uses.)
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 reimplementprintln!
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.
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.
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.
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.
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 ...
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.
It's an double edged sword. With Spring Boot in the Java ecosysteem, a lot can be auto configured. Just add a dependency, and a lot of classes wil be created and started for you. Once you need to change something, it can be hard to know where to change it. And when something goes wrong on startup it might not always be obvious.
There are a lot more types of magic, like macros or synthetic sugar, for which more or less the same counts. It's easy when it works, but it can be hard when it doesn't.
Magic is great. Until it doesn't work for your new use case. Then the "abstraction" rapidly becomes technical debt.
If you want to achieve software manufacturing -as in a repeatable and scalable industrial process- relying on relatively unskilled workers (aka juniors) to cut the cost, while still achieving high velocity or even some automation through code scaffolding, some "magic" is unavoidable. If you prefer artisan software development, resulting in an inconsistent code base, only understandable by the magicians themselves, by all means go ahead, but watch "The Sorcerer's Apprentice" first....
This is the dilemma of software engineering.
If your application or website rely a lot on frameworks or libraries then perhaps low code or no code would be the safer and faster way to go. Something such as WordPress allows user to use boilerplate templates and customize them.
Thank you for your feedback. As architects, we have a number of responsibilities: guarding non functional requirements, offering guarantees in the quality level of the output, providing tools that turn software development into software manufacturing, just to name a few. This is not limited to the front-end. In fact, the front-end is often the least of our concerns (cutting corners here, i know) and sure why not pick the path of least resistance there. But as for back-ends that handle huge amounts of events/data and/or need serious concurrency, core code that is tested through and through with minimal specific implementation is probably preferable.
Abstractions are great! In 2022 we don't boot our computers and literally have to type our program before running it... we came a long way from punch cards.
But any abstraction should be clearly documented and with the possibility to extend / customize. I hear a lot of complains from the folks using swift ui, so not a good example for that.
As the team works through putting COBOL onto Exercism I'm reminded about some of the declarative magic that COBOL provides. The thing I'm thinking about is 88 levels which can simplify code dramatically.