On Jan 9, 11:04*pm, "Lynn McGuire" <l...@winsim.com> wrote:
> How to write good code:
> * *http://xkcd.com/844/
>
> I usually follow the code fast branch myself.
Me too. There are some things to keep in mind when going to code fast:
1) It is often faster to write new code initially unintegrated from
rest of application. As result i do not need to build the whole
application to see if it compiles and links. I do not need to navigate
in whole application to particular place/situation to see if and how
it works.
2) It is faster to see if it compiles and how it behaves instead of
reading the code and imagining its behavior. For that purpose it is
good to write tests. Sometimes little separate unit tests are fine,
sometimes testing application can be made. Testability also indicates
how clear are requirements and how easy is to integrate the new code
with something else.
3) When i integrate my code with rest of the application then i pay
attention that it should be made cheap to throw it or its parts away
and replace with something else. New requirements *will* pop up always
(unlike comic tries to tell). If the initial design does not fit with
new requirements then it is often faster to write that part anew and
not to try and hack the previous attempt to meet new requirements.
4) GUI is terribly slow to test. It changes a lot depending on things
displayed, skins and styles and localization settings used, so
automatic test frameworks can somewhat support but not replace human
testers. Since GUI is something that share-holders see, the
requirements about it change most often. We try keeping GUI as
separate layer and never place application's business logic into GUI
layer. Then that layer can be replaced with fake "GUI" layer and usual
unit tests can be written using it.
5) The external devices and third party applications are in too
constant change ... quite like GUI and even more expensive to test. We
always aim to fake these things too, it ends up faster to market.
Some novice may think that i talk too lot about tests. Nope. Usually
more than 60% of to-market effort goes into discovering and dealing
with issues so that is the biggest part of real development and it
gives best effect to speed it up.
As for "good code" is code that my team members do understand and
accept when they read it. For achieving that we have review process.
Team members have to read each others code and then write what they
did not understand, what defects they saw and what did not fit with
coding policies that we have agreed to use. Defects discovered that
early are cheaper to fix too, so reasonable review process actually
speeds everything up and helps to achieve "good code" too.