PDA

View Full Version : The ten commandments for c programmers


descapa
03-30-2003, 07:30 AM
Just in case you have never seen this before I thought you might like it. enjoy

The source is here:
http://www.lysator.liu.se/c/ten-commandments.html

1 Thou shalt run lint frequently and study its pronouncements with care, for verily its perception and judgement 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 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.

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.

5 Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.

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.

7 Thou shalt study thy libraries and strive not to reinvent 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 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.

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.

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.

Stanley
03-30-2003, 02:09 PM
I would like to mention that this applies to other serious programming languages as well. I want know Java people thinking they don't have to follow them.

jyorke
03-30-2003, 02:40 PM
lar, some of these are somewhat out of date. My comments:

1- People rarely use lint anymore... use gcc/g++ -Wall and heed all warnings
2- Chaos and madness certainly do await thee at the end of the null pointer, as well as uninitialized variables. Take heed!
3- Newer compilers are much better at implicit casts. However, casting arguments is indeed a good idea.
4- This is not an issue in ANSI-complient C, but it should be heeded when working with non-complient (OLD) code.
5- Bounds checking is the single most important thing you can do. Heed this, and never use gets()
6- Error checking is important. Do it.
7- Always use code available for you. Don't reinvent the wheel.
8- The one true brace style is ugly. I prefer the next-line brace. However, you must always pick one style and stick with it.
9- Always a good idea to maintain portability.
10- Don't fool yourself... 64-bit is here now in Sparc, PowerPC, and Itanium, and soon coming in x86-64 flavor. If you program for only 32-bit, you aren't being smart...

Stanley
03-30-2003, 03:47 PM
Just because 64-bit is here, doesn't mean that general programming should be done for it. 32-bit is the safest to write for until 64 becomes more wide-spread. 90% of users can't make use of 64-bit code.

As for the one true brace style, I hate when people put the brace on a new line. Drives me friggen crazy. But justin is right, if you must be a heathen and go astray from the one true style, do it consistantly.

rosemary
04-07-2003, 04:30 PM
aww come on guys, you all know FORTRAN is the only logical choice for real (wo)men everywhere

jyorke
04-07-2003, 05:13 PM
</span>Quote[/b] (rosemary @ April 07 2003,15:30)]aww come on guys, you all know FORTRAN is the only logical choice for real (wo)men everywhere<span =''>
Strangly enough, the only people I know who have ever coded in FORTRAN are women....

04-13-2003, 10:31 PM
</span>Quote[/b] ] aww come on guys, you all know FORTRAN is the only logical choice for real (wo)men everywhere<span =''> ...So says my java instructor...how strange.

ifette
05-01-2003, 10:37 PM
Actually, I'm more of a COBOL guy, personally, but as long as we're on the subjects of c(++) commandments, can we please not forget the most important?

#0: Thou shalt not use GOTO, lest ye cause thine self much agony.

// Ian - ifette AT engin DOT umich DOT edu (spambots are everywhere...)
--
Missed the 2003 staff application deadline, but oh well :-) Have fun all who are attending.

Lain
05-12-2003, 12:44 PM
damn strait about FORTRAN. first and only language my mother ever learned...
she's 50...
doesn't that make all you silly people feel young?

pascal... wheee... the true language of foxtrot.

Stanley
05-13-2003, 03:47 AM
Actually, it doesn't. Mainly because I have to realize that when I was born, an atari 2600 was hot stuff and processors being faster than 100mhz a far off dream. Then again, I also remember when Wolfenstien 3d was the sweetness.