What is good code?
Code can be called as good code when it is
How to write good code? What are coding best practices?
In order to write good code, we need to follow/define coding best practices which should be followed by Junior Developer to Sr. Developer.
Below are some of the coding best practices i have come across:
- Naming convention: Decide which name convention to follow for variables/Methods/Classes etc
- Code refactoring: Remove dead code, duplicate code/Make reuse of code
- Simple code design: Keep design simple so that it is understandable to everyone and easy to maintain. Keep method/class size small.
- Pair programming: In case of complex code or when there are multiple scenarios to be implemented/tested, its better to do pair programming
- Continuous Integration: Make sure latest code is available to everyone working on project so that there are no integration issues later.It is always good practice to have common code base.
- Test driven development:Use tools like Nunit
- Making use of code review tools: Use tools like Fxcop, Stylecop or resharper for code reviews.
Test first vs Debugging approach:
It’s always good to have test driven development so that we have test cases ready and can be used by everyone. Debugging efforts are wasted and only helps for person who is working on it to write quality code. If same person continues to work on that module, he will not face much problem in identifying and verifying the scenarios.However there is no guarantee that all the scenarios will be tested.