News for hackers. Stuff that matters.
Re:We should be more ambitious with the software we build by sirsinsalot on Sunday October 25, 2026 @07:59PM (#50237272)
Or you know, test if the key exists before using it. The key could exist and be None, representing a legitimate None at that key. Or the key might not exist and asking for it is a bug.

Use a defaultdict if you must have all keys optional. Using get() everywhere is buggy because it masks illegal key use.

Re:We should be more ambitious with the software we build by Chaosvex on Monday October 26, 2026 @04:29AM (#50240786)
> test if the key exists

Double lookup.

Re:We should be more ambitious with the software we build by sirsinsalot on Monday October 26, 2026 @06:11AM (#50241511)
Cheaper than fixing bugs due to illegal key access.

Cheaper than get() masking bugs in your code or dict generation.

But yes let's prematurely optimise for speed in a slow-by-default language by writing bug prone non-idiomatic code. OK.

Re:We should be more ambitious with the software we build by Windchaser on Monday October 26, 2026 @05:04PM (#50250929)
There are times where you want to check for existence before fetching a key-value pair, and there are times where you want to automatically throw an error if the value doesn't exist.

Both have valid use cases. It's weird to be sarcastic about it.