Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^6: On Backwards Compatibility and Bareword Filehandles

by jcb (Parson)
on Jul 20, 2020 at 00:35 UTC ( [id://11119531]=note: print w/replies, xml ) Need Help??


in reply to Re^5: On Backwards Compatibility and Bareword Filehandles
in thread On Backwards Compatibility and Bareword Filehandles

package variables are global, which means visible everywhere.

Close — fully-qualified names are visible everywhere, but most "global" variables are implicitly scoped to the current package.

File-scoped lexicals are still lexically-scoped. They aren't seen outside the file.

If a 1:1 correspondence between files and packages (as is convention) is maintained, those are equivalent, with the exception that you can refer to a package "global" variable from elsewhere if you specifically do so. In terms of "accidents", the risks for a package variable and file-scope lexical are very similar.

  • Comment on Re^6: On Backwards Compatibility and Bareword Filehandles

Replies are listed 'Best First'.
Re^7: On Backwards Compatibility and Bareword Filehandles (Orthogonality)
by LanX (Saint) on Jul 20, 2020 at 01:24 UTC
    I spend much time training colleagues in Perl.

    I'm pretty happy when they understood scoping rules and follow the basics of declaring with my.

    And believe me, nobody there thought much about using package before I started there.

    There is simply not much room to tell a beginner about all the specialties of a package scoped bareword, which needs to be treated with local, the internals of type-globs and how to pass them around as reference with \*FH .

    Yes Perl has many ways to do it and it's impressive how I can always come up with a nifty trick to fix the sins of a 15 year old code base.

    But orthogonality rules, they don't need to learn how to use a baseball bat to drive a nail into the wall, if there is a hammer called my $FH and they already learned to use that hammer with many other nails ...

    And there is no issue with "backwards compatibility" whatsoever!

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

      To be clear, I am content with the status quo, but it seems that there is an effort afoot to remove bareword filehandles entirely, and I present this proposal as an alternative change that will cause less breakage than the previously proposed change of removing the feature entirely. I do not think that I can get indefinite continuation of the status quo, so I make this proposal as a "next best thing" from my perspective.

      You raise a good point that existing code expects to be able to pass a reference to a bareword filehandle with \*FH. The parser could still accept that syntax and consider it another form of {I/O}FH, but the \* would no longer be required. This would allow passing filehandles as arguments to I/O builtins and user subroutines equivalently.

      I am not saying that my $FH should stop working, only that "plain" filehandles should become equivalent to that in preference to being removed entirely. I also see some opportunities to simplify the interpreter guts along the way, which is a suitable justification for change, especially when efforts are made to maximize compatibility with existing code that does not use my $FH, as this proposal seeks. Since you mentioned that even package was not being considered at your workplace before you started, how likely are there to be other places where my $FH is still entirely unknown? How much code will they have?

        > seems that there is an effort afoot to remove bareword filehandles entirely

        No, there isn't!

        Good night! :)

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

Re^7: On Backwards Compatibility and Bareword Filehandles
by ikegami (Patriarch) on Jul 21, 2020 at 02:39 UTC

    In terms of "accidents", the risks for a package variable and file-scope lexical are very similar.

    I didn't say otherwise. The fact that they have similar risks doesn't make them the same thing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11119531]
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: (3)
As of 2024-04-19 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found