Proposal: Consider adding $ syntactic sugar for nameof. #3448
Replies: 5 comments
-
Code gets written once (or maybe twice 😃) and read dozens of times. I'd suggest trading a few characters of typing for impaired readability is a poor tradeoff. |
Beta Was this translation helpful? Give feedback.
-
, so instead of
, could help. |
Beta Was this translation helpful? Give feedback.
-
The keyword Check into the formal research on readability - it turns out that symbols are not faster to read nor to process for comprehension. For experienced readers, they come out about equal, but for learners, symbols are much slower. |
Beta Was this translation helpful? Give feedback.
-
Actually, I like this idea better than the $ prefix. Backticks would work great. What we really want to see is the name, but also ensure that if the member spelling changes that the reference to it changes as well. And quotes, double quotes and backticks are already common place, so it should not be a large hurdle to learn. In fact it's already common in MarkDown. |
Beta Was this translation helpful? Give feedback.
-
I'm strongly opposed to this. It would be using a very suitable syntax for something that is already trivially supported today. I would not want to use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Nuisance
We've been using nameof extensively on our projects. This has turned out to be a very handy feature, but in our multitude of assert statements in our tests, having to type nameof over and over is getting cumbersome.
Proposal
Consider a
$
or some other prefix character that can be placed before any variable, type or member to produce their name.For example (samples borrowed from https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof):
EDIT (6-6-2020):
@dzmitry-lahoda made an alternate suggestion in the comments that works better. Instead of the
$
originally suggested, surrounding the variable, type or member with backticks would work nicely. So for example:Beta Was this translation helpful? Give feedback.
All reactions