3 ms·
This is a really nice set of C# improvements that fit together to solve a big problem. I love it. I do have some minor questions, though! The simplest improvem
by kevingadd 12y ago
This is a really nice set of C# improvements that fit together to solve a big problem. I love it. I do have some minor questions, though!
The simplest improvement that confused me at first is the ability to declare a new inline local to handle an 'out' variable:
int x;
foo(out x)
becomes
foo(int x)
This by itself is a quality-of-life improvement but it enables the really nice extraction of values for pattern matching. I'm happy to see this as a general language feature instead of a hack specific for records. (Was this already introduced in a proposed future C# version, and I missed it?)
The record classes considerably simplify the creation of simple data structures, trees, etc. This alone would kill thousands and thousands of lines of pointless duplicate code in JSIL, so I'm really happy to see it. Are the properties of record class instances read-only? (It's hard to tell from the draft spec. I'd be okay with mutable-by-default with opt-in readonly, but always-readonly would also be okay with me as a simpler design.)
The introduction of an overloaded 'is' operator that accepts user-defined arguments on the right-hand-side. You define the operator on a given type and give it out-parameters (and presumably it can accept value parameters, as well, so you can do more sophisticated matching), and the compiler converts that into a call to the matching function that, if successful, yields values from the match. Really clever way to introduce this - the syntax is slightly confusing, but it avoids introducing new keywords and almost all of this feature follows nicely from existing C# features.
And switch statements are expanded to be able to pattern-match! Lovely! This is a natural improvement given that switch statements are already compile-time sugar for dictionary lookups when you're switch()ing on non-integer values.
It seems like all of this is compile-time sugar that doesn't require any runtime changes. Is that true? If so, what version of the runtime do you think will be the minimum for Roslyn output that uses these features?