DEV Community

Discussion on: Mutation isn't always bad in JavaScript

Collapse
 
jwp profile image
John Peters

I attribute the 'don't mutate gospel' to inexperience. It was accepted at face value in Js community solely because of opinionated frameworks like React.
So much so, that we now see entire component designs requiring its use.

In a poll here on Dev.to, I asked for comments on the goodness on non mutable design. The best answer was 'to avoid per element comparisons' to determine what changed in an array'. All other answers were weak.

We got by just fine mutating objects in C# for 30 years. So the new found non mutable crowd has little history to stand on.

Also JS didn't really have strong typing nor did users really understand by reference and by value. All contributed to traps.

It's all about perspective and experience. Either way works, but what I choose in the end is simply the right thing for my project.

This article is greatl!

Collapse
 
nas5w profile image
Nick Scialli (he/him)

I really appreciate this perspective, John. As I mentioned in the introduction, we often find ourselves clinging to dogmatic views based on some bad experiences or simply because nuance is hard.

I also think the “opinionated frameworks like React” part is more like a misunderstanding a lot of folks have about React. The truth is React works based on referential equality, so its only opinion on mutation is that you shouldn’t mutate an object if you expect React to detect that change and take an action based off of it.

Anyways, thank you so much for the thoughtful response!

Collapse
 
jwp profile image
John Peters

My thoughts on React being opinionated is based on how it demands its own way of doing things. For example just look at how it did styling. React is 20 times less opinionated than Angular which is good. The advent of webassembly brings all discussions like these to an end. We now have the ability to write entire websites using c# and it's huge set of class libraries. Cool