There's a few reasons I think this form is better, but if you start using concurrency (which seems feasible considering the nature of the project possibly dealing with multiple senors and devices) then you will avoid an unlikey class of concurrency bugs that are particularly nasty. What can happen is that introducing more latency via more lines of code can mean that the value of keys can under some circumstances start to diverge from the t rue value of PIN_DOOR.read().
I see a number of situations where there's a logical check then
True
is returned if this check is true andFalse
otherwise.Take for example this:
https://github.com/JamesDevJim/game-zulu/blob/9bf97d92194ff8e7d61785aa535806c37a14003a/shared/control.py#L158-L162
I'd re-write this as:
Or if the function
PIN_DOOR.read()
returned a boolean itself I'd drop the explicit cast and just do:There's a few reasons I think this form is better, but if you start using concurrency (which seems feasible considering the nature of the project possibly dealing with multiple senors and devices) then you will avoid an unlikey class of concurrency bugs that are particularly nasty. What can happen is that introducing more latency via more lines of code can mean that the value of
keys
can under some circumstances start to diverge from the t rue value ofPIN_DOOR.read()
.