Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The Ten Commandments for C Programmers

Name: Anonymous 2014-04-03 15:55

1. Thou shalt run lint frequently and study its
pronouncements with care, for verily its
perception and judgment oft exceed thine.
2. Thou shalt not follow the NULL pointer, for
chaos and madness await thee at its end.
3. Thou shalt cast all function arguments to the e
xpected type if they
are not of that type
already, even when thou art convinced that
this is unnecessary, le
st they take cruel
vengeance upon thee when thou least expect it.
4. If thy header files fail to
declare the return types of t
hy library functions, thou shalt
declare them thyself with the most meticulous care, lest grievous harm befall thy
program.
5. Thou shalt check the array bounds of all strings
(indeed, all arrays),
for surely where thou
typest "foo" someone someday shall type
"supercalifragilistic
expialidocious".
6. If a function be advertised to return an e
rror 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 thinke
st "it cannot happen to me", the gods shall
surely punish thee for thy arrogance.
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.
8. Thou shalt make thy program's purpose and st
ructure 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.
9. Thy external identifiers shall be unique
in the first six charac
ters, though this harsh
discipline be irksome and the years of its neces
sity stretch before thee seemingly without
end, lest thou tear thy hair out
and go mad on that fateful da
y when thou desirest to make
thy program run on an old system.
10. Thou shalt foreswear, renounce, and abjure the
vile heresy which claimeth that "All the
world's a VAX", and have no commerce with th
e 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.

Name: Anonymous 2014-04-08 6:50

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

This hasn't been best practice since K&R. In fact littering casts all over the place is actively harmful if you're using an ANSI compiler, because doing so will suppress any type warnings that the compiler might otherwise emit. (Cf. C++, which still gets this wrong by requiring that void * be explicitly cast away.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List