|
|
| Don't ask to ask, just ask | |
| PerlMonks |
Re^2: disadvantages of perlby ELISHEVA (Prior) |
| on Jul 03, 2009 at 14:02 UTC ( #777056=note: print w/ replies, xml ) | Need Help?? |
|
You seem to be viewing (...) as a data structure. That isn't at all unreasonable, but it is not the only meaning that we commonly give to (...). Perl's definition of (...) is drawn from another part of life: math. A better mental model would be the parenthesis in math statement: (3+4)*(6+10). It is simply a way of grouping things to indicate the order in which you want them processed. Merely being an ordered collection doesn't determine how we'll use it. There are many different things one can do with groupings: nest them, concatenate them, visit their members one by one. In Perl which action you want to take on the grouping depends entirely on context. For example, when you use it in a for loop, the for loop processes the elements in order (just as you asked). And when you assign it to an array, Perl adds each element to the array in order, just as you asked. Nesting parenthesis doesn't change the treatment any more than does ((3+4))*((6+10)). The elements still get added in the order you requested. I had little trouble grasping Perl's approach to parenthesis because my interest in mathematics and my interest in programming are closely related. Perl's syntax was natural for me. But I fully appreciate that others have come to programming from different directions than I. They are used to giving symbols other meanings than I give them. It all comes back to the the vagaries of DWIM (Do What I Mean). As tweetiepooh has pointed out a language's strengths are also its weaknesses. DWIM, or as Larry Wall calls it "The Principle of Least Surprise", is rather subjective:
In a language where DWIM rules, we need to be very sensitive to the fact that not all of us are thinking the same thing when we get to the word "mean". If you are teaching Perl or helping an organization develop Perl skills it is very important to be sensitive to this issue or else you will end up with confused frustrated programmers for whom Perl definitely does not do what they mean. Best, beth
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||