Velocity Reviews > A stylistic question.

# A stylistic question.

Andrew Poelstra
Guest
Posts: n/a

 05-18-2006
On 2006-05-18, Bill Pursell <(E-Mail Removed)> wrote:
>
> Andrew Poelstra wrote:
>> On 2006-05-18, James Dow Allen <(E-Mail Removed)> wrote:
>> >
>> > CBFalconer wrote:
>> >> James Dow Allen wrote:
>> >
>> > In such a trivial case we can agree to quibble, or, better yet,
>> > disdain. But suppose one is doing a 3-D convolution:
>> >
>> > for (x = 0; x < Wid; x++)
>> > for (y = 0; y < Hei; y++)
>> > for (z = 0; z < Dep; z++) {
>> > valu = 0;
>> > for (xx = 0; xx < Filt->wid; xx++)
>> > for (yy = 0; yy < Filt->hei; yy++)
>> > for (zz = 0; zz < Filt->dep; zz++) {
>> > valu += Isig[x+xx+Xoff][y+yy+Yoff][z+zz+Zoff]
>> > * Filt->kern[xx][yy][zz];
>> > }
>> > Osig[x][y][z] = valu;
>> > }
>> >
>> > Anyone who will claim that this loop becomes "more readable" when four
>> > more levels of indentation are added has probably been over-indulging
>> > in ... (well, in another newsgroup, someone has taken to rhyming James
>> > with Flames and blames so let's avoid further charges of hyperbole).

>
>> Well, you could indent by less than 8 spaces:
>>
>> for (x = 0; x < Wid; x++)
>> for (y = 0; y < Hei; y++)
>> for (z = 0; z < Dep; z++)
>> {
>> valu = 0;
>> for (xx = 0; xx < Filt->wid; xx++)
>> for (yy = 0; yy < Filt->hei; yy++)
>> for (zz = 0; zz < Filt->dep; zz++)
>> {
>> valu += Isig[x+xx+Xoff][y+yy+Yoff][z+zz+Zoff]
>> * Filt->kern[xx][yy][zz];
>> }
>>
>> Osig[x][y][z] = valu;
>> }
>>
>> Now my deepest indentation is less than yours, with full indenting.
>> And it was /far/ easier to figure out what loop what is in.

>
>
> I disagree that it's easier. I actually very much like the
> non-indented
> nested loop style.
>
> This is going to change the subject a bit, but still talking about
> style, so I'll leave it in this thread. I've never found an
> indentation
> scheme for line continuations that I like. What do you think
>
> #define ____ /* to denote a continued line*/
>
> if (really_long_name -> a &&
> ____ (b == && (c & 0x0 ||
> ____ (another_boolean_condition) &&
> ____ (yet_another() == 2) ) {
> do _stuff()
> }
>
> I want something at the start of the line with the
> same level of indentation as the "if". "..." would
> be better than underscores, but "..." would clash
> with variadic function decldarations, and "...." isn't
> a valid name for a macro.
>
> At the moment I think using ____ is a pretty poor
> idea, but I'd really like to hear suggestions on
> better ways to do continuations. I've thought about
> column-aligning '\' at the end of the lines way out
> to the right, but it's not as much of a visual cue
> as I'd like. half or double indenting the continued
> line just doesn't work as well as it ought.
>

I align the continued line to the right side of the expression:
int x = 2 + 5 \
+ 6 / 2;

That looks terrible only because it is so artificial.

--

Andrew Poelstra < http://www.wpsoftware.net/blog >

Andrew Poelstra
Guest
Posts: n/a

 05-18-2006
On 2006-05-18, Andrew Poelstra <(E-Mail Removed)> wrote:
> On 2006-05-18, Bill Pursell <(E-Mail Removed)> wrote:
>>
>> This is going to change the subject a bit, but still talking about
>> style, so I'll leave it in this thread. I've never found an
>> indentation
>> scheme for line continuations that I like. What do you think
>>
>> #define ____ /* to denote a continued line*/
>>
>> if (really_long_name -> a &&
>> ____ (b == && (c & 0x0 ||
>> ____ (another_boolean_condition) &&
>> ____ (yet_another() == 2) ) {
>> do _stuff()
>> }
>>
>> I want something at the start of the line with the
>> same level of indentation as the "if". "..." would
>> be better than underscores, but "..." would clash
>> with variadic function decldarations, and "...." isn't
>> a valid name for a macro.
>>
>> At the moment I think using ____ is a pretty poor
>> idea, but I'd really like to hear suggestions on
>> better ways to do continuations. I've thought about
>> column-aligning '\' at the end of the lines way out
>> to the right, but it's not as much of a visual cue
>> as I'd like. half or double indenting the continued
>> line just doesn't work as well as it ought.
>>

> I align the continued line to the right side of the expression:
> int x = 2 + 5 \
> + 6 / 2;
>
> That looks terrible only because it is so artificial.
>

Oops. I quoted /way/ too much. These stupid slow
school computers take 2 seconds to delete an single line.

--

Andrew Poelstra < http://www.wpsoftware.net/blog >

ais523
Guest
Posts: n/a

 05-19-2006
Bill Pursell wrote:

> #define ____ /* to denote a continued line*/

<snip>

> At the moment I think using ____ is a pretty poor
> idea, but I'd really like to hear suggestions on
> better ways to do continuations. I've thought about
> column-aligning '\' at the end of the lines way out
> to the right, but it's not as much of a visual cue
> as I'd like. half or double indenting the continued
> line just doesn't work as well as it ought.

____ is in implementation namespace, because it starts with two
underscores, and therefore dangerous to use as a macro name.
Personally, I tend to indent the continued line to the point where the
bracketed expression containing it started, e.g.

my_array[my_function(6)] = another_function(45 + i*6 +
st2[7]);

Robert Latest
Guest
Posts: n/a

 05-19-2006
On 18 May 2006 09:44:43 -0700,
Bill Pursell <(E-Mail Removed)> wrote
in Msg. <(E-Mail Removed) .com>

> This is going to change the subject a bit, but still talking about
> style, so I'll leave it in this thread. I've never found an
> indentation
> scheme for line continuations that I like. What do you think

[...]

I always do it like this:

if (really_long_name -> a &&
(b == && (c & 0x0 ||
(another_boolean_condition) &&
(yet_another() == 2) ) {
do _stuff()
}

My "normal indent" is 4 spaces, but for continuations within if, for, or
while staements I use 8 and go back to 4 for the actual block.

For long funtion argument lists, I indent 4 spaces:

fprintf(stderr,
"...really long format string. In fact so long that the"
" string itself doesn't fit on a line",
foo, bar, baz,
and, many, more, args);

robert

pete
Guest
Posts: n/a

 05-19-2006
Robert Latest wrote:
>
> On 18 May 2006 09:44:43 -0700,
> Bill Pursell <(E-Mail Removed)> wrote
> in Msg. <(E-Mail Removed) .com>
>
> > This is going to change the subject a bit, but still talking about
> > style, so I'll leave it in this thread. I've never found an
> > indentation
> > scheme for line continuations that I like. What do you think

>
> [...]
>
> I always do it like this:
>
> if (really_long_name -> a &&
> (b == && (c & 0x0 ||
> (another_boolean_condition) &&
> (yet_another() == 2) ) {
> do _stuff()
> }

I prefer to start the broken lines with a binary operator,
if possible,
and to move the opening brace back to the "if" column.

if (really_long_name -> a
&& (b == && (c & 0x0
|| (another_boolean_condition)
&& (yet_another() == 2))
{
do _stuff()
}

Indian Hill
http://www.psgd.org/paul/docs/cstyle/cstyle06.htm

--
pete

James Dow Allen
Guest
Posts: n/a

 05-20-2006

Robert Latest wrote:
> On 18 May 2006 09:44:43 -0700,
> Bill Pursell <(E-Mail Removed)> wrote
> > I've never found an indentation scheme for line continuations that I like....

> I always do it like this:
>
> if (really_long_name -> a &&
> (b == && (c & 0x0 ||
> (another_boolean_condition) &&
> (yet_another() == 2) ) {
> do _stuff()
> }

I also do it that way: double-tab for the continuation.
Given my track record for other's liking my style, I hope
Robert doesn't decide to switch to something else now.

> My "normal indent" is 4 spaces, ...

My "normal indent" is one TAB character, and I'm amazed people
mess around with spaces. It seems futile to try a TAB other than
8 spaces, though I admit 6 spaces would be slightly better.
4 spaces of indentation is almost too little for my taste.
I *do* like being able to line up begins and ends easily, so if I was
ever forced to work on code that used (gasp!) 2-space indentation
I'd become an indent(1) fan *real* quick. (2-space indentation may
look
OK on little fragments, but am I the only one that ever puts more than
3 or 4 lines of code into the body of a for or if?)

James Dow Allen

Bill Pursell
Guest
Posts: n/a

 05-20-2006

James Dow Allen wrote:
> Robert Latest wrote:
> > On 18 May 2006 09:44:43 -0700,
> > Bill Pursell <(E-Mail Removed)> wrote
> > > I've never found an indentation scheme for line continuations that I like....

>
> > I always do it like this:
> >
> > if (really_long_name -> a &&
> > (b == && (c & 0x0 ||
> > (another_boolean_condition) &&
> > (yet_another() == 2) ) {
> > do _stuff()
> > }

>
> I also do it that way: double-tab for the continuation.
> Given my track record for other's liking my style, I hope
> Robert doesn't decide to switch to something else now.
>
> > My "normal indent" is 4 spaces, ...

>
> My "normal indent" is one TAB character, and I'm amazed people
> mess around with spaces. It seems futile to try a TAB other than
> 8 spaces, ...

<snip>

That's actually the motivation behind my looking for a new
continuation style. I've also used double indent for
continuations, but I've recently changed from being a
tabstop=4 person to being a tabstop=8, and 16 spaces
is too much for the line continuation. I don't want to
go to half-indents, because I'm trying to go back to
the tab-only indent style (I'm tired of using spaces
just to conform to the wishes of people
who don't know how to use an editor.)

It'd be cool if you could do:

if (this_is_the_first_line == 5 && \
\ this_is_the_continuation == 4)

and use the '\' to mark continuations both at the
end of the line and at the begninning.

pete
Guest
Posts: n/a

 05-20-2006
Bill Pursell wrote:

> (I'm tired of using spaces
> just to conform to the wishes of people
> who don't know how to use an editor.)

That's a good way to avoid the problem
if you're really capable of considering that to be a problem.

--
pete

Bill Pursell
Guest
Posts: n/a

 05-20-2006

pete wrote:
> Bill Pursell wrote:
>
> > (I'm tired of using spaces
> > just to conform to the wishes of people
> > who don't know how to use an editor.)

>
> That's a good way to avoid the problem
> if you're really capable of considering that to be a problem.
>

The only problem that occurs when you use tabs
for indentation is when someone else comes along
and edits the code using spaces. From my perspective,
once someone edits the code, the readability issue
and any problems that may occur are their own
responsibility. In other words, my code is very
own code? Readability problems that may occur
in edited versions that are descended from
my code are the responsibility of the person who

Is using tabs for indentation a decision I'll regret? Ask
me in 12 months.

Andrew Poelstra
Guest
Posts: n/a

 05-20-2006
On 2006-05-20, James Dow Allen <(E-Mail Removed)> wrote:
>
> Robert Latest wrote:
>> On 18 May 2006 09:44:43 -0700,

> I *do* like being able to line up begins and ends easily, so if I was
> ever forced to work on code that used (gasp!) 2-space indentation
> I'd become an indent(1) fan *real* quick. (2-space indentation may
> look
> OK on little fragments, but am I the only one that ever puts more than
> 3 or 4 lines of code into the body of a for or if?)
>

Am I the only one who ever nests blocks more than two levels deep?
Suppose I had a function that implemented Warshall's algorithm for
finding the transitive closure of a matrix. It's a function with
three loops nested inside of it.

Running anything inside of the third loop would take 8 spaces with
2-space indentation, while it would take 32 spaces with your tabbing
strategy (not to mention the fact that will these new GUI's people
are using, tab may or may not switch you from your editor window).

On a 80-character wide screen, I'd be taking up 32 spaces, which
is /40%/ of my line, with nothing but whitespace! Somehow 10% seems
more attractive.

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
Get your game faces on, because this is not a game.