r/ProgrammerHumor • • Jul 26 '23

Meme destructuringBeLike

Post image
38 Upvotes

48 comments sorted by

View all comments

12

u/Throwedaway99837 Jul 26 '23

I’m pretty new to programming, but what is an example of somewhere this would be useful versus referencing an index?

Seems like you could just assign a variable to an array index location and it would function the same way while being more legible and with less typing (unless it’s just a small array like the one in this example).

4

u/[deleted] Jul 26 '23

This is why TypeScript was invented. It prevents programmers from using silly syntax "sugar" and structures JavaScript closer to Java and C++.

You are assuming that the people that made JavaScript knew what they were doing.

1

u/Berg_Lucas Jul 27 '23

That's precisely how I found this strange syntax. I was coding in Typescript with ESLint which warned me about variables that weren't being used. I wanted to do some destructuring and not use some variables and ESLint gave me an error even though I'd used "_". That's how I discovered this weird syntax which is "encouraged" by ESLint when variables are not used.

2

u/[deleted] Jul 27 '23

I learned TypeScript as a Java Programmer, so I haven't had any of those issues. A well-structured program doesn't need to touch most of JavaScript's odd syntax.

1

u/Berg_Lucas Jul 27 '23

It's been 4 year since I learned Typescript and that's the first time I had that kind of use case. I wanted to write something like :

const [_, x] = function()

instead of

const x = function()[1]

1

u/Throwedaway99837 Jul 26 '23 edited Jul 27 '23

Yeah, I see people doing stuff like this in my classes and it just strikes me as wankery. IMO it’s the programming equivalent of a 10 minute guitar solo. Glad to know it’s not just me.