4 ms·
result.process() That doesn’t make logical sense. You already have a result. It shouldn't need processing to be a result.
by nailer 1y ago
result.process()
That doesn’t make logical sense. You already have a result. It shouldn't need processing to be a result.
- riskable 1y agoIt also doesn't make sense for `process()` to be an attribute of `result`. Why would you instantiate a class and call it result‽
- Bayko 1y agoA more common example for me at work is getting a response from url. Then you gotta process it further like response.json() or response.header or response.text etc etc. and then again select the necessary array index or doc value from it. Giving a name like pre_result or result_json etc etc would just become cumbersome.
- nixpulvis 1y agoI would never do `response = response.json()`. I use it when it's effectively the same type, but with further processing which may be optional.
- nomel 1y agoDepends on how clear it is. I usually write code to help local debug-ability (which seems rare). For example, this allows one to trivially set a conditional breakpoint and look into the full response: response = get_response() response = response.json() 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. and I think is just as clear as this: response = get_response().json() This motivated by years of watching people through code, and me working with deeply non-software engineers, and is always very much appreciated.
- nailer 1y agoget_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.
- feoren 1y ago> Why would you instantiate a class and call it result‽ Are you suggesting that the results of calculations should always be some sort of primitive value? It's not clear what you're getting hung up on here.
- nailer 1y agoNo, the result of a calculation could be a key value or list or other compound value - whatever the result is. I am getting hung up on deceptive naming. If you have a 'result', the calculation is done. You have a result.