Re: Coding Standards
On Sep 2, 1:42 am, Jerry Coffin <jcof...@taeus.com> wrote:
In article <F7Cdnc-Fcu9fl0XbnZ2dnUVZ_hudn...@adelphia.com>,
phlip...@yahoo.com says...
[ ... ]
(For those of you just tuning in, class methods should be 1
to 5 lines, even in C++,
While this can sometimes be true, there are other times that trying to
break up a routine that's naturally large can result it it becoming less
readable and maintainable rather than more so.
While 1 to 5 lines sounds a bit too strict, anytime a function
gets longer than about 10 lines, I start asking myself
questions. As always, however, there are exceptions: a single
switch with 100 cases, each of which is a single line, is not a
problem, and trying to break it into smaller functions is
definitly counter productive.
A more general rule for function complexity would involve levels
of nesting of control structures, or the number of different
paths through the function.
and every comment should be treated as a failed opportunity
to add self-documenting identifiers, assertions, or unit
tests...)
Only if you don't know what sort of comments to write.
Comments should generally be devoted to things like _why_ you
did something -- e.g. why it's important to have used a prime
number for the size of this particular array, or why it was
important to use one sorting algorithm instead of another.
I also find comments as to why you didn't do something to be
important: why you didn't use the obvious simple solution (which
maybe not so obviously doesn't work).
These reasons are not reasonable to explain in identifiers,
assertions, unit tests, etc.
More importantly, assertions and unit tests aren't part of the
documentation. Unit tests, in particular, should be reviewed
against the documentation, to ensure that all requirements and
limit cases are checked---unit tests without a requirements
specification (documentation) are meaningless.
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34