DEV Community

Discussion on: Mutation is ok

Collapse
 
phlash profile image
Phil Ashby

Couple of thoughts while reading this excellent article Maciej:

  • Functional core, imperative shell: is a whole-application design ethos that you are not suggesting we break (thanks!), which differs in scale from your examples here of perfectly legitimate mutation within a method/function, however...
  • Internal mutation falls apart if others can attempt to extend/get-inside a thing, this largely impacts next-scale up entities such as classes or libraries that expose the state.
  • Ensuring that referential transparency is maintained is harder to prove when mutating anything, neat/efficient it may be, but proving it's safe for missile guidance may be harder :)
Collapse
 
macsikora profile image
Pragmatic Maciej

Hi Phil,
Thanks for the comment.

Internal mutation falls apart if others can attempt to extend/get-inside

Extending function is not a common practice in FP. We more should strive for small replaceable units. Instead of adding new use cases to the unit we should compose it with another. Until we keep them small even imperative code should not be any issue.

Ensuring that referential transparency is maintained is harder to prove

Again the same counter argument from my side. Until we keep functions small with one responsibility, nothing like that should happen.