TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Boolean Headache

2 pointsby supernihilover 4 years ago
today i had to do some refactoring and came across this piece of python code (using requests)<p>400 &gt;= response.status_code<p>i first read it as &quot;status of response has to be higher than or equal to 400&quot; 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 &quot;status_code needs to be less than or equal to 400&quot;<p>i realized switching the statement the other way around made my headache go away;<p>response.status_code &lt;= 400<p>now its clear to me, myself and I: &quot;status_code needs to be less than or equal to 400&quot;<p>i realized i had suffered a brief encounter with boolean headache inducing syntax<p>anybody felt the same anytime?

2 comments

friend-monoidover 4 years ago
Yes absolutely. I tend to put my comparisons in order from least to highest always these days, so it’s “value &lt; max” and “min &lt; value”. Eases up on the headwork
评论 #26092726 未加载
gus_massaover 4 years ago
A Yoda condition you have meet. <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Yoda_conditions" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Yoda_conditions</a> The &quot;Advantage&quot; section you must read.
评论 #26088273 未加载