Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^17: eof not recognised when applying diamond operator to invocation arguments?

by tilly (Archbishop)
on Jan 18, 2011 at 21:12 UTC ( [id://882989]=note: print w/replies, xml ) Need Help??


in reply to Re^16: eof not recognised when applying diamond operator to invocation arguments?
in thread eof not recognised when applying diamond operator to invocation arguments?

You claim that there is no documentation that covers this form. But perlop documents its existence quite clearly. The same place also clearly documents that you should expect no surprising language semantics from the existence of the optimized version. If you know what the loop is supposed to do, it will still do that. Just using less memory than you thought it would.

However even if you're unaware of that documentation, it should be irrelevant. Any program that ran before it existed will run after, and should give the same output.

As for people who micro-optimize the wrong way without benchmarking, what can I say? My philosophy has been to make things clean and not worry about performance until I have to. So while I'm pleased by the optimization, it doesn't change my default coding style at all.

On the style difference, there is no point in having that argument with me. I always spell it "for". Anyone who has to deal with Perl code in the while will encounter that spelling, and I see no significant benefit in avoiding it. Sure, if you are training beginners in a code base that is careful to always spell them differently, there could be a small learning benefit. (I'm not saying that there is, just that there could be. I have no data either way.) But you're doing your newbies no great favors, and it will annoy experienced people. I would follow such a style rule, but I would dislike it.

However if you were having the argument with me, I wouldn't think that the existence of a minor optimization that programmers are not supposed to be aware of would change my opinion. And, in fact, I believe that your discussion was going in circles in part because I doubt that Argel knew about the optimization. Therefore you were drawing an apparently arbitrary distinction between two different examples of the list form.

Replies are listed 'Best First'.
Re^18: eof not recognised when applying diamond operator to invocation arguments?
by Argel (Prior) on Jan 19, 2011 at 00:03 UTC
    I'm sure I knew about the optimization at some point, but it is just trivia to me. As I mentioned in another post, I haven't used ".." in a loop in several years. If I had needed that optimization I would have remembered it because figuring that out would have been a painful process (and there's nothing like several hours wasted to burn something into memory).

    As for the stylistic differences, from the perlsyn docs (emphasis added):

    The foreach keyword is actually a synonym for the for keyword, so you can use foreach for readability or for for brevity.

    Elda Taluta; Sarks Sark; Ark Arks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-03-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found