DEV Community 👩‍💻👨‍💻

Discussion on: Put Down the Destructuring Hammer

Collapse
bytebodger profile image
Adam Nathaniel Davis

I recently wrote an article exploring the same concept (dev.to/bytebodger/why-do-js-devs-h...). JS devs seem to have an aversion to namespacing. Although I destructure often, there are still many times when I purposely choose to use the object without destructuring - because it can make the code far more self-explanatory.

Collapse
derekmt12 profile image
Derek N. Davis Author

Great minds think alike I guess! "Well, destructuring effectively robs a variable of its context." So true. And you have a great point about the namespacing. That's even more broad than destructuring, but it makes a lot of sense. I had never thought about it.

Collapse
jfbrennan profile image
Jordan Brennan • Edited on

Yes, that loss of context is what kills me.
I stepped into a project that destructured lodash. I was thinking, "Wow, all these custom function signatures feel so familiar... Oh. [facepalm]" Is _ really too much nowadays?

Collapse
bytebodger profile image
Adam Nathaniel Davis

<SMH/>

Collapse
bdunn313 profile image
Brad Dunn

There's one legitimate case for that when you are able to leverage some of the tree shaking and unused code elimination during bundling - if you set up webpack correctly, for example, you can import individual functions from lodash while still including the whole lodash package in your dependencies, but at bundle time drop all of the unused functions.

Other than this case, I agree that often context is more important - lodash is such a specific example haha