Next: Coding Guidelines
Up: Programming in Opus and
Previous: Programming by Contract
Index
These design guidelines are key rules that, if followed, will help you
create code that is easy to develop and to maintain.
- Practice test-driven development. Before you write
any code, write an automated test that tests if that code works.
Use this for new features as well as bug fixes.
- Include automated unit tests. A unit test tests an internal part
of the code, such as a method. A method is a contract: given
certain assumptions about the data used by the method, the method
is guaranteed to produce certain data. A good rule of thumb is to
have at least one unit test for every contract of every method. As
always, use your judgment as to what tests to write.
- Include automated acceptance tests.
- Never duplicate code. Avoiding duplication results in lots of good, such
as decoupled designs.
- Favor composition over inheritance.
- If you can think of a reason you want to use different
versions of a method, convert the method to an class and use
composition.
- Relentlessly keep your abstractions current with your
understanding of the system.
- Have an abstraction for every ``real world'' object that the modeler
interacts with, e.g. ``a run request,'' ``a queue of run requests,'' etc.
- Create decoupled designs. A class C should only know about another
class B when C's abstraction requires knowledge of B.
Next: Coding Guidelines
Up: Programming in Opus and
Previous: Programming by Contract
Index
info (at) urbansim.org