You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Sander Striker <st...@apache.org> on 2002/03/11 11:55:07 UTC

Minor(?) style questions

Hi,

Just checking if people have given this some thought before.
And, maybe if there was something decided on this matter.  For
instance, that this is free when it comes to style rules.

As some of you have noticed I am doing style reviews of/
corrections on the current httpd codebase, which has the nice
sideeffect of getting us some basic code review aswell.  With
everything in a consistent style, review by other parties will
be easier aswell.  Not to mention that one can probably read
the code quicker...

So, just a few simple questions:

1) Can we decide on a standard style when it comes to using
   ++ or --?

   Example:

   lines++;

   vs.

   ++lines;

   We are currently mixing this in the current code base.
   I personally favor the first.  And unless we are testing
   the variable in an expression, pre- or postfix doesn't
   matter for the resulting binary, only for readability.


2) How should a do {} while look like?

   do {
       ...
   } while (...);

   or

   do {
       ...
   }
   while (...);


3) What is the preferred method of doing an infinite loop?

   while (1) {
       ...
   }

   or

   for (;;) {
       ...
   }


Thanks,

Sander


Re: Minor(?) style questions

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Mon, Mar 11, 2002 at 05:14:47PM -0800, Greg Stein wrote:
> As with Bill and Jeff, I'd put #2 into the style guide, and leave the others
> out.

1+.  ;-)  -- justin


RE: Minor(?) style questions

Posted by Sander Striker <st...@apache.org>.
> From: root@localhost.localdomain [mailto:root@localhost.localdomain]On Behalf Of Eli Marmor
> Sent: 12 March 2002 12:39

> Sander Striker wrote:
>> Consider:
>> 
>>  lines += 1;
>> 
>> Which is the same as:
>> 
>>  lines++;
>> 
>> Personally I am slowed down when I see this:
>> 
>>  ++lines;
>> 
>> Because I am used to seeing the op _after_ the variable.
> 
> "lines++" is NOT the replacement of "lines += 1", but of "(lines+=1)-1"

Uhuh, true.  If you are going to use the statement inside an expression.
If you are not, and it is just a one-liner, as above, the meaning is the
same.
 
> Only "++lines" is the replacement of "lines += 1".
> 
> For example, if you have to increment "lines" and after that insert 2
> times of it into result, and you MUST do it in one instruction, then
> "result = 2 * (lines += 1)" can't be replaced by "result = 2 * lines++"
> but only by "result = 2 * ++lines". It's not styling; It's a totally
> different thing.

I am not going to be amused if I see something like your example being
used anywhere ;)

> What you are USED to see, is your own taste, but in this case, even the
> meaning is different.

You are missing my point.
 
> But again, the whole issue is minor...

Yeah, let's close this thread on that account.


Sander


Re: Minor(?) style questions

Posted by Eli Marmor <ma...@netmask.it>.
Sander Striker wrote:

> >>> 1) Can we decide on a standard style when it comes to using
> >>>    ++ or --?
> >>>
> >>>    Example:
> >>>
> >>>    lines++;
> >>>
> >>>    vs.
> >>>
> >>>    ++lines;
> >>
> >> I prefer the latter. The first thing your eye sees is the increment, then
> >> the variable. The *operation* is first, which is the most important.
> >
> > I'm very bad in styling, but I absolutely agree.
> 
> Consider:
> 
>  lines += 1;
> 
> Which is the same as:
> 
>  lines++;
> 
> Personally I am slowed down when I see this:
> 
>  ++lines;
> 
> Because I am used to seeing the op _after_ the variable.

"lines++" is NOT the replacement of "lines += 1", but of "(lines+=1)-1"

Only "++lines" is the replacement of "lines += 1".

For example, if you have to increment "lines" and after that insert 2
times of it into result, and you MUST do it in one instruction, then
"result = 2 * (lines += 1)" can't be replaced by "result = 2 * lines++"
but only by "result = 2 * ++lines". It's not styling; It's a totally
different thing.

What you are USED to see, is your own taste, but in this case, even the
meaning is different.

But again, the whole issue is minor...

-- 
Eli Marmor
marmor@netmask.it
CTO, Founder
Netmask (El-Mar) Internet Technologies Ltd.
__________________________________________________________
Tel.:   +972-9-766-1020          8 Yad-Harutzim St.
Fax.:   +972-9-766-1314          P.O.B. 7004
Mobile: +972-50-23-7338          Kfar-Saba 44641, Israel

RE: Minor(?) style questions

Posted by Sander Striker <st...@apache.org>.
> From: root@localhost.localdomain [mailto:root@localhost.localdomain]On Behalf Of Eli Marmor
> Sent: 12 March 2002 11:43

> Greg Stein wrote:
>> 
>> On Mon, Mar 11, 2002 at 11:55:07AM +0100, Sander Striker wrote:
>>> 1) Can we decide on a standard style when it comes to using
>>>    ++ or --?
>>>
>>>    Example:
>>>
>>>    lines++;
>>>
>>>    vs.
>>>
>>>    ++lines;
>> 
>> I prefer the latter. The first thing your eye sees is the increment, then
>> the variable. The *operation* is first, which is the most important.
> 
> I'm very bad in styling, but I absolutely agree.

Consider:

 lines += 1;

Which is the same as:

 lines++;

Personally I am slowed down when I see this:

 ++lines;

Because I am used to seeing the op _after_ the variable.


> ++something is simpler:
> 
> 1. Increment "something".
> 2. Use the result (in case it is a part of a bigger expression).
> 
> While something++ is more complicated:
> 
> 1. Keep the original value of "something".
> 2. Increment "something".
> 3. Use the original value, which was kept by rule #1 (in case it is a
>    part of a bigger expression).
> 
> Although under most hardware architectures, both expressions are
> compiled into the same number of instructions (even in case it is a
> part of a bigger expression),

It's just style.  Compilers should be smart enough to optimize both
notations equally.

> ++something should be the default, unless
> you specifically need something++.

I would go for the other way around for the reason above.

> But again: I'm bad in styling, so this is only my humble opinion...
> And the whole issue is really minor...

Indeed.  It doesn't go in the style guide because this is too minor
and there probably is never going to be full agreement on this ;)


Sander

Re: Minor(?) style questions

Posted by Eli Marmor <ma...@netmask.it>.
Greg Stein wrote:
> 
> On Mon, Mar 11, 2002 at 11:55:07AM +0100, Sander Striker wrote:
> > 1) Can we decide on a standard style when it comes to using
> >    ++ or --?
> >
> >    Example:
> >
> >    lines++;
> >
> >    vs.
> >
> >    ++lines;
> 
> I prefer the latter. The first thing your eye sees is the increment, then
> the variable. The *operation* is first, which is the most important.

I'm very bad in styling, but I absolutely agree.

++something is simpler:

1. Increment "something".
2. Use the result (in case it is a part of a bigger expression).

While something++ is more complicated:

1. Keep the original value of "something".
2. Increment "something".
3. Use the original value, which was kept by rule #1 (in case it is a
   part of a bigger expression).

Although under most hardware architectures, both expressions are
compiled into the same number of instructions (even in case it is a
part of a bigger expression), ++something should be the default, unless
you specifically need something++.

But again: I'm bad in styling, so this is only my humble opinion...
And the whole issue is really minor...

-- 
Eli Marmor
marmor@netmask.it
CTO, Founder
Netmask (El-Mar) Internet Technologies Ltd.
__________________________________________________________
Tel.:   +972-9-766-1020          8 Yad-Harutzim St.
Fax.:   +972-9-766-1314          P.O.B. 7004
Mobile: +972-50-23-7338          Kfar-Saba 44641, Israel

Re: Minor(?) style questions

Posted by Greg Stein <gs...@lyra.org>.
On Mon, Mar 11, 2002 at 11:55:07AM +0100, Sander Striker wrote:
> Hi,
> 
> Just checking if people have given this some thought before.
> And, maybe if there was something decided on this matter.  For
> instance, that this is free when it comes to style rules.

I think it is fine to make these consistent during your changes, but that
style rules on much of this isn't too important.

>...
> 1) Can we decide on a standard style when it comes to using
>    ++ or --?
> 
>    Example:
> 
>    lines++;
> 
>    vs.
> 
>    ++lines;

