Saturday, June 20, 2009

Change of style and plan for 6.20

How to write solid code from some web materials:

Write less code.


KISS and DRY. “Keep It Simple Stupid”: do what is required and no more. Focus on a clean and simple implementation. “Don’t Repeat Yourself”: avoid duplicating code. Refactor mercilessly. This will decrease the size of your code-base, which is a Good-Thing™ because the less code you write, the less bugs you write.

Use code analysis tools


In gcc or g++, using -Wall to eject warnings and errors.
open the preferences in Eclipse and activate most warnings for the Java compiler (be pragmatic). Use any lint-clone you can put your hands on for your language. Here are the tools I recommend for Java: JDepend to measure the quality of my abstractions and to avoid cyclical dependencies, PMD to identify potential bugs and potential optimizations, FindBugs to (coincidentally) find bugs.I should mention Checkstyle again since it can also detect bug patterns. The situation is simple: the more code analysis tools you run on your code the more you will be able to fix problems before they bite you.

Write unit-tests

I could almost have numbered it 1bis. Unit tests show and validate how the code is supposed to be used. Write the tests first if possible — unless you can get your hands on a time-machine, this is not an option when doing some maintenance. The quality of your interfaces will improve dramatically because you will design them from their user’s point of view.

Some personal feelings about the tests. Put a separate directory about the test files and illustrate what the result should be. When changing the code, do a regression test.

Read books about writing codes


Record the good practices and build the reusable libraries
The good practices usually are from the internet, and you may forget this after you use it! Record them in the reusable libraries would save you time and improve the quality of your code.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.