4 ms·
> I would prefer people assign as many new variables as they like, and just avoid mutating them While I would agree that it is much more important to have func
by hannofcart 8y ago
> I would prefer people assign as many new variables as they like, and just avoid mutating them
While I would agree that it is much more important to have functions NOT mutating their local variables, doing away with assignments is a straight-jacket which immediately forces you to decompose larger functions into smaller ones.
In fact, even in languages like Haskell where mutations of local state is entirely done away with, I see constructs such as `where` and `let` being abused to construct inordinately long functions.
Longer functions tend to accrue even more length over a code base's life and become harder and harder to test as they do.
- striking 8y agoEventually function decomposition becomes a proxy for assignment anyway, especially in languages where assignment and mutations are necessary. Function decomposition is not necessary for all code and can actually be harmful to one's understanding if done improperly. I generally follow the rule of threes ("if the code appears in three places the exact same way, extract it to a separate function") as this helps me balance readability of functions with size of functions. I understand your advice applies very neatly to functional languages. I would love to live in a functional world. I don't. So that's why my advice is like that.