Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Burned by precedence rules

by swampyankee (Parson)
on Dec 24, 2008 at 04:26 UTC ( #732408=note: print w/ replies, xml ) Need Help??


in reply to Burned by precedence rules

Like toolic, I work on the principle of "when in doubt, parenthesize." I've also dealt with optimizing compilers that would handle something like

do i = 1, 10 do j = 1, 10 do k = 1, 10 l = i + j + k enddo enddo enddo

differently from

do i = 1, 10 do j = 1, 10 do k = 1, 10 l = (i + j) + k enddo enddo enddo

in that it would not recognize i + j as constant in the innermost loop in the first fragment, but would in the second. There are also cases where I've needed to force a specific order of operations to preclude under or overflow.

I also won't rule out the possibility that, unlike the compiler, I can get confused about logical tests that have multiple and's, or's, and not's; using (perhaps superfluous) parentheses will reduce my confusion.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc


Comment on Re: Burned by precedence rules
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (16)
As of 2015-07-28 19:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls