Destructuring on an empty stomach
-
Sometimes you read code and wonder what it does. Behold this line:
const { measurementEnd } = station;
Now I did recognize this as destructuring and even understood what it does after a fashion. I also think it's a useful ES6 feature in some circumstances. Here? Well the perpetrator cleverly managed to avoid naming
measurementEnd
twice. Doubtful benefit overall in my view.const measurementEnd = station.measurementEnd;
would have been more readable the way I see it. But some people crave the novelty I guess.Now how is this variable used? Well? Once. On the next line:
const { measurementEnd } = station; if (measurementEnd > threshold) {
So the whole assignement could have been avoided writing:
if (station.measurementEnd > threshold) {
which would have been just fine. Much easier to understand.
Now you may say that I'm blowing this all out of proportion and you see worse every other diff you review. While I can grant you that, I contend that there is a huge hidden cost to writing it this way: Now I'm ranting on TDWTF about the unreasonable people I'm working with instead of working happily on the feature I'm supposed to add. And this diversion is entirely the fault of the author of this piece of shitty code.
-
@gleemonk said in Destructuring on an empty stomach:
const { measurementEnd } = station;
While I like the idea behind that concept I have to say that I absolutely loathe the syntax. Because if I don't know the exact spelling and thus rely on code completion (in order to not to have to switch between windows), I now first have to type this:
const { } = station;
And then walk backwards into the brackets and init the code suggestions. Gah.
-
@gleemonk said in Destructuring on an empty stomach:
Now I'm ranting on TDWTF about the unreasonable people I'm working with instead of
working happily on the feature I'm supposed to addreading other people's rants on TDWTF.Let's be honest.
-
@Gąska While that is true in general I was actually working when this happened!
-
@Rhywden Same goes for SQL. :/
-
@Zecc said in Destructuring on an empty stomach:
@Rhywden Same goes for SQL. :/
Yeah, this bites me all the time...
-
@gleemonk said in Destructuring on an empty stomach:
I was actually working
Pictures or it didn't happen!
-
@HardwareGeek said in Destructuring on an empty stomach:
@gleemonk said in Destructuring on an empty stomach:
I was actually working
Pictures or it didn't happen!
The proof is right up there.
He was working on finding something to rant about here
-
@gleemonk said in Destructuring on an empty stomach:
Now you may say that I'm blowing this all out of proportion and you see worse every other diff you review.
I've seen things on code reviews you people wouldn't believe. 15-argument constructors plunged deep in the common libraries. I watched conditions nested miles deep near the data layer. All those moments will be lost in the squash merge, like tears in rain.
@gleemonk said in Destructuring on an empty stomach:
While I can grant you that, I contend that there is a huge hidden cost to writing it this way: Now I'm ranting on TDWTF about the unreasonable people I'm working with instead of working happily on the feature I'm supposed to add.
So all in all nothing has happened that wouldn't have happened anyway.
-
@HardwareGeek Proof:
(specimen 1: my face when I understood what the code does)
-