Here I describe coding style and conventions you would encounter when going over my source codes. Most of them are easy to follow and understand.
- Pascal casing: the first character of all words is upper case and the rest of characters are lower case.
- Camel casing: the first character of all words, except the first word, is upper case and rest of characters are lower case.
Assemblies and Projects
The name of the assembly and project should follow one of those patterns:
They should be meaningful. It should always start with the name of the assembly, and the rest of it should be aligned with the project directory structure. Do not abbreviate the namespace. Use pascal casing.
Class name should always be a noun. Use pascal casing.
Name methods as verbs or verb phrases. Use pascal casing. Member arguments’ casing should be camel.
Private and Protected Member Variables
Member variables would start with “_“. Use pascal casing.
Public Member Variables
There is no restriction to the naming and casing of public member variables. Just do NOT use them at all.
Properties should not contain contain too much logic and computations inside. In most of the cases properties would just return the private variable and modify the same. Inside the property setter check the value for equality, and don’t overwrite the member variable if the new value is same as existing (it will help you when you fire the PropertyChanged event inside the property). Do not abbreviate properties. If the property type is boolean, it should start with “Is” or “Has”, and the name of the property should be grammatically correct and would represent the its meaning. In the rest of cases properties would be nouns. Use pascal casing.
Constants and Readonly Fields
Do not abbreviate. Use Pascal casing. Do not create Properties for static constants and readonly members.
Event name should be a verb phrase in past tense. Do not include any prefix (i.e. “On”). For each event create a private or protected method with OnYourEventName which fires the particular event.
Start the interface with “I” letter. The name should be a noun. Use pascal casing.
Open scopes only when you want to emphasize an important block of code. Avoid redundant scopes. Follow practices from Scope Nightmare to make the code more readable and reusable.
2009-03-01 07:55 +0000
9e0398a @ 2019-04-18