Preview Feedback: C# 13+ field
backed properties
#8588
Replies: 2 comments 4 replies
-
It was a very intentional part of the design that we use
That's life tbh. That's how 'var', and all our other contextual semantic keywords, works. In time people get used to it :) |
Beta Was this translation helpful? Give feedback.
-
This is a misunderstanding of the space. We want breaking changes here. We believe it will be better for the ecosystem to have a clean and uniform syntax for properties, where 'field' just is the keyword with this meaning, just like any other keyword in the lang. It's a non-goal to have a non-BC approach, and we explicitly rejected several options along the way that would have had no BC concerns. |
Beta Was this translation helpful? Give feedback.
-
The new
field
keyword available in preview of C# 13+ is very useful. Apparently the motivation for keeping it in preview, is the breaking change with introducing a new keywordfield
in a context where that actually quite frequently will cause a problem with ambiguity.Since a long time, C# has had the
verbatim
identifier character '@' to ensure that when a keyword is used as identifier name, it'll be interpreted as an identifier instead, for example@default
etc.I would propose the introduction of a
keyword
character or syntax with the reverse meaning. Although I'm not sure what character will work without conflict, I think perhaps the '#' character would work - and it's also kind of nice, as it alludes to the '#' in C# to indicate that it's a language component. The only conflict I can think of offhand is the preprocessor directives, but then again - if '#' indicates a keyword, the#if
etc. would be easily interpreted as a preprocessorif
. I think...It would be acceptable anywhere a keyword can syntactically appear as an identifier, so you could use it as
#field
to ensure that even if there's an identifier in scope with the namefield
, it would be interpreted as the keyword instead.In fact, the only thing that makes the current situation manageable is the syntax highlighting provided by all IDE's. Without syntax highlighting it's not obvious just what interpretation an identifier that is also used as a keyword is given.
If the '#' character doesn't work, I'm sure there is some other non-conflicting compact syntax that can do the job. But assuming '#' would work we could then have
#field
,#default
etc. The '#' would be allowed anywhere the '@' verbatim character is allowed before an identifier.Back to the
field
preview feature. For this feature, I'd propose that thekeyword
modifier character/syntax be required forfield
. This will remove the breaking change problem, as there is no conflict anymore.For the future, I would suggest a gradual move to require the
keyword
modifier character for all such cases, starting with an info level intellisense suggestion, later to a warning (that could be disabled, and thus make for a soft break), and possibly in the further future an error.This would remove the dependence on syntax highlighting to indicate how a keyword/identifier is interpreted by the compiler, and also solve the problem of the
field
breaking change problem, and perhaps open up for similar new features being non-breaking changes.(This seems such an obvious thing, so even though I've not been able to find a similar proposal.... #7033 relates to this but not quite in the same way. If this has already been discussed and dismissed for reasons that are obvious to everyone but me, sorry for taking up your time!)
Beta Was this translation helpful? Give feedback.
All reactions