C
C#2y ago
Kibar

❔ C# private methods capitalization convention

What is the official capitalization convention for private methods? The capitalization convention page (https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions) does not mention private methods explicitly. However the dotnet runtime repo enforces PascalCase for all methods (https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/coding-style.md number 13) So what is the official convention?
37 Replies
Anton
Anton2y ago
generally the convention is that all methods are pascal case to me, prefixing with _ also looks fine but that's just my opinion
ero
ero2y ago
A method?
Kibar
KibarOP2y ago
Generally yeah, but I am asking what the official convention is.
Anton
Anton2y ago
that's the convention that's what I'm saying
Kibar
KibarOP2y ago
Where can I find it in the Microsoft documentation?
ero
ero2y ago
Why do you need some website to say it...?
Kibar
KibarOP2y ago
Because I’d like to comply with official Microsoft guidelines and using the recommended best practices
ero
ero2y ago
So why do you need a website to say it There are no guidelines There are no "official" conventions You do whatever you want Or whatever your team does
Kibar
KibarOP2y ago
Capitalization Conventions - Framework Design Guidelines
Apply capitalization conventions for identifiers, compound words, and common terms. Understand how case sensitivity works in .NET.
ero
ero2y ago
No one is gonna put you in jail for not following these
Kibar
KibarOP2y ago
Sure, but that still does not answer my question.
Anton
Anton2y ago
I think they just forgot to mention it there
Anton
Anton2y ago
C# Coding Conventions
Learn about coding conventions in C#. Coding conventions create a consistent look to the code and facilitate copying, changing, and maintaining the code.
Anton
Anton2y ago
they say you should use pascal case for public things, but fail to mention private methods even tho in all their code they're Pascal Case
ero
ero2y ago
It even does mention methods Methods: PascalCase
Anton
Anton2y ago
open any codebase, they're pascal case
ero
ero2y ago
What more could you want
Kibar
KibarOP2y ago
Yep, hence I am asking what the official convention is. Because it’s undocumented.
Anton
Anton2y ago
If it bothers you, you can open an issue on the docs repo
ero
ero2y ago
The documentation Anton linked says "When naming public members of types, such as [...] local functions, use pascal casing." Which, while contradictory, lets me assume that private methods are also pascal case Like, a local function is not a public member by default
Jimmacle
Jimmacle2y ago
i don't know where it's literally written down, but 99% of c# codebases i've seen use pascal case for all methods
ero
ero2y ago
This dude won't even start writing code until literally every convention is laid out and documented
Jimmacle
Jimmacle2y ago
yeah i wouldn't worry about it too much you can just change it later if you decide you don't like how you're naming things
Kibar
KibarOP2y ago
That’s not the case. But I’d like to know what the official convention is. That’s all 🙂
Pobiega
Pobiega2y ago
its PascalCase for all methods. .NET is open source, you can read the source of the core libs.. its all PascalCase
ero
ero2y ago
you can also just do dotnet new editorconfig
Pobiega
Pobiega2y ago
editorconfig is best config
Kibar
KibarOP2y ago
I know I can and I have. But if it’s the official convention then why is it not mentioned in the example on the capitalization convention documentation? Anyways, I’ve created an issue on the docs repo.
Pobiega
Pobiega2y ago
Because noone has ever questioned it, in the last 20 years of C# development 😛
ero
ero2y ago
the truth is... nobody looks at or cares about that document. you follow whatever conventions you like. and if those happen to be the .net runtime conventions, which are the most widely used, then you line up with 99% of c# developers already
Pobiega
Pobiega2y ago
I don't understand why it needs to be explicitly stated, but I wont be sad if it gets added to the docs either. Its not like the docs suggest it would be any other way, and everyone except fleksi writes private methods as PascalCase, so its "convention by default"
Kibar
KibarOP2y ago
Because some people I am working with are not satisfied with “but the dotnet runtime repo uses it” so I need an official source from the C# docs stating what the convention is. But yeah I think in general you can’t go wrong with being more explicit with conventions Hence I opened an issue on the docs repo 🙂
Pobiega
Pobiega2y ago
And thats fine, good even. I agree with you that explicit is better than implicit, but how someone can read that document, the runtime contribution guidelines and all the open source code and say "you know what, its inconclusive!" is.... mindboggling
Kibar
KibarOP2y ago
🤷🏻‍♂️
sibber
sibber2y ago
but they are official
ero
ero2y ago
NOOOO
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server