Two Main Rules in Writing Code

1. High Cohesion
Which means that the written code has to be in a clear chronology and can be understood easily by everyone. Remember that every programmer can write code than computer understands, but only a good programmer can write code that human and computer understand.

Imagine that one day you wrote a bunch of code that runs, but was organized in a very awful way. There were so many temporary variables even you have to re-read every rows to get to know what they mean at the time you were developing it. Next month from that day you had to fix something in that piece of crap, what were you gonna do?
There are 2 things you could do here:
- next time you write a highly cohesive code, or
- resign from the job so you don't have to look at it anymore.

2. Low Coupling or Loosely Coupling
Which means that the code you write can't be tightly coupled between a method with another. You have to write a method in the way that in the future it's very easy to be used by another module, and you can easily change something without affecting another module.

Example:
- To change database server from MySQL to Oracle, is as easy as to edit some simple lines for database settings, and some adaptation in some query strings.
- To change the color of entire component in a GUI application, is as easy as editing 1 line only.
- To use a super-combobox you invented on an application you developed 3 months ago is as easy as compiling it into a jar and then using it.

0 comments: (+add yours?)