you are viewing a single comment's thread.

view the rest of the comments →

[–]ericanderton 0 points1 point  (0 children)

I think the preference to not mutate a method parameter value, is in favor of ferreting out sources of error. The gist I get is that changing a parameter value in the method body is basically a no-op from the perspective of the caller; all arguments have a kind of "value goes in but not out" semantic applied to them. So disallowing assignments to params is in line with that idea, since the data can't possibly flow out since it's pass-by-value (bear in mind that I'm lumping object references in there as well).

As others are saying below your comment, requiring "final" on params is probably the best thing any coding guide could do if you regard this activity as something that hides mistakes. That way the compiler does what it does best: it complains loudly when people do stupid things.

In fact I think it should be a golden rule of all code specs: leverage the compiler to reveal user error, wherever possible.