Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

What does it mean for a Perl feature to be Magic?

by Elliott (Pilgrim)
on Oct 12, 2001 at 19:02 UTC ( [id://118492]=perlquestion: print w/replies, xml ) Need Help??

Elliott has asked for the wisdom of the Perl Monks concerning the following question:

I'm always reading that such-and-such a Perl feature is "magic" or "automagic". Can someone explain what this actually means? Or would that spoil the magic?

Replies are listed 'Best First'.
Re: What does it mean for a Perl feature to be Magic?
by perrin (Chancellor) on Oct 12, 2001 at 20:00 UTC
    It means that that feature is implemented by NBA star Magic Johnson. Whenever Perl executes "magic", it is actually sending an RPC call to a remote receiver implanted in Magic himself. He computes the answer, and then sends a return message. The use of Mr. Johnson for all the hard parts of Perl provides a great abstraction layer and simplifies porting to new platforms. It's way easier than, say, the Apache Portable Runtime.

      Wow! And there was me thinking that it was David Blaine. I thought that's why everyone's systems froze when he did his block of ice trick last year?


      Examine what is said, not who speaks.

      That also might help to explain how Magic Johnson seems so slow on the uptake, at times. Apparently, much of his braincycles are being preempted by Perl interpreters.

      Now I know, and knowing is half the battle.

      - apotheon
      CopyWrite Chad Perrin

Re: Magic
by merlyn (Sage) on Oct 12, 2001 at 19:14 UTC
    There are two types of "magic" references in the Perl documentation.

    There's a general "handwaving" magic, where the author isn't really interested in describing the (probably bizarrely complicated) mechanism by which a particular process happens. In this case, the magic is knowable, but you probably won't need to know, or even want to ask.

    There's also a specific "magic" bitfield attached to every symbol table entry inside. This bitfield records unusual properties about that variable. For example, a tied variable needs to be able to announce that something unsual will happen when it is fetched or stored, so the "tied" "magic" bit is set, and checked by those accessing mechanisms.

    So yes, there's "magic" you don't want to know, and there's "magic" that actually means something very specific. Hope that helps.

    -- Randal L. Schwartz, Perl hacker

      There's actually a third, lesser known type of magic that's not mentioned directly in the Perl reference material. This type is known as magick. It's not something you want to know about, and it's not something you can put your finger on. Only a very few people are able to fully comprehend everything about this dark and mysterious art, and those that do generally go doolally within a few days of understanding. Some people go insane even after recognizing that it even exists.

      There's a school of thought that says that magick is the life force of programming languages. They believe that if magick can be mastered, then the secrets of human understanding itself will be revealed.

      Another theory held by some is that magick is the dark side of programming, something to be left well alone and not interfered with. They claim that by attempting to control something as powerful and dark as magick, we could set loose things beyond anyone's control.

      Whatever the real nature of magick is, be warned: many have tried, and failed disastrously, to discover its workings.

Re: Magic
by suaveant (Parson) on Oct 12, 2001 at 19:08 UTC
    I believe Arthur C. Clarke said it best...
    "Any sufficiently advanced technology is virtually indistinguishable from magic."
    Basically perl is so great at doing some things, that one would almost think that it does things magically, when really just a LOT of thought and effort has gone into its design behind the scenes...

    Automagically is really just a cute term for automatically, but again a lot of things are often done behind the scenes that, if you don't understand them, can seem quite magical :)

    That's about the size of it...

                    - Ant
                    - Some of my best work - Fish Dinner

      Or, as Heinlein said: "One man’s magic is another man's engineering."

      Guildenstern
      Negaterd character class uber alles!
Re: Magic
by mirod (Canon) on Oct 12, 2001 at 19:26 UTC

    The most immediate "magic" in Perl is usually the result of the deliberate DWIM-ism (Do What I Mean) of the language: the interpretor goes out of its way to do what people expect it to do, even though that might not be the real logical thing to do.

    2 examples:

    • in regexps the $ matches the end of the string... or a \n and the end of the line, try it: perl -e' $foo="toto"; $bar="tata\n"; foreach ( $foo, $bar) { if( m/^t.t.$/) { print "$_ matches\n"; } }'
    • autoincrementing: the interpreter tries real hard to make sense of the content of the variable and return a meaningfull value:
      perl -e 'foreach my $foo ("1", "A1", "AA", "A001", "A009", "A999", "Z +", "AZ", "ZZ", "Z999") { my $bar= $foo; print "$bar++ = "; $bar++; p +rint $bar , "\n"; }'

    There are more. In fact Perl goes beyond trying to "make the easy things easy", it tries real hard at "making not-so-easy things look easy". That's Magic!

    There are of course other kinds of magic: tie-ed variables look like ordinary variables but behave magically (of course, as they have set the "Magic bit"), then there are deeper kinds of magics, but you will have to attend Dominus classes to learn them...

Re: What does it mean for a Perl feature to be Magic?
by Albannach (Monsignor) on Oct 12, 2001 at 19:26 UTC
    You will find a good thread on this exact question in What is Magic ?

    Super Search is your friend! ;-)

    Update: Well taken tye, but in this case I was fairly certain of both where the thread was and when it was posted so I was able to narrow my result list nicely ;-)

    --
    I'd like to be able to assign to an luser

      ++Super Search but don't jump right to it. Just putting "magic" into the search bar at the top of the page and scanning the results might have been enough in this case. (:

              - tye (but my friends call me "Tye")
Re: What does it mean for a Perl feature to be Magic?
by gryphon (Abbot) on Oct 12, 2001 at 19:39 UTC

    Greetings Elliott,

    Many here have already posted good definitions of what programming "magic" may be. However, I think there is an important distinction between "general magic" and "Perl magic" that needs to be addressed.

    In the world of "real" magic (i.e. those various "tricks" and such used by professional non-IT magician entertainers), there is an unwritten law forbidding the sharing of the secrets behind the magic. As a professional magician, you are called on not to tell anyone how your tricks work. It is of paramount importance in that community to protect these secrets from public view.

    In the Perl universe, the complete inverse seems to be true. There seems to be an unwritten law stating that as a Perl hacker, your duty is to do you best to explain your "magic" to others (so long as they don't expect you to code everything for them). The desire of a hacker to share knowledge of the "how to" behind the complicated and often amazing "magic" is often considered a virtue.

    My observations of other language user groups around lead me to believe that most if not all other language centers live philosophically somewhere between the two extremes.

    -gryphon
    code('Perl') || die;

Re: Magic
by bluto (Curate) on Oct 12, 2001 at 19:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://118492]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-19 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found