Boolean Headache

2 points by supernihil ↗ HN
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?

5 comments

[ 4.2 ms ] story [ 26.1 ms ] thread
Yes 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
I agree. Something like

  def f(x):
    print( 3 > x < 8)
is horrible.