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

Re: RFC: pragma pragmatic

by BrowserUk (Patriarch)
on Aug 09, 2017 at 08:39 UTC ( [id://1197078]=note: print w/replies, xml ) Need Help??


in reply to RFC: pragma pragmatic

Many moons ago, I implemented a 'say' keyword into the 5.8.something sources and offered it to p5p. Their response was that it needed to be explicitly enabled by the programmer to avoid clashes with existing code that used 'say' as a sub name. So, I implemented that. Their response was, the scoping needs to be lexical, and the mechanism for lexical scoping needs to be generic. I got the NIH message and gave up.

About 5 years later Perl finally got the say keyword with 5.10, and the use feature pragma was the mechanism to enable it's lexical scoping.

To this day, I've never seen anyone, anywhere use use feature qw[ say ]. Everyone who uses say, uses the "use 5.010;" or later global-scope enablement.

Now I've said that out loud, I'm sure that they'll be one or more pedants pop-up claiming they always use use feature qw[ say ]; and all those other things it can optionally enable -- that noone can remember what they are -- explicitly at the closest possible scope in every program and module they write, lording the virtues of clean namespaces...

but can anyone tell me the benefit of getting to the end of a programs run with a clean namespace? Do I win an environmental award or something?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Replies are listed 'Best First'.
Re^2: RFC: pragma pragmatic
by hippo (Bishop) on Aug 09, 2017 at 09:36 UTC
    Now I've said that out loud, I'm sure that they'll be one or more pedants pop-up claiming they always use use feature qw[ say ]; and all those other things it can optionally enable -- that noone can remember what they are

    Hello! That's me (the pedant).

    The reason which I (albeit rarely) use feature 'say'; is that it means I don't have to remember which version of perl introduced say. As a bonus it's also self-descriptive - when I come back to such code in 6 months I don't have to think, "Why in Hades did I use 5.010; here?", although a comment would work just as well. FWIW I don't recall ever using use feature for anything other than "say", so we can agree on that part at least.

      Hello! That's me (the pedant).

      :). Your reasoning is sound.

      Having hankered for say enough, that I took the time to learn enough about the sources that I could add a say keyword; when it eventually came I tried to train my fingers to use it, but in the end, just gave up and went back to print and -l on the shebang line.

      My point was mostly that even when people do use feature qw[ say ];, they use it at global (file) scope. I've never seen anyone use it lexically.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
Re^2: RFC: pragma pragmatic
by Corion (Patriarch) on Aug 09, 2017 at 08:44 UTC

    I think the idea of a clean namespace (via namespace::autoclean or whatever) is that you don't get methods in your objects for helper subroutines that you imported in your class.

      namespace::autoclean is a module I've never had the need for.

      If users of my OO modules -- and yes, I've written a few of those :) -- are diligent enough to look inside my modules and notice it has some undocumented methods imported from modules it uses, and they work out why and how to call them, that's fine by me. And if no one looks, those undocumented methods in the modules namespace, do no harm outside of it.

      But then, I don't use Mooose, and I guess it needs all the help it can get. I guess it is conceivable that the presence of extra names in a modules stash could slow down specified method call lookup -- though I doubt anyone could measure the difference -- but then, I guess Moooose needs all the help it can get in that regard also. I also assume that the cleanup might return some memory to the runtime pool, though you wouldn't guess it from the size of every piece of Mooooose code I've ever seen :)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

        The best reason I've seen for autocleaning a namespace is to prevent imported functions from being accidentally called as methods by a class's user. I can't remember seeing that problem myself, but something around the JSON module is tickling my mind.

        Hi,

         use Wx qw(:everything); imports about 3.2MB worth of constants/"macros", so you can type (as in C++) wxDefaultSize instead of Wx::wxDefaultSize() and EVT_MENU(...) instead of Wx::Event::EVT_MENU(...)

        Some guys prefer namespace::autoclean to typing a few extra Wx::/Wx::Event::

Re^2: RFC: pragma pragmatic
by ikegami (Patriarch) on Aug 12, 2017 at 01:35 UTC

    First, use 5.010; is not "a global-scope enablement"; it's just as lexically-scoped as use feature qw( say ); (except for the version check, obviously).

    $ perl -e' > { use 5.010; say "foo"; } > say "bar"; > ' String found where operator expected at -e line 3, near "say "bar"" (Do you need to predeclare say?) syntax error at -e line 3, near "say "bar"" Execution of -e aborted due to compilation errors.

    Secondly, the need for say to be enabled has nothing to do with a need for "clean namespaces"; it's all about not breaking existing programs that have a sub named say.

      1. If you put X inside curlies, it is no longer at global (file) scope. NSS!
      2. Requiring say to be enabled is about backwards compatibility; making that lexical, is not.

      Pointless pedantry, and wrong on all counts. (You and sundial should team up, that'd be really entertaining.)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

        Requiring say to be enabled is about backwards compatibility; making that lexical, is not.

        That's not true. Limiting the scope of use feature is required to enable backwards compatibility. If the effect of use feature qw( say ); was global, the following would break:

        # script.pl use feature qw( say ); use Module; say Module::foo();
        # Module.pm package Module; sub say { "I say \"$_[0]\""; ) sub foo { say "Hi!"; } 1;

        If you put X inside curlies, it is no longer at global (file) scope.

        It's never globally scoped; it's always lexically scoped.

Re^2: RFC: pragma pragmatic
by stevieb (Canon) on Aug 10, 2017 at 22:48 UTC

    I too very infrequently use use feature 'say';, but it is always only used for testing. hippo had a good point for prod work if one doesn't remember which version included which feature, but I'm a bit different here. I've been reading perldelta since 5.8, so for things that stick, it's not often I forget which version contained what.

    My reasoning for selecting individual 'feature's is typically because I only need one or two to make it easier to do certain things in a test file while debugging specific problems. Given that I attempt to write all of my code to 5.8 compatibility, I specifically put in the feature I need explicitly, then remove it afterwards. In other words, I add the feature temporarily, use *only* it/them, then when the debugging work is done, remove the debug/test lines and the individual features.

    It avoids me from going overboard with newer features I didn't expressly use, and have to re-edit the specific file because I forgot things. If I haven't included a whole raft of features by using a whole branch, it's less likely I'll have additions I didn't intend later.

      Given that I attempt to write all of my code to 5.8 compatibility

      I never use feature, but I can't live without defined-Or (//), so 5.10 is a prerequisite for anything I right. There was a defined-or patch for 5.8 for anyone still stuck there.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
      In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

        If there was one feature from 5.10 that I'd use that tipped me over the edge to comply with 5.10+ in my code, it'd be defined-or.

        In fact, at least two of my distributions that I've had to bump up to 5.10 from 5.8 was due to defined-or being used in a required non-core module.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 22:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found