Hacker News new | past | comments | ask | show | jobs | submit login

This might be the most exciting group of new features since the beginning of C#. Those tuples...seriously sexy.

But, as much as I love C# (I changed jobs so I could work in it) this just has a pungent code smell to me:

p.GetCoordinates(out var x, out _); // I only care about x

Ug, some random underscore? I'm no language designer, but something maybe could have been done better here? It just looks fugly to me.




It's pretty common in languages with pattern matching to use underscore as a catch-all (ML family, Haskell, etc.). I'm not sure how the underscore is a code smell; if you want wildcard patterns without throwing a bunch of unused variables into scope (which can definitely lead to non-obvious bugs), you have to use some symbol.


Mostly like if I submitted some code for review and peppered it with underscores because "I don't care about those variables" I'm pretty sure it'd come back to me with a remark about starting to care.

At the point your writing code you don't care about, something might be wrong.


When working with an object, you don't always care about all of its properties. If it's packed in a certain way (tuple, Optional wrapper, etc.) that is easy to unpack with destructuring, then you might use an underscore to say "this is how it's structured, but I don't care about the particular value it has so please don't bind it to a variable."

If you bound it to a variable and didn't use it, it'd be the same as declaring an unused variable.


Do you ever write an if statement where you don't check one of the fields of an object, or a method call where you ignore a return value? If so, how is this any different?


Yeah, why not "out null" or something similar? Magic characters make me sad.


Unfortunately you have to download a nuget package to get the tuple syntax to work..




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: