3 ms·
Boolean Headache
today i had to do some refactoring and came across this piece of python code (using requests)
400 >= response.status_code
i first read it as "status of response has to be higher than or equal to 400" but then i read it again a few times (read 10+) with increasing levels of headache and realized i read it all wrong, it was "status_code needs to be less than or equal to 400"
i realized switching the statement the other way around made my headache go away;
response.status_code <= 400
now its clear to me, myself and I: "status_code needs to be less than or equal to 400"
i realized i had suffered a brief encounter with boolean headache inducing syntax
anybody felt the same anytime?
- gus_massa 6y agoA Yoda condition you have meet. https://en.wikipedia.org/wiki/Yoda_conditions https://en.wikipedia.org/wiki/Yoda_conditions The "Advantage" section you must read.
- friend-monoid 6y agoYoda mostly applies to equality comparisons
- supernihil 6y agohahaha exactly, what a nice world to live in with tings and concepts having names!
- friend-monoid 6y agoYes absolutely. I tend to put my comparisons in order from least to highest always these days, so it’s “value < max” and “min < value”. Eases up on the headwork
- gus_massa 6y agoI agree. Something like def f(x): print( 3 > x < 8) is horrible.