Preferences

How does C# the language or C# the language standard evolution process accommodate a new keyword with such a generic name? Is it context-dependent?

It's been a while, but from memory I think C# allows you to override keywords and use them as variable names when prefixed with @

The compiler knows what you're doing. A keyword like 'field's inside a function's braces just isn't valid. Putting 'field' after a type name in a variable declaration makes as much sense as 'private int class;'

Yes, it's contextual. There is more details in this section of the article: Naming Conflicts with Existing Class Members
Thanks, my bad. I didn’t continue reading past the sections on Entity Framework and AutoMapper.
Historically every time new keywords are added, they try to make them contextual so that existing code won't break. 'await' and 'yield' are both examples where a new keyword was added without (generally) breaking existing code - they're only keywords in specific contexts and the way you use them ensures that existing code won't parse ambiguously, AFAIK.
Though, contextual keywords are a thing going back to the original design of C# 1.0 even. The nearest and most obvious example to the topic at hand is that `value` is only reserved in situations such as a property setter, and always has been. You don't need `var @value = …` in the vast majority of C# code and can just write `var value = …` just about anywhere but inside a `set { }` block.

Part of why C# has been so successful in introducing new contextual keywords is that they've been there all along. I think C# 1.0 was ahead of the game on that, and it's interesting how much contextual keywords have started being a bigger tool in language design since C# (all of ES3 of ES4 and some of ES5 were predicated on keywords are always keywords and ES6/ES2015 is where you first start to the shift in JS to a broader contextual keyword approach which seems equal parts inspired by C# as not).

This is the first time they've done this in a long time fwiw. So the answer is "they usually never worry about this because it never happens".

That said, they will also throw compiler warnings in console during build if you are using an all lowercase word with some small number of characters. I don't remember the exact trigger or warning, but it says something like "such words may be reserved for future use by the compiler" to disincentivize use.

Yes, you have to use field as the backing variable name in a property. The article is pretty clear about its usage.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal