Parentheses: more than emoticon mouths

emoticonI keep telling my students to use parentheses all the time. I even tell them to parenthesize something like 2+(3*4), even though we know that multiplication has precedence over addition, because it’s a good habit to always be crystal-clear to humans and computers alike.

Sometimes I feel silly for being so dogmatic about this. But I just spent an hour debugging, because (a&0xFF<<24) did not put my alpha value into the top 8 bits of an int. It should have been ((a&0xFF)<<24). Now I feel good again about telling people to use lots of parentheses!

Leave a Reply

Your email address will not be published. Required fields are marked *