2015-09-08

New Features in C# Version 7

I previously commented on the features being developed for C# version 6, shipped with Visual Studio 2015. They are now working on C# version 7. The discussion can be followed at https://github.com/dotnet/roslyn/labels/Design%20Notes. Right now they are just talking about things, and nothing is set in stone.

Notable things being discussed:
  1. Tuples (#347)
  2. Pattern matching (#206)
  3. Records / algebraic data types (#206)
  4. Nullability tracking (#227)
  5. Async streams and disposal (#114, #261)
  6. Strongly typed access to wire formats (#3910)
  7. Method contracts (#119)
  8. Params IEnumerable (#36)
  9. Readonly parameters and locals (#115)
  10. Immutable types (#159)
  11. Object initializers for immutable objects (#229)
  12. Array slices  (#120)
  13. Local Functions (#259)
  14. Covariant returns (#357)
Some comments on these:
  • The tuples feature would allow a method to return multiple values, among other things. The LUA language has this ability, and I find it rather nice.
  • Pattern matching would have some syntax similar to a switch statement that could match a string to a pattern and execute some code.
  • Records would simplify having a simple type essentially only made of properties.
  • Nullability tracking would allow you to specify whether a reference variable would ever be allowed to be null. For example, you could make a string variable that could never be null. It sounds like this would be implemented as a language feature, not a CLR (common language runtime) feature, so under some circumstances it could be defeated. I'm unsure whether implementing this halfway is the right thing to do here.
  • Method contracts would move code contracts into the language. This would be welcome feature, as now they are implemented as method calls and a tool that patches the C# code.
  • Readonly parameters and locals. This would improve code quality. I'm not sure I like the keywords they are talking about, but the feature is good.
  • Immutable types. Another thing to improve code quality.
  • Array slices. There is one place in my code that this would improve performance by several orders of magnitude. They are saying that this would require CLR support, so is unlikely to make it into version 7.
  • Local functions. Syntactic sugar, don't think it is really that helpful.
Some nice things. I do worry that they are making the language more complicated with each version. This increases the learning curve for new programmers.

No comments :

Post a Comment