Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2001:
[Freeciv-Dev] Re: Please vote!
Home

[Freeciv-Dev] Re: Please vote!

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Cc: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: Please vote!
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Fri, 30 Nov 2001 22:25:00 -0500

These sorts of restrictions or differentiations are largely a
waste of time, and in only one case is there any real technical
coding implication or possible benefit :-).

Cheers,
RossW
=====

At 12:37 PM 01/11/28 +0000, Gregory Berkolaiko wrote:
>Please vote more actively on the Coding Guideline Updated RFC
>
>Only 8 people have voted so far:
>
>Greg Wooledge:
>Daniel Sjölie
>Raimar Falke
>Tony Stuckey
>Petr Baudis
>Andrew Sutton
>Mike Kaufman 
>and meself
>
>(If you've sent an email but I haven't recorded you, please shout!)
>
>No vote -- no voice!
>
>G.
>
>> ============ Cut here.  Fill in blue ink only ==================
>> 
>> /*************** 
>>  * 1: init vars 
>>  ***************/
>> 
>> /* A */
>> int foo1a(struct city *punit)
>> {
>>   int x = punit->x;
>> }
>> 
>> /* B */
>> int foo1b(struct city *punit)
>> {
>>   int x;
>> 
>>   x = punit->x;
>> }

Either is acceptable, the first better in small routines, the second
when things start to get out of hand.

>> /**************************
>>  * 2: empty line after vars 
>>  **************************/
>> 
>> /* A */
>> int foo2a(void)
>> {
>>   int x;
>>   x = 3;
>> }
>> 
>> /* B */
>> int foo2b(void)
>> {
>>   int x;
>> 
>>   x = 3;
>> }

Either is acceptable, blank lines are commentary useful to separate code 
blocks, and the current example doesn't give enough context to make the
second a realistic 2 block grouping even if this wasn't a programmer
perogative (commentary is always suggested, never imposed).

>> /****************
>>  * 3: comments 
>>  ****************/
>> 
>> /* A */
>> int foo3a(int x)
>> {
>>   x = 3;                     /* assign 3 to x */
>> }
>> 
>> /* B */
>> int foo3b(int x)
>> {
>>   /* assign 3 to x */
>>   x = 3;
>> }

A in macros because of macro peculiarities, B elsewhere - most of the time.

>> /**************************
>>  * 4: extra {} on iterates 
>>  **************************/
>> int foo4(struct city *pcity)
>> {
>> 
>>   /* A */
>>   unit_list_iterate(pcity->units_supported, punit) {
>>     kill(punit);
>>   } unit_list_iterate_end;
>> 
>>   /* B */
>>   unit_list_iterate(pcity->units_supported, punit)
>>       kill(punit);
>>   unit_list_iterate_end;
>> }

A slightly preferred, it is more of a do { ... } while(); construct
with an explicit code block. Also adding an "} else {" makes more
logical sense in cases where the macro is so coded.

But the macro should allow the other under "do more, expect less rules".

>> /****************************************** 
>>  * 5: unnecessary braces after conditionals 
>>  ******************************************/
>> int foo5(int x)
>> {
>> 
>>   /* A */
>>   if (x == 3) {
>>     return;
>>   }
>> 
>>   /* B */
>>   if (x == 4)
>>     return;
>> }

Either is allowed.

>> /**************************************************** 
>>  * 6: unnecessary braces after conditionals with else 
>>  ****************************************************/
>> int foo6(int x)
>> {
>> 
>>   /* A */
>>   if (x == 3) {
>>     return 1;
>>   } else {
>>     return 0;
>>   }
>> 
>>   /* B */
>>   if (x == 4)
>>     return 1;
>>   else
>>     return 0;
>> }

Either is allowed

>> /****************************
>>  * 7: merge declaration lines
>>  ****************************/
>> 
>> /* A */
>> int foo7a(struct city *pcity)
>> {
>>   int total, cost;
>>   int build = pcity->shield_stock;
>> }
>> 
>> /* B */
>> int foo7b(struct city *pcity)
>> {
>>   int total, cost, build = pcity->shield_stock;
>> }

Either is allowed

>> /*************************
>>  * 8: double dereferencing
>>  *************************/
>> 
>> /* A */
>> int foo8a(struct city *pcity)
>> {
>>   struct player *owner = city_owner(pcity);
>>   struct nation_type *nation = get_nation_by_plr(owner);
>> }
>> 
>> /* B */
>> int foo8b(struct city *pcity)
>> {
>>   struct player *owner = city_owner(pcity);
>>   struct nation_type *nation;
>> 
>>   nation = get_nation_by_plr(owner);
>> }

Same as 1, but if you don't allow A, then disallow B as well and choose 
case C :-). 

>> __________________________________________________
>> Do You Yahoo!?
>> Everything you'll ever need on one web page from News and Sport to
>> Email and Music Charts
>> http://uk.my.yahoo.com
>>  
>
>__________________________________________________
>Do You Yahoo!?
>Everything you'll ever need on one web page from News and Sport to Email
and Music Charts
>http://uk.my.yahoo.com




[Prev in Thread] Current Thread [Next in Thread]