Code Style and Best Practices
Naming Conventions
Class Names
Classes should be named using PascalCase, starting with an uppercase letter. For example:
public class DefaultListBinding
{
// ...
}
Method Names
Methods should be named using PascalCase, starting with an uppercase letter. For example:
public void AddItem(object item)
{
// ...
}
Variable Names
Variables should be named using camelCase, starting with a lowercase letter. For example:
private List<object> items;
Constant Names
Constants should be named using uppercase letters, separated by underscores. For example:
public const int MaxItems = 10;
Code Formatting
Indentation
Code should be indented using four spaces.
Line Length
Lines of code should be limited to a maximum of 120 characters.
Braces
Braces should be placed on their own line, and should be aligned with the opening statement.
if (condition)
{
// ...
}
Best Practices
Code Readability
- Use meaningful variable and method names.
- Keep methods concise and focused.
- Comment your code to explain complex logic or unusual behavior.
Error Handling
- Handle exceptions gracefully.
- Provide informative error messages.
Code Reuse
- Use existing code libraries and frameworks whenever possible.
- Extract common functionality into reusable methods or classes.
Security
- Validate user input.
- Avoid using insecure coding practices.