The best practice is a **_method _**or **_technique _**that has been generally accepted as **_superior _**to any alternatives because it produces results that are superior to those achieved by other means or because it has become a standard way of doing things, e.g., a standard way of complying with legal or ethical requirements.
Best Practices Help you by:
- Understand the code quickly.
- Facilitate copying, changing, and maintaining the code.
1. Naming and handling classes
The **benefits **of proper class naming and naming conventions:
- You know what to expect from a certain class without looking at code or documentation, even if you aren’t the person who created it or if it was written a long time ago.
- It’s easy to search and navigate a codebase.
- It’s easier to talk to your team when discussing problems/improvements.
- It makes onboarding newcomers easier, quicker, and less confusing.
Names Rules
- Choose descriptive and unambiguous names.
- Make a meaningful distinction.
- Use pronounceable names.
- Use searchable names.
- Replace magic numbers with named constants.
- Avoid encodings. Don’t append prefixes or type information.
2. Naming and handling methods, fields, and properties
Method Overloading:
**Overloading **is used (recommended) when multiple methods have the same purpose but there is more than one way to start it.
Methods rules:
- Small.
- Do one thing.
- Use descriptive names.
- Prefer fewer arguments.
- Have no side effects.
- Don’t use flag arguments. Split method into several independent methods that can be called from the client without the flag.
#web-development #dotnet #programming #c#