#header-inner {background-position: right !important; width: 100% !important;}

8/6/12

Few thoughts on code quality (for professionals).

In my opinion java code of quality should have following properties:

1. Proper naming of classess, methods, variables and constants.
2. Single, properly defined and documented responsibility of each class and method. No unneccessary code (to remove code duplication you can use constants (final keyword, UPPERCASE_NAMES) and split methods with large chunks of code into few smaller methods so you can reuse them. To ensure single responsibility of method or class move some code into another method or class. Single responsibility class or method is more reausable and easier to document, read, test and modify. [or to break if someone wants to try firing quality coder].). Single responsibility of method may involve calling more than one instruction as long as it is considered atomic. For example: changeStateWithSideEffect(...);
3. Documented methods headers (first lines of methods and all information therein, including variable names) according to javadoc documentation.
4. Use of assert keyword, software contracts, preconditions, postconditions and invariants.

Later JUnit/Easymock automated tests can be added to build test harness.

It also should be properly formatted.

Commits should be commented.

Methods should be abstract, empty or final.

Ideally, methods should consists of three instructions. init(...); transform(...); return [(...)]; Complex instruction counts as single instruction;

There can be more requirements , but in practice it's almost perfect if these are used. Professionals after all have no time to comment code, or they want to be priceless and unfirable by bosses.


See also: Design by Contract, Code Reuse.

1 comment:

  1. I was Inspired by Martial Arts Philosophy when i developed this method. Shortest path moves are most difficult to defend against (least amount of time for reaction). It's also most powerful as Force is Acceleration Squared times Mass. (F=a^2*m). It's law. Of Physics. So no unneccessary characters. Especially hidden.

    ReplyDelete