Hacker News new | ask | show | jobs
by benj111 15 days ago
> x = (x + 2step) % width

Hmm. now. Is operator precedence not an instance of hidden flow control?

You need to know that 2step is done before adding x.

x = (x + (2step)) % width Or x = ( 2step + x) % width

Should be preferred?

Personally I try to bracket all things like this, so that it isn't hidden.

1 comments

Yes it is control flow, but IMO it's not hidden. It's true that you need to learn that * happens before + (which usually happens in school), but I don't see how that's any different from needing to learn that `and` short-circuits, or that `if` only evaluates its body if the condition is true.

Compare to what people usually call hidden control flow (exceptions, RAII, ...) where you don't know which parts of the code will run unless you read the definitions of the classes and bodies of the functions you use. The syntax at the call site is not enough to tell.