News for hackers. Stuff that matters.
Re:Get Ready For C# 4.0 by SanjayU on Monday May 10, 2010 @11:33AM (#1334705)
Yeah, I'm not a huge fan of named parameters, either. Seems a bit superfluous.
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?

    var c = new Cube(1, 2, 3)
or:

    var c = new Cube(height: 1, width: 2, depth: 3);
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.

Re:Get Ready For C# 4.0 by seasoup on Monday May 10, 2010 @12:22PM (#1334899)
Named parameters are awesome. The equivalent pattern in javascript is passing in an options object.

foo({ 'name': 'bar', 'title': 'Bar' });

This means not having to look up what the exact order of options are, nor having to pass in a bunch of null parameters because the one you want is the last parameter. Very cool.

}

Re:Get Ready For C# 4.0 by bruceboughton on Monday May 10, 2010 @01:23PM (#1335212)
Named parameters will be particular useful when calling methods which take bools (rather than a intention revealing enum).
Re:Get Ready For C# 4.0 by rhythmAddict on Monday May 10, 2010 @08:24PM (#1336367)
I agree that it makes it "more readable", but that only would matter if intellisense wasn't working. I see the parameters, and they are strongly typed. In JS, this isn't the case, so it is much more helpful (e.g, I can completley screw up types/params and they will probably materialize as some strange behavior. As far as bools, I generally try to avoid having more one or two bools as an argument, unless it's required, and it rarely is.

Obviously, all IMO.

Re:Get Ready For C# 4.0 by InclinedPlane on Tuesday May 11, 2010 @06:05AM (#1337388)
Do you have intellisense in your eyes? A line of code with a handful of named parameters reveals its intentions (and possibly also its correctness) for more readily than a line of code with a laundry list of parameters that you need to mouseover then do a bit of mental juggling to line up which value lines up with which parameter. In doing so you've likely interrupted and degraded your reading of the code and you've definitely degraded your ability to readily spot the difference between correct and incorrect code.
Re:Get Ready For C# 4.0 by rhythmAddict on Tuesday May 11, 2010 @09:18AM (#1337697)
Actually, you guys are right. I realized the flaw in my thought process right after I read seasoup's post.

I do, however, have intellisense in my eyes.

Re:Get Ready For C# 4.0 by TeHCrAzY on Monday May 10, 2010 @07:40PM (#1336265)
Bingo. You can also avoid the fun Enum.IsDefined that comes with it.