PBP: 006 Operators

PBP says to put whitespace around binary operators.  This, I entirely agree with.  It also notes to keep unary operators together with their operand.  This, too, I think is a good idea.

There is also a suggestion to use more whitespace to delimit things into groups of order of operations.  I think that’s interesting, but very subtle and not something I’ll be able to do or find very helpful.

If I know the order of operations, I’ll assume it doesn’t matter or that everyone is familiar with them, and not think to mark them.  If I’m not sure, I’ll use highly visible parenthesis to make sure it’s obvious what I’m doing, rather than happening to get it right, and using whitespace to hint what the order will be.

Interesting idea, though.

 

One Response to “PBP: 006 Operators”

  1. hobbs says:

    I generally use whitespace around binary operators, but I’m willing to reduce it to aid comprehension, rather than add more. For example. sqrt( $x*$x + $y*$y ) rather than sqrt( $x * $x + $y * $y )

Leave a Reply to hobbs