Const declares something to be constant. Can it mutate?
TL;DR: Don't rely on languages cheating about directives.
Unexpected side effects.
Use better languages
Use spread operator
const array = [1, 2]; array.push(3) //array => [1, 2, 3] //Wasn't it constant ? //constant != immutable ?
const array = [1, 2]; const newArray = [...array,3 ] //array => [1, 2] Didn't mutate //newArray = [1, 2, 3]
Since this is a "language feature", we can explicitly forbid it.
We should always favour immutability on our designs and take extra care with side effects.
Thank you, @oliverjumpertz for this tip.
Maxi Contieri@mcsee1@oliverjumpertz so.. a 'const' array is mutable ? WTF !
Another code smell ?
What do you think?13:06 PM - 24 Aug 2021
Correctness is clearly the prime quality. If a system does not do what it is supposed to do, then everything else about it matters little.
This article is part of the CodeSmell Series.