Re^2: RFC: pragma pragmatic
by hippo (Archbishop) 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.
| [reply] [d/l] [select] |
|
|
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.
In the absence of evidence, opinion is indistinguishable from prejudice.
Suck that fhit
| [reply] [d/l] |
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.
| [reply] |
|
|
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.
In the absence of evidence, opinion is indistinguishable from prejudice.
Suck that fhit
| [reply] |
|
|
| [reply] |
|
|
|
|
|
|
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::
| [reply] [d/l] |
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.
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
# 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.
| [reply] [d/l] [select] |
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.
| [reply] [d/l] |
|
|
| [reply] |
|
|
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.
| [reply] |