I prefer the latter. The first thing your eye sees is the increment, then
the variable. The *operation* is first, which is the most important.

>...
> 2) How should a do {} while look like?
> 
>    do {
>        ...
>    } while (...);
> 
>    or
> 
>    do {
>        ...
>    }
>    while (...);

If this isn't already in the style guide, then it should be, as the first
form. The control structure is matched with the block.

> 3) What is the preferred method of doing an infinite loop?
> 
>    while (1) {
>        ...
>    }
> 
>    or
> 
>    for (;;) {
>        ...
>    }

I prefer the former. The second form uses implicit rules about 'for', across
each of its three control components. Thus, you have to recognize the idiom
to quickly understand it, or take a small pause to process it. The while
form is also an idiom, but even simpler in construction.

As with Bill and Jeff, I'd put #2 into the style guide, and leave the others
out.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Minor(?) style questions

Posted by Bill Stoddard <bi...@wstoddard.com>.
\> > I would be in favor of
> > adding 2) to the existing guidelines
> 
> +0.4   (slightly nicer style IMHO, but such a specification conflicts
>        with desire to keep the style guidelines simple)
> 
> > and leaving 1) and 2) personal choice.
> 
> if you mean "leaving 1) and 3) personal choice": +1

Yes that is what I ment. Mr. Bimbo who lives in my finger has a different opinion :-)


Bill

Re: Minor(?) style questions

Posted by Jeff Trawick <tr...@attglobal.net>.
"Bill Stoddard" <bi...@wstoddard.com> writes:

> -----
> > Hi,
> >
> > 2) How should a do {} while look like?
> >
> >    do {
> >        ...
> >    } while (...);
> >
> >    or
> >
> >    do {
> >        ...
> >    }
> >    while (...);
> >
> 
> The first style is more compact and not less readable than the second, IMO.
> 
> >
> > 3) What is the preferred method of doing an infinite loop?
> >
> >    while (1) {
> >        ...
> >    }
> >
> >    or
> >
> >    for (;;) {
> >        ...
> >    }
> >
> I like using the while(1) style. No justification ...
> 
> >
> > Thanks,
> >
> > Sander
> 
> I would prefer to keep the style guidelines as small as possible.

+1!

> I would be in favor of
> adding 2) to the existing guidelines

+0.4   (slightly nicer style IMHO, but such a specification conflicts
       with desire to keep the style guidelines simple)

> and leaving 1) and 2) personal choice.

if you mean "leaving 1) and 3) personal choice": +1

-- 
Jeff Trawick | trawick@attglobal.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: Minor(?) style questions

Posted by Bill Stoddard <bi...@wstoddard.com>.
-----
> Hi,
>
> Just checking if people have given this some thought before.
> And, maybe if there was something decided on this matter.  For
> instance, that this is free when it comes to style rules.
>
> As some of you have noticed I am doing style reviews of/
> corrections on the current httpd codebase, which has the nice
> sideeffect of getting us some basic code review aswell.  With
> everything in a consistent style, review by other parties will
> be easier aswell.  Not to mention that one can probably read
> the code quicker...
>
> So, just a few simple questions:
>
> 1) Can we decide on a standard style when it comes to using
>    ++ or --?
>
>    Example:
>
>    lines++;
>
>    vs.
>
>    ++lines;
>
>    We are currently mixing this in the current code base.
>    I personally favor the first.  And unless we are testing
>    the variable in an expression, pre- or postfix doesn't
>    matter for the resulting binary, only for readability.
>
>

I would vote for both :-) Either are equally readable IMHO (I tend to use the first,
FWIW).

> 2) How should a do {} while look like?
>
>    do {
>        ...
>    } while (...);
>
>    or
>
>    do {
>        ...
>    }
>    while (...);
>

The first style is more compact and not less readable than the second, IMO.

>
> 3) What is the preferred method of doing an infinite loop?
>
>    while (1) {
>        ...
>    }
>
>    or
>
>    for (;;) {
>        ...
>    }
>
I like using the while(1) style. No justification ...

>
> Thanks,
>
> Sander

I would prefer to keep the style guidelines as small as possible. I would be in favor of
adding 2) to the existing guidelines and leaving 1) and 2) personal choice.

Bill