Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^5: Interview Prepration

by demerphq (Chancellor)
on Apr 05, 2005 at 17:03 UTC ( [id://445039]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Interview Prepration
in thread Interview Prepration

Actually I think the community has selected a third way to avoid this debate, whatever it actually says in Perlsyn. The way they solved this debate is they say for LIST and 3 arg for loop or c-style for loop or if you are like me the while loop that likes to crossdress and call itself a for loop.

I agree with chromatic, your usage, while strictly correct is confusing and misleading, especially when it leads you to obvious contortions like saying

foreach(;1;) { }
is a "for" loop and
print for @list;
is a "foreach" loop.

Hopefully youll drop this piece of pedantry as its just confusing.

---
demerphq

Replies are listed 'Best First'.
Re^6: Interview Prepration
by merlyn (Sage) on Apr 05, 2005 at 17:37 UTC
    I don't know what's confusing about calling something what it is, especially when there's an authoritative source that most people should have already read, or will read now. In fact, I find it more confusing when people are inventing their own terms when perfectly good terms exist.

    No, I'll stand by the reference docs here, unless I hear otherwise from the man himself.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      merlyn,
      Let me preface my post by stating that I agree with most of what you are saying. I do think it is confusing to be able to use the keywords interchangeably but not have interchangeable behavior - regardless of it being documented. Since both the Camel and Llama are copyrighted, I will quote from perldoc perlsyn.

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

      I know that the rest of the documentation explains the distinct differences in the behavior (implicit aliasing and localizing), but how hard would it be to add:

      "Caution: While the keywords are interchangeable, the behavior of the looping constructs are not. What appears in the parens after the keywords determines the internal behavior".

      It certainly isn't your fault that most people don't carefully read the documentation nor is it mine. That doesn't negate the fact that it happens everyday. Taking that one snippet out of context would lead people to believe they are the same thing. Using the "Try It And See" method in a naive way supports this since interchanging for and foreach keywords results in identical behavior.

      In summary, it is my belief that that because the keywords are interchangeable and there are no big red warning flags in the documentation, people are going to incorrectly believe there is no difference.

      Cheers - L~R

      I don't know what's confusing about calling something what it is, especially when there's an authoritative source that most people should have already read, or will read now. In fact,

      I personally don't find it confusing - but I've come across many people who do. Since the for/foreach keywords can be used interchangable for for/foreach loops I don't find the confusion that odd.

      Having become bored with conversations that go:

      "You should use a foreach loop there"
      "I am"
      "No you're not"
      "Yes I am - look"
      <sound of Adrian gritting teeth> "I mean you're using a C-style for loop, why not just iterate over the container"
      "Oh - yeah"

      I tend to always call them "C-style for loops" to save myself the effort.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found