In article <>,
says...
> On Wed, 4 Nov 2009 23:10:37 +0100, "Geek" <> wrote:
>
> >What coding standard are you using for C (if any)?
> >
> >Like naming variables, functions, constants, globals, locals, types etc.?
Choice of fonts printed can have a bearing avoid the ONE and L
confusions, let alone the zero and letter o confusions. There
are others.
> What ever you choose, keep it throughout the project.
> >
> >for example:
> >
> >MyFunction();
> >myFunction();
My personal preference on that would be how the parntheses are done
always put a space between, even for empty list. Avoids problems
with some fonts the parentheses being confused as a letter eg 0.
> I myself prefer:
.....
> Opening braces are in the line of if/while/for/do/switch, indention 2
> spaces.
More importantly indent with spces the block of code by the
same amount. Tabs can be different on systems/IDE/editors
> Code should be readable, so no
> if(i==1||i==4)
> but
> if ( (i == 1) || (i == 4) )
My personal method is ensure the opening parentheses for functions,
language construct ( if, while.. ) are by the name. All others spaced
out, so in a complex if( .... ), it becomes easier to spot at a glance
what is a function and what is a variable.
> Use spaces, good code should not look like prose rather like poetry.
Despite C, being free format, avoid too much free format, remembering
that at some time it may well be printed, 300 character lines wrap
very interestingly, if they wrap. Choosing indentation matching
can make following the code easier, even if you have managed
to get the function to fit on one page.
Look up 'obfuscated C' for examples of how not to do things, one
year they had code that compiled correctly but printed out you could
see the code made a picture.
> But of course, writing code for customers forces other styles.
>
--
Paul Carpenter |
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate