Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Sigils in Perl 6

by db4n (Initiate)
on May 14, 2007 at 16:55 UTC ( [id://615381]=note: print w/replies, xml ) Need Help??


in reply to What's wrong with Perl 6?

What's the purpose of the sigils now? When I first learned Perl, I assumed they served some function I didn't quite understand. They contained context information not conveyed by the braces or brackets in the expression. But the new ones seem like gratuitous ornaments. They seem redundant.

What I like about Perl is that it's designed for fairly experienced/capable programmers instead of being optimized for complete beginners (P4E). Even in Ruby you have to keep typing "end" all the time. Yuck. I've sort of held out hope that Perl6 might take back the scripting-language market for programmers who don't need so much hand holding, but I wouldn't mind getting rid of any unnecessary historical cruft.

--Dan

Replies are listed 'Best First'.
Re: Sigils in Perl 6
by philcrow (Priest) on May 14, 2007 at 17:16 UTC
    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.
      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-23 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found