Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: Pointers and References

by GrandFather (Saint)
on Nov 23, 2020 at 22:02 UTC ( [id://11124085]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Pointers and References
in thread Pointers and References

I almost never use our. Usually when I say global I mean global to the file and I might prefix the variable name with a g. our tells you something is "global" where you declare the variable, but it doesn't tell you that where you use it. You tend to use a variable much more often than you declare it so the ugliness of a g prefix is an immediate and obvious reminder at the point of use that this is a global variable.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^6: Pointers and References
by LanX (Saint) on Nov 23, 2020 at 22:17 UTC
    Your coding style is peculiar, probably C'ish? ;)

    > our tells you something is "global" where you declare the variable, but it doesn't tell you that where you use it.

    I have problems to follow. our $var creates a lexically scoped alias to a package variable $PKG::var whith PKG for the current __PACKAGE__ . If you are afraid to loose count "where you use it" just limit the scope, much the same way you do with private vars declared with my.

    > of a g prefix is an immediate and obvious reminder at the point of use that this is a global variable.

    Then maybe consider full qualification instead of a g_ prefix.

    Using $PKG::var is IMHO much clearer, and $::var is a handy shortcut for $main::var

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      C++ish I'd accept (but see the list of languages I've worked with on my home node).

      Perhaps I was being too specific when I said "our tells you something is "global" where you declare the variable". I was more intending to suggest that using an identifier over a wide scope puts more onus on the identifier to convey meaning and that any amount of "documentation" at the point of declaration doesn't help at the point of use. A simple g prefix is a heads up that this variable has large scope: beware, here be dragons. Most of the time the extra markup to convey that the variable hails from some package or another is unnecessarly heavy handed and doesn't add much value anyway.

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124085]
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-04-23 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found