cuneiform team mailing list archive
-
cuneiform team
-
Mailing list archive
-
Message #00213
Re: Code style discussion
On Mon, Feb 2, 2009 at 3:35 PM, Dmitry Polevoy
<openocr.polevoy@xxxxxxxxx> wrote:
>> - beginning brace is always on the same line as
>> if/else/for/while/function definition/etc
>
> I prefer beginning brace on next line like
> if...
> {
> // if body
> }
> and AFIK this style is more convinient. If you use an editor (such as vi)
> that supports brace matching you can move to the opening brace hit a key and
> the editor finds the matching closing brace.
Don't all proper editors do this regardless of where the braces are?
Emacs at least does brace matching this way.
>> - no space between if/while/etc and parenthesis, one space after
>> comma/semicolon, like this:
>>
>> for(i=0; i<value; i++)
>
> I prefere insert single space after keyword (if/while, preprocessor, etc.)
> and not insert a space betwen function name and open brace '('.
> As a rules it can be like this:
> - Put a whitespace next to keyword. Do put round bracket next to function
> names without whitespace.
This is ok.
> - Semicolons in for statments should be followed by a space character.
> - Commas should be followed by a whitespace.
> func(par1, par2, par3);
> is better, then
> func(par1,par2,par3) ;
Yes for all these.
> As for white spaces I can suggest:
> - Binary (conventional) operators should be surrounded by a space character.
> sum = a + b * c;
> is better, then
> sum=a+b*c;
> - Remove trailing white spaces.
There is still the question whether we should have
sum = a + b * c;
or
sum = a + b*c;
The latter makes operator precedence more clear.
A few more issues. These are things that bug me about the current code.
Prefer functions to #define macros whenever possible.
No hungarian notation in new code.
Do not redefine elementary data types in new code. That is, use "char
*" rather than "PChar".
No handles in new code, pass pointers directly. This preserves type
safety. There is a lot of code that does this:
func((Handle) pointer_to_foo);
And then func starts with:
void func(Handle p) {
foo* my_pointer = (foo*) p;
The definition of func should be:
void func(foo* p);
Only define anything (structs, functions, data types etc) once. If
something is needed in many different places, move it to a distinct
header and include that.
Follow ups
References