A Definition of Magic in Programming Languages
The term “magic” is commonly thrown about in the programming world without a definition. This post gives a definition for it.
Not the definition, just a definition. As a long-standing fuzzy term, I can’t necessarily capture all uses of it in the wild, but I believe this captures a lot of the practical value.
Magic Definition
A piece of code is magic in proportion to:
- How many other places in the code must be consulted for a human to understand what it does.
- How difficult it is to know what code to consult based on an examination of the code in question.
You can think of it as being proportional to the amount of time that someone skilled in the language, but unfamiliar with the code base, would need to be sure they know what a given piece of code is doing, from the full source code alone. That is, no debugger or similar tools.