Re: Code as documentation
- From: Andrew Chen <hangfei@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 14:46:38 -0800 (PST)
Agree on end should have complete name. Emacs editor can do this
automatically.
6) Inside a module, declare everything as private, and everything
public must be explicitly declared. In another word, everything
default to be private.
7) Less or no comments. Use meaningful variable name of subroutine
names whenever possible. Obsolete comments can become poison. Try to
make the code readable first.
8) Try to generate other documents from source code.
Post processor that can pull documents out from the source code.
Fruit does one example for "executable requirement". The requirements
are written as test method name, or one variable spec inside the test
method.
Then a spec script can pull all of those in-code-requirement-document
out, to compile a document.
The benefits are obvious: 1) don't need to maintain a separate
reqirement document, or test plan document. 2) deadly clear about
which requirement is done, and which is not.
Example: ( http://fortranxunit.wiki.sourceforge.net/Executable+Specification+by+Fruit
)
in code:
subroutine
test_**calculator_should_produce_4_when_2_and_2_are_inputs**
use calculator, only: add
integer:: result
call add (2,2,result)
call assertEquals (4, result)
end subroutine
test_calculator_should_produce_4_when_2_and_2_are_inputs
in report:
fruit/sample/test >rake spec
(in fruit/sample/test)
All executable specifications from tests:
calculator
--
-- calculator should produce 4 when 2 and 2 are inputs
-- calculation should produce 4.0 when 2.0 and 2.0
are
inputs
-- calculator should remember previous calculation results
Thanks
~Andrew Chen
.
- References:
- Code as documentation
- From: David Flower
- Re: Code as documentation
- From: Richard Maine
- Code as documentation
- Prev by Date: How to quote the " character in a format statement?
- Next by Date: Re: passing a variable number of args/vectors to a routine
- Previous by thread: Re: Code as documentation
- Next by thread: Re: Code as documentation
- Index(es):
Relevant Pages
|
|