22 ms·
get_response().json() is ideal, and I'm assuming yoiu're writing an HTTP wrapper since decoding JSON is a sensible default. If you need to add an intermediar
by nailer 1y ago
get_response().json()
is ideal, and I'm assuming yoiu're writing an HTTP wrapper since decoding JSON is a sensible default.
If you need to add an intermediary variable, name it as clearly as possible:
raw_response = get_response()
response = raw_response.json()
- nomel 1y ago> The fact that the first response is immediately overwritten proves to the reader it's not important/never used, so they can forget about it, where a temp variable would add cognitive load since it might be used later. I strive to write code that reduces cognitive load. To me, putting it in a temp variable is more of habit of old languages, mixed with a bit of cargo cult.
- nailer 1y ago> To me, putting it in a temp variable is more of habit of old languages If you do want an intermediate variable, naming it non-deceptively will reduce cognitive load. If you don't want one, that's fine too. There's no deception with a name that doesn't exist.