4 ms·
"moment.js: Mutable. Thank you, next." Mutable is not bad, buddy. You live in mutable world.
by glintik 6y ago
"moment.js: Mutable. Thank you, next."
Mutable is not bad, buddy. You live in mutable world.
- theon144 6y agoMutable is not bad when necessary, but otherwise I'd say that immutable is generally quite good.
- japgolly 6y agoFalse comparison. We're not creating a copy of the mutable world, we're writing software. Pretty different. Good luck programming in DNA or whatever and knowing that your code does what you want it to do.
- deleted 6y ago[deleted]
- TheCoelacanth 6y agoNo I don't. I live in an immutable, four-dimensional world /s These are all just models of the real world, not the reality. The real world can be modeled equally accurately as mutable or immutable, it just depends which properties of the real world you care about modeling.
- bbotond 6y agoMutability, in this case, can be pretty unexpected. Just like you don't expect the expression a + 5 to change the value of a but to return a new number, most people don't expect myDate.add(5, 'days') to change the value of myDate. I know that moment values are mutable, yet I often forget it while writing code and make dangerous mistakes because of how unnatural it is to see an arithmetic expression that is not immutable.
- mywittyname 6y agoThat's totally expected behavior to me. I would expect to use something like Moment.addDate(date1, 5, 'days') if I wanted a new instance of a date to be returned. Even in javascript-land, methods like that will have side-effects, yet still return this often just for the sake of method chaining. E.g. date.add(5, 'days).format("%Y-%m-%d") would mutate date, but return the same instance as a convenience.