Saturday, October 8, 2011

Principles to follow while coding

Simplicity leads to better code.
Keep-It-Simple-Stupid (KISS)

Don’t optimize prematurely.
It is much better to get the design of your code right and leave performance improvement as a separate task requiring separate skills,

Interfaces promote flexibility of design.
Interfaces enable us to define the contract without regard to the underlying implementation. Because of this, they give us flexibility in our design by facilitating pluggability of implementation.

All production code should be covered by automated unit and functional tests.
Modern development practices demand that our software be rigorously united and functionally tested to ensure the ongoing integrity of the code. In keeping with this approach, after defining the interface, but before defining any concrete implementation, we translate our functional requirements into test cases, ensuring that every assumption has been covered and confirmed.

This approach, also known as test-driven development (TDD), forces us to concentrate on the contract, the published behavior, of our classes, rather than the implementation.

Assertions are a developer’s best friend.
 Check for null pointers; assert that objects are in the correct state at the start of a method, and so on.

No comments:

Post a Comment