On Wednesday, 24 December 2014 at 09:02:56 UTC, Kagamin wrote:
On Wednesday, 24 December 2014 at 08:39:26 UTC, Ola Fosheim Grøstad wrote:int myfunc(int n){ ...lotsofstuff... x = mayormaynotchange(n); ...lotsofstuff... return n>0 ? x : 0; // modified from "return x" }If you require another variable for a sanitized version of `n`, you get confused, when to use `n` and when to use `x`, they are almost the same and if you pick a wrong value, the code will break sometimes.
Not really, because you should strive to keep mutable state local. Validation does not belong to the implementation, so "the right way" is to put it in a wrapper before you call the function that does the actual work.
When functions get long and complicated and evolve over time then all mutable state become a source for errors.
I never want to change parameter values for long functions. I do it for because I am in a hurry. The more constraint the language impose the better code I am likely to write.
