Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: unless vs. bare block

by JavaFan (Canon)
on May 10, 2012 at 05:48 UTC ( [id://969746]=note: print w/replies, xml ) Need Help??


in reply to Re: unless vs. bare block
in thread unless vs. bare block

They are local variables and so avoid the generally evil programming practice of keeping state in global variables.
Generally, avoid the evil practice of being too general. There are lots of cases where it doesn't matter at all, or where other trade offs can be made. Remember, people could have used lexical filehandle references since 5.000, but it wasn't until they autovivified that people actually started to use them on a larger scale. The world didn't burn up in flames in the mean time.
They close themselves automatically when their lexical variable goes out of scope.
Yeah, and so will "bare word" handles. You can even limit their scope by using local.
They avoid the confusion of barewords. IMHO, barewords are an unfortunate Perl feature and should be avoided
Wait. You're saying we should write &foo and "Module::Foo"->new instead of foo and Module::Foo::->new, because they're barewords, and unfortunate? You're sure you mean this?
As for why the three-argument form of open is preferred, the old two-argument form of open is subject to various security exploits
You've no idea where the second argument is coming from. For all we know, there's no problem. Don't scare people.

Replies are listed 'Best First'.
Re^3: unless vs. bare block
by eyepopslikeamosquito (Archbishop) on May 10, 2012 at 12:02 UTC

    Wait. You're saying we should write &foo and "Module::Foo"->new instead of foo and Module::Foo::->new, because they're barewords, and unfortunate? You're sure you mean this?
    No I didn't mean that. My characterization of all barewords as "unfortunate" was inaccurate and I thank you for pointing that out. To be more specific, I detest bareword strings, for example $x = Hello, except when playing golf and writing poetry (when I adore them). Thankfully, "use strict" disallows this particular use of barewords.

    I also dislike bareword file handles, endorsing the point of view expressed in Why the Modern Perl Book Avoids Bareword Filehandles.

    I prefer not to teach beginners about local and dynamic scope, at least not initially. OTOH, I do teach them about my and lexical scope in the very first lesson.

    For an example of the confusion that can be caused by bareword file handles see: Bareword "FILE" not allowed while "strict subs".

    For similar reasons, I feel that beginners should learn three argument open first: there are fewer gotchas and I don't want to overwhelm the beginning Perl user with many different ways to do the same thing. Rather, I prefer to teach them first what is usually the best way of doing something. I am aware that there are strong differences of opinion on this matter as indicated by this long P5P thread.

    Update:

    Don't scare people.
    Don't bully people. :) In his reply, the OP stated: "I haven't had any experience with the three-argument version" followed by "Thanks, I'll check it out". So the net result of my pointing out three-argument open was not to "scare" the OP but rather to improve his Perl knowledge and skill by encouraging him to read about three-argument open and to learn about the specific problems it solves in security-sensitive environments.

      I feel that beginners should learn three argument open first
      That's all fine and dandy that you feel that way, but that doesn't mean that if someone has a question about unless and block, you should treat their use of 2-arg open as if it contains security problem, just because it's 2-arg open.

      It looks to me that the OP has already past the point of "learn 2-arg open or 3-arg open first". He *knows* 2-arg open. From his post, we cannot deduce the state of his knowledge of 3-arg open (nor of a gazillion other Perl constructs).

      I prefer not to teach beginners about local and dynamic scope, at least not initially. OTOH, I do teach them about my and lexical scope in the very first lesson.
      I'd like to point out that the poster came here with a specific question, and didn't come here with "Heh, I don't know any Perl -- who is going to give me my first lesson".

      I also think that your use of terms like 'evil programming practice' when describing the efforts of someone who in your opinion still needs to get their first lesson isn't very constructive.

        I'd like to point out that the poster came here with a specific question, and didn't come here with "Heh, I don't know any Perl -- who is going to give me my first lesson".
        The OP has already indicated in Re^2: unless vs. bare block that he was very happy with my reply and even went to the trouble to thank me for it. Besides, I am not answering just for the OP, but also for others who read the thread. Unlike your replies in this thread, the tone of my reply was polite, not bullying, the intent was to help the OP and others improve their knowledge of Perl.

        One of the things I enjoy about perlmonks is that threads often meander a bit, not just "answer the topic at hand and nothing more". This has already been discussed at length in When do we change our replies?, where my exact point of view was expressed by moritz:

        I really like to see replies that not only answer the question, but contribute to the education of all readers in terms of idiomatic Perl and robust programming (always in the context of the original question, of course).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-16 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found