Hacker News new | ask | show | jobs
by Chaosvex 40 days ago
> test if the key exists

Double lookup.

1 comments

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.

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.