Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ten Commandments For C Programmers

2,870 views
Skip to first unread message

Henry Spencer

unread,
Oct 14, 1987, 5:35:26 PM10/14/87
to
Sparked by some comment somewhere or other, I have decided to compose The
Ten Commandments for C Programmers. Here's what I came up with.

Note that this is addressed to C, not Unix or programming in general, and
that I have no hope of attacking all the different sins that C programmers
commit -- I just want to cover the ten worst ones.

------------
.TL
The Ten Commandments for C Programmers
.AU
Henry Spencer
.IP 1
Thou shalt run \fIlint\fR frequently and study its pronouncements with
care, for verily its perception and judgement oft exceed thine.
.IP 2
Thou shalt not follow the NULL pointer, for chaos and madness await thee at
its end.
.IP 3
Thou shalt cast all function arguments to the expected type if they are not
of that type already, even when thou art convinced that this is unnecessary,
lest they take cruel vengeance upon thee when thou least expect it.
.IP 4
If thy header files fail to declare the return types of thy library functions,
thou shalt declare them thyself with the most meticulous care,
lest grievous harm befall thy program.
.IP 5
Thou shalt check the array bounds of all strings (indeed, all arrays),
for surely where thou typest ``foo'' someone someday shall type
``supercalifragilisticexpialidocious''.
.IP 6
If a function be advertised to return an error code in the event of
difficulties, thou shalt check for that code, yea, even though the checks
triple the size of thy code and produce aches in thy typing fingers,
for if thou thinkest ``it cannot happen to me'',
the gods shall surely punish thee for thy arrogance.
.IP 7
Thou shalt study thy libraries and strive not to re-invent them without cause,
that thy code may be short and readable and thy days pleasant and productive.
.IP 8
Thou shalt make thy program's purpose and structure
clear to thy fellow man by using the
One True Brace Style,
even if thou likest it not,
for thy creativity is better used in solving problems than in creating
beautiful new impediments to understanding.
.IP 9
Thy external identifiers shall be unique in the first six characters,
though this harsh discipline be irksome and the years of its necessity
stretch before thee seemingly without end,
lest thou tear thy hair out and go mad on that fateful day when
thou desirest to make thy program run on an old system.
.IP 10
Thou shalt foreswear, renounce, and abjure the vile heresy which claimeth
that ``All the world's a VAX'', and have no commerce with the
benighted heathens who cling to this barbarous belief,
that the days of thy program may be long even though the days of thy
current machine be short.
------------
--
"Mir" means "peace", as in | Henry Spencer @ U of Toronto Zoology
"the war is over; we've won". | {allegra,ihnp4,decvax,utai}!utzoo!henry

0 new messages