News for hackers. Stuff that matters.
Re:Should function arguments be reassignable or mutable? by SideburnsOfDoom on Monday January 01, 2018 @09:12AM (#16046108)
I agree up to a point.

Firstly, "Immutable by default" is recognised as a good design feature now for modern languages. But there is plenty of code in existing languages like Java, JavaScript, C, C# etc. which does not follow this rule.

Secondly, the "principle of least surprise" suggests that function arguments should work like local vars in that language. So if local vars are immutable by default, then arguments should be as well. Or if local vars can be optionally declared as immutable, then function arguments should be as well.

I can't really say what's the best for every/any language. It's not one size fit all. There are always design tradeoffs and differing schools of thought. But these days it looks a lot like "immutable by default, unless there's a good reason otherwise" is a good starting point.

There are no comments on this comment yet.