Main article: Referential transparency
"Magic" refers to procedures which make calculations based on data not clearly provided to them, by accessing other modules, memory positions or global variables that they are not supposed to (in other words, they are not referentially transparent). According to most recent software architecture models, even when using structured programming, it is usually preferred to make each function behave the same way every time the same arguments are passed to it, thereby following one of the basic principles of functional programming. When a function breaks this rule, it is often said to contain "magic".
A simplified example of negative magic is the following code in PHP:
While the code above is clear, if it is seen in a large project, it is often hard to understand where the function magic() gets its value from. It is preferred to write that code using the following concept:
Any SV [scalar value] may be magical, that is, it has special features that a normal SV does not have.— Larry Wall, perlguts manual page,1 Perl 5
Any SV [scalar value] may be magical, that is, it has special features that a normal SV does not have.
This definition of magic or magical can be extended to a data type, code fragment, keyword, or machine address that has properties not shared by otherwise identical objects. The magical properties may or may not be documented.
"perlguts – perldoc.perl.org". 5 October 2014. Retrieved 18 February 2015. http://perldoc.perl.org/perlguts.html ↩
Banahan, Mike; Brady, Declan; Doran, Mark (1991). "9.10.3 The stdio.h header file". The C book: Featuring the ANSI C standard. The Instruction Set (2nd ed.). Wokingham, England: Addison-Wesley Publishers. p. 234. ISBN 0-201-54433-4. It is not safe to copy these objects within the program; sometimes their addresses may be 'magic'. 0-201-54433-4 ↩
"perlop – perldoc.perl.org". 7 September 2010. Retrieved 17 February 2011. http://perldoc.perl.org/perlop.html ↩
"27. Keywords" (PDF). BBC BASIC Reference Manual (1st ed.). Cambridge, England: Acorn Computers. October 1992. pp. 229, 349. ISBN 1-85250-103-0. Retrieved 9 May 2007.[dead link] 1-85250-103-0 ↩