Re: Coding Standards

2003-08-14 Thread Alan Ingleby
"Jeff Wheeler" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> 1. Function definition allows parameters to be commented. I also switched
> the order so that inputs were listed first and outputs last.

I've always preferred to have the outputs first, and the inputs last.  But
that's just me.  I think of it as A=B : Assignment from right to left.

> 4. Tabs set to four spaces.

Yes.. and *real* tabs

Oh and I don't break my lines at 80 chars either... I have a 19" monitor, so
my lines are still all visible at around 150 chars :-)

So much for making our choice for a standard easier huh?.. I think I'll just
have to try to get the team to "do as I do"... There's just too many
variations...

Alan




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


RE: Coding Standards

2003-08-14 Thread Jeff Wheeler
In a previous post, Alan Ingleby wrote:
>> What's the generally preferred way of structuring a 
>> switch statement? (This is mine...)
>>
>> void MyFunc(Char* buffer, UInt32 type) {
>>   switch(type) {
>> case 1:
>>   StrCopy(buffer, "One");
>>   break;
>> case 2:
>>   StrCopy(buffer, "Two");
>>   break;
>> default:
>>   StrCopy(buffer, "Huh?");
>>   break;
>>   }
>> }

One more opinion, similar to Keith's:

/*
 ---
MyFunc

Any relevant comments about the function's purpose and usage go
here.
 ---
*/

void MyFunc(// no return value; always works
UInt32 type,// [in] what number you want
Char* buffer)   // [out] loaded with results, must be X bytes

{
switch(type)
{
case 1:// This is an example with braces.
{
StrCopy(buffer, "One");
break;
}

case 2:// This is an example without braces.

StrCopy(buffer, "Two");
break;

default:

StrCopy(buffer, "Huh?");
break;
}
}

Some comments:
1. Function definition allows parameters to be commented. I also switched
the order so that inputs were listed first and outputs last.
2. The { and } are part of the block, so are on a new line and are indented
to the same level as the block.  K&R don't get this right, either. ;-)
3. White space (especially between lines) is good.
4. Tabs set to four spaces.

Jeff
 





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: Coding Standards

2003-08-14 Thread Chris Faherty
On Tuesday 12 August 2003 09:11 pm, Alan Ingleby wrote:

> (This is mine...)
>
> void MyFunc(Char* buffer, UInt32 type) {
>   switch(type) {
> case 1:
>   StrCopy(buffer, "One");
>   break;
> case 2:
>   StrCopy(buffer, "Two");
>   break;
> default:
>   StrCopy(buffer, "Huh?");
>   break;
>   }
> }

Hmm.  This is fun..

void MyFunc(Char* buffer, UInt32 type)
{
switch (type) {
case 1:
StrCopy(buffer, "One");
break;
case 2:
StrCopy(buffer, "Two");
break;
default:
StrCopy(buffer, "Huh?");
break;
}
}

This can be summarized as:
indent -gnu -brs -br -ce -i4 -ncs -npcs -nprs -l80 -npsl -nut -nlp -ci4

Which I use to change PalmOS coding style sources into something usable :)

-- 
/* Chris Faherty <[EMAIL PROTECTED]> */

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


RE: Coding Standards

2003-08-14 Thread Keith Rollin
That's close to mine.  Personally, I'd have it as:

void MyFunc(Char* buffer, UInt32 type)
{
switch(type)
{
case 1:// This is an example with braces.
{
StrCopy(buffer, "One");
break;
}

case 2:// This is an example without braces.
StrCopy(buffer, "Two");
break;

default:
StrCopy(buffer, "Huh?");
break;
}
}

That is: braces always line up, and use 4-space TABs (I'm using spaces above since not 
all email programs expand TABs the way I'd like them).

I hate the way MS lines the case statement under the switch statement.

-- Keith

--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


Re: Coding Standards

2003-08-14 Thread Stuart Eichert
> 4. Tabs set to four spaces.
> 
> Jeff
>  
4 space good, two space bad?

This sounds like a religious war in the making.  So I say 2 spaces for a tab
and don't use tab characters.  If you can cleanly fit your code into 80
columns that would also be nice (though I realize that is unlikely for
Palm OS).

-- 
Stuart Eichert
Copera, Inc.
[EMAIL PROTECTED]


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/


RE: Coding Standards

2003-08-14 Thread Jeff Wheeler
Jeff:
>> 4. Tabs set to four spaces.

Stuart:
> 4 space good, two space bad?
>
> This sounds like a religious war in the making.  So I say 2 
> spaces for a tab and don't use tab characters.  If you can 
> cleanly fit your code into 80 columns that would also be 
> nice (though I realize that is unlikely for Palm OS).

2?  Fine.  4?  Fine.  Just not 3!  ;-)  (just kidding)

Isn't the advantage of tabs that if you and I are sharing code and using
well-mannered IDEs, you can set your tabs to be 2 spaces wide and I can set
mine to 4 spaces wide, and we're both happy?

I expected more guff over the { and the } than the tabs and spaces!

On a slightly related note, I've always thought that programming is a
pleasant mix of both science and art.  There's a certain aesthetic about a
well written function that also looks good.  Of course, code beauty is in
the eye of the beholder.

Jeff




-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/