httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sander Striker" <stri...@apache.org>
Subject RE: Minor(?) style questions
Date Tue, 12 Mar 2002 09:01:27 GMT
> 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

Mime
View raw message