Re:Get Ready For C# 4.0
by j_baker on Monday May 10, 2010 @01:55PM
(#1335344)
Named parameters make code more readable when used properly. For example, which is more readable?
or:
[ Parent
| on HN ]
Re:Get Ready For C# 4.0
by InclinedPlane on Tuesday May 11, 2010 @05:58AM
(#1337380)
The real advantage of named parameters is the ability to have optional parameters as well. Which means that instead of:
var c = new X(3, "blue", null, null, null, null, false, true, null, 1, null);
(which, sadly, is an all too common implementation pattern), you can have: var c = new X(foo: 3, bar: "blue", baz: false, quux: true, wibble: 1);
Which seems quite a bit better.Another advantage of named/optional parameters is that you can use them in the construction of immutable objects, whereas you don't get that advantage if you use settable properties.