Sitemap
Backend Engineers Club

Real-world backend engineering scalability, systems design, and the production failures nobody warns you about.

Member-only story

x is 257 Was True on Monday and False on Tuesday

8 min read3 days ago

--

Press enter or click to view image in full size
Equal Value, Different Identity

I had a check that compared two numbers. Something close to this, simplified:

if parsed_id is expected_id:
grant_access()

It worked. Every test passed. Then one day, with slightly different data, the same comparison started returning False for two numbers that were obviously equal. Both were 257. I printed them. They were identical. And parsed_id is expected_id was False.

You can read this article for free via this link ( my newsletter ): Click Here 👈

So I changed the test data, and it went back to True. Smaller numbers worked. Bigger numbers did not. The comparison's correctness depended on how large the number was, which is not a sentence that should ever make sense.

The culprit was a single two-letter word I had used where I meant something else: is. In Python, is and == look interchangeable and are not. One asks "are these equal?" The other asks a completely different question, and the answer to that question happens to be unpredictable for numbers. Here is what is actually checks, why it lied to me, and the one rule that…

--

--

Anas Issath
Anas Issath

Written by Anas Issath

From Backend Developer to System Thinker

Backend Engineers Club
Backend Engineers Club

Published in Backend Engineers Club

Real-world backend engineering scalability, systems design, and the production failures nobody warns you about.