A class is based on Single responsibility principle.
We provide regions in class to surround block of code. I could be single or multiple methods.
Regions makes it easier to navigate around large files.
But if a class does too many things it will violate Single responsibility principle.
So for different kind of task use different class.
Prefer short methods
In most of the projects , we have complex logics which result into large methods.
The best practice says , method should be ended in 1-10 LOC.
When we have a method with large LOCs, select block of codes and use extract method.
This ends up in making another method for a selected purpose. This helps in increasing readability of the code.
Avoid too many parameters
Instead of using too many parameters its better to make a class with required parameters.
Avoid complex expressions
Its better to have a property with complex logics.
Consider the project warnings also.
On building , we get errors and warnings both. Usually we solve error and ignore warnings. This is a bad practice.
We should have project level settings to give error for more than 4 warnings.
Project -> csharp-code Properties -> build -> Error and warnings
Avoid handling non specific exceptions using System.Exception, System.SystemException. These can be used but rarely.This results in unexpected state of the application.
Instead of using this, its better to terminate the process.
Do not handle non cls complaint exceptions using parameter less catch blocks.
0 Comment(s)