Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When talking about programming languages, what is the definition of Magic?

The word "magic" gets thrown around a lot here in contexts like "language X just has too much magic", or "platform Y generally avoids magic". However, it seems the term is pretty poorly defined, something people know when they see it. For example, Java is reputed to contain very little magic, but its garbage collector hides a lot from the programmer. If magic simply means abstraction that hides details, then why is it considered a bad thing, given that nobody writes large programs in assembly language anymore? If magic means something more, then what does it mean?

like image 255
dsimcha Avatar asked Feb 28 '09 17:02

dsimcha


4 Answers

"Any technology sufficiently advanced is indistinguishable from magic" — Arthur C. Clarke.

Actually not quite that — magic is used for complicated and hidden rather than advanced (though presumably the designers thought they were being advanced), such as systems which require specific states before procedure calls (COM threading models) as well as 'automagic' type conversions (VB variants, Javascript ==, Java autoboxing).

Once systems hide details from the programmer that they are no longer predictable, they become magic. You're stuck with repeating an invocation in a language you don't understand because it's had the right effect in the past. That's bad magic, or voodoo.

There's also good magic — http://aggregate.org/MAGIC/

like image 86
Pete Kirkham Avatar answered Sep 28 '22 09:09

Pete Kirkham


Something is magic while you ignore it / you don't know how it works.

like image 22
mati Avatar answered Sep 28 '22 07:09

mati


At Microsoft this tends to be used two ways

1) In a negative way (probably the most common usage). For example, someone might say the following "I don't understand; first you will refactor the API, next you will keep the old API and have a layer between them that performs magic?"

The implication is that the magic component is too complex, too undefined, or too 'something'.

The other negative context is when something is defined naively: This often happens when someone assumes there is a simple solution to a complex problem because they do not realize that the problem is really complex. Raymond Chen's blog is full of these kinds of examples.

2) Its less often that the term 'magic' is used positively. But it does happen. Usefully to refer to things that perform complex tasks that just work. To me NTFS is that kind of magic. NTFS is really, really mature and hides a lot of complexity behind some pretty simple APIs. Compiler's can be seen as 'magic' in this way as well - do you really understand, deeply, how a C++ compiler works? I don't - I just trust that they do.

like image 31
Foredecker Avatar answered Sep 28 '22 09:09

Foredecker


Magic is very relative to your understanding.

I wrote a fair amount of C and C++ before I started writing in Java. I had to allocate and deallocate all of my memory. It wasn't a lot of fun once I started getting memory leaks. Once I started writing in Java, I knew (basically) what was going on behind the scenes in order to make all my instance objects. Thus, to me, it's not near as much magic (I've done allocation but how it actually stores objects and knows when to deallocate them is a little more "magical" to me) as it would be to someone who had started on Java (who has never had to manually handle memory.)

Another example is ORM. I rolled my own temporary Object Relational Mapping structure early in a project until I had time to really buckle down and learn Hibernate or something similar. I had to write in things like ResultSet mappers, Lazy Loading and some basic caching. Now, when I go back and replace this stuff with more mature Hibernate or JPA mapped entities, I'll still have a basic understanding of what's going on. If you've never used JBDC or anything similar, all you're going to really know is that the data goes from the database to the object and back again.

Everyone deals with a certain level of magic in their careers. We can't know everything. Magic really can be synonomous with Abstraction. When it becomes "too magic" is when the Abstraction begins to cover up things that you need to be able to control. An example the other day was that in a JSF program, I didn't know how to start a JSF context. JSF just does this when you navigate to a JSF page for the first time. I needed to start the context from a regular servlet. I ended up having to make a dummy JSF page to handle it instead. I simply didn't have time in this project to learn the "magic" of JSF context management.

like image 31
Drew Avatar answered Sep 28 '22 08:09

Drew