4 ms·
> What about maintainability? It's only anecdotal, but I find pure, immutable code far easier to maintain in any language. To a first approximation, a function
by chriswarbo 12y ago
> What about maintainability?
It's only anecdotal, but I find pure, immutable code far easier to maintain in any language. To a first approximation, a functional interface == a testable interface.
- denim_chicken 12y agoIt's only anecdotal, but I feel the opposite.
- chriswarbo 12y agoReally? I'd genuinely love to see some examples. I've joined several projects in their maintenance phase which had no tests, and introduced some as I went about debugging, adding features, etc. Since the code was often untestable, I'd make a few refactorings over and over again to allow testing, and these just-so-happen to tease apart the pure computation from the effects; in essence making the code more functional. An obvious example is to turn implicit state into explicit parameters, eg. // BEFORE function foo(x, y) { b = x + y + a; } // AFTER function foo(x, y) { b = foo_pure(x, y, a); } function foo_pure(x, y, z) { return x + y + z; } This doesn't make `foo` more functional or easier to test; but testing `foo_pure` is trivial. In particular this makes debugging logic errors much easier; since there's no need for elaborate/brittle test setup (eg. setting all the right globals, creating and cleaning up files, etc.).