Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Sigils in Perl 6

by philcrow (Priest)
on May 14, 2007 at 17:16 UTC ( [id://615387]=note: print w/replies, xml ) Need Help??


in reply to Sigils in Perl 6
in thread What's wrong with Perl 6?

Sigils are good because:
  • The allow easier interpolation in strings
  • They tell you the type of the variable (hash, scalar, array), a little bit like hungarian notation, but enforced by the compiler
  • They keep your variables from clashing with reserved words, making it possible to safely add reserved words later without breaking existing code (or at least without interfering with variables in existing code).
Phil
The Gantry Web Framework Book is now available.

Replies are listed 'Best First'.
Re^2: Sigils in Perl 6
by TimToady (Parson) on May 14, 2007 at 20:06 UTC
    Well, those are all true to some extent in Perl 5 as well. In addition to those reasons, Perl 6 pushes sigils in a direction that makes more sense in the context of human linguistics:
    • Sigils distinguish nouns from verbs, which is especially important when you wish to talk about a verb as a noun. Many human languages require noun markers of some sort or other. (English is interesting in generally requiring plurals to be marked rather than singulars, but there is much linguistic precedent for requiring both.)
    • Sigils distinguish nouns from types and other adverbial notions, which helps the parameters in declarations stand out, and tells the compiler which parts of the declaration are intended as referential and which are intended to declare something new.
    • Your typical noun phrase will contain a single sigil somewhere, and that marks the "head" of a noun phrase. This makes it really easy to figure out where to start reading a noun phrase.
    • The sigils provide a "safe haven" namespace for twigils that mark extraordinary scoping in an immediately recognizable fashion. Unlike sigils, twigils can therefore have an unmarked form for ordinary $foo variables. Otherwise all the twigils would be confusable with prefix operators.
    I'm sure I could think of more reasons if I tried, but those are good enough. :-)
      For those as clueless as me: twigil
        And just to add something that is not explained at all in the synopsis, the idea of twigils is actually stolen straight from Ruby, which uses sigils to indicate strange scoping rather than data structure. A lovely idea, but using up sigils for that limits the extensibility of the mechanism, because there aren't that many ASCII symbols left to use in the sigil position that don't already mean something else. But by placing the scope indicator in the twigil position (that is, after a mandatory sigil), we can reserve the rest of the symbol keys on your keyboard to indicate future scopes that maybe haven't even been invented yet. Maybe someone will invent transaction scopes, for instance.

        So I think of twigils as just another way of making Perl more like Perl. As with sigils, the primary purpose of twigils is to give you, the reader, a visual clue about what's going on in a bit of code without having to memorize every declaration surrounding this scope. The moment you see something like $?FOO you can know that it's a variable to the compiler but a constant to the compiled code, without having to memorize a list of special symbols, or use weird non-sigil conventions like __FOO__.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found