Skip to content

Blazor access modifiers and field underscores #18446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Blazor access modifiers and field underscores #18446

wants to merge 2 commits into from

Conversation

guardrex
Copy link
Contributor

@guardrex guardrex commented Jan 18, 2020

For Blazor templates per dotnet/AspNetCore.Docs#15853 (comment) ...

  • Few access modifier touches.
  • Underscores for fields.
  • Alphabetize class properties and place properties before methods.
  • [Parameter] on its own line.
  • Summaries, a private static readonly string[] field, is named like a constant (capitalized). If that's by-design, I'll revert.
  • I swap in an underscored field for this.logger = logger in WeatherForecastController.cs. I thought this was "banished to the land of wind and ghosts (-RN)." If by-design, I'll revert. Reverted!

@rynowak
Copy link
Member

rynowak commented Jan 21, 2020

I swap in an underscored field for this.logger = logger in WeatherForecastController.cs. I thought this was "banished to the land of wind and ghosts (-RN)." If by-design, I'll revert.

BTW - whether or not we're doing this. or _ in templates is currently under civil debate. We're not currently very consistent about it, because it was largely a decision made by the people who wrote the code and their preferences.

That doesn't sound like me, I'm part of #ThisSquad 😁

@Pilchie Pilchie added the area-blazor Includes: Blazor, Razor Components label Jan 21, 2020
@guardrex
Copy link
Contributor Author

Mentioning the guideline for discussion only in case anyone else sees this. I know that ur aware of the lingo 😄 ...

Avoid this. unless absolutely necessary

From: https://github.com/dotnet/aspnetcore/wiki/Engineering-guidelines#coding-style-guidelines--general

I performed a doc sample search to see how common this is used ... very rarely ... half-dozen times or so in mostly obscure samples. This one tho, WeatherForecastController is going to be seen quite a bit I think. 👀

@pranavkm
Copy link
Contributor

@guardrex we spoke about this offline, and the decision was to land close to what VS does by default which is to use this.. This of course only applies to content that lands in user's projects (templates and scaffolded code), and not to our engineering guidelines. Would you like to take a stab at updating this or should we close this?

@guardrex
Copy link
Contributor Author

guardrex commented Feb 19, 2020

I can update this ... I think the rest of the goodies on here are ok. I'll take care of it tomorrow (Wednesday) NOW.

@guardrex
Copy link
Contributor Author

@pranavkm ... Had a minute while 🍗 was cook'in. 👨‍🍳 Updated!

@@ -38,14 +38,14 @@ else
}

@code {
private WeatherForecast[] forecasts;
private WeatherForecast[] _forecasts;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ones above I'm 😐 about since they're sample. However, going by my discussion, we would use this. to disambiguate locals versus global, and not prefix items with underscores.

@guardrex
Copy link
Contributor Author

Nevermind my last remark here. I'm rambling a bit.

Let's close this. If a docs issue is opened to conform doc examples/samples to different coding style than the one we have, lay out the rules for me in the new docs issue. I'll go through and conform everything to the guidance.

Currently, the docs follow this pattern:

  • this isn't used in any Blazor sample or example. IIRC, this did appear in a few engineering code examples/samples that were handed to me, but I removed it in those cases ... placing me in the #NotThisSquad 😄. Those PRs were signed off on review, so I guess reviewers weren't too upset about my actions at the time.
  • All fields in @code blocks use an underscore.
  • I don't think we have any classes in @code blocks or Razor explicit expressions; but if we ever do, my intention is not to use underscores in those scenarios.
  • Members are explicitly marked private when that's the case.

The docs are internally consistent. The only discrepancy is between what devs see in a template-generated app and the docs. That's where I think devs might become confused 😵.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants