JamesDevJim / game-zulu

First game of the coolest project
0 stars 1 forks source link

Return booleans directly #7

Open shuttle1987 opened 4 years ago

shuttle1987 commented 4 years ago

I see a number of situations where there's a logical check then True is returned if this check is true and False otherwise.

Take for example this:

https://github.com/JamesDevJim/game-zulu/blob/9bf97d92194ff8e7d61785aa535806c37a14003a/shared/control.py#L158-L162

I'd re-write this as:

        def doorOpen(self) -> bool:
            return bool(PIN_DOOR.read())

Or if the function PIN_DOOR.read() returned a boolean itself I'd drop the explicit cast and just do:

        def doorOpen(self) -> bool:
            return PIN_DOOR.read()

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().