A stylistic question.

B

Bill Pursell

Ben said:
Really? Do you not line up continuation lines after parentheses?
long_function_name (long_function_argument_1,
long_function_argument_2,
long_function_argument_3,
long_function_argument_4);

Generally not. I find that it often degenerates into:

long_variable_name = long_function_name (a,

b);

and I don't like the massive indent to the second argument. I prefer
to do:
long_funct_name (
a,
b,
);

and match the indentation of the closing ')' with that of the function
call
(or the variable being assigned to). I'm not entirely happy with
that style, but I prefer it to aligning with the open paren. Actually,
the
main reason I went to that style was because of the difficulty
in changing the apparent indentation with the other style. I really
work hard to have parameter lists and names short enough so
that I don't have to continue the line, which is tough considering
that I like very descriptive names and generally spell words out
completely. Thr's nthing wrse than arbtrary and incnsstnt removal
of vwls. :)
 
G

Guest

Ben said:
Really? Do you not line up continuation lines after parentheses?
long_function_name (long_function_argument_1,
long_function_argument_2,
long_function_argument_3,
long_function_argument_4);

Personally, I tend to use tabs for indentation, but only for that,
exactly to avoid this kind of problem. (I also make sure my editors
show tabs.) To be specific, your example, if I would write it in your
form at all, would be
<tab>long_function_name (long_function_argument_1,
<tab> long_function_argument_2,
<tab> long_function_argument_3,
<tab> long_function_argument_4);
 
I

Ian Collins

Harald said:
Personally, I tend to use tabs for indentation, but only for that,
exactly to avoid this kind of problem. (I also make sure my editors
show tabs.) To be specific, your example, if I would write it in your
form at all, would be
<tab>long_function_name (long_function_argument_1,
<tab> long_function_argument_2,
<tab> long_function_argument_3,
<tab> long_function_argument_4);
How does this work with auto-indent in your editor?
 
G

Guest

Ian said:
How does this work with auto-indent in your editor?

After pressing Return after long_function_argument_2, I end up with one
tab, followed by a bunch of spaces, on the next line. (This is in
KDevelop.)
 
I

Ian Collins

Harald said:
After pressing Return after long_function_argument_2, I end up with one
tab, followed by a bunch of spaces, on the next line. (This is in
KDevelop.)
Does this work if you move a bit of nested code to another indentation
level or its own function? Just curious, I've never seen an auto-indent
work with a mix of spaces and tabs.
 
G

Guest

Ian said:
Does this work if you move a bit of nested code to another indentation
level or its own function? Just curious, I've never seen an auto-indent
work with a mix of spaces and tabs.

No, unfortunately that doesn't seem to work properly. Depending on the
configuration, I can manage to either get the spaces replaced with a
mix of tabs and spaces, or the tabs replaced with spaces. This is after
selecting text, and then pressing the key to indent/unindent the
selection. That is what you meant, right?
 
I

Ian Collins

Harald said:
No, unfortunately that doesn't seem to work properly. Depending on the
configuration, I can manage to either get the spaces replaced with a
mix of tabs and spaces, or the tabs replaced with spaces. This is after
selecting text, and then pressing the key to indent/unindent the
selection. That is what you meant, right?
Yes. I think indentation style should be automatic, or at least lend
itself to automation, otherwise it (having to fix up manualy) becomes an
obstruction to code refactoring.
 
B

Bill Pursell

What do you do when you refactor a bit of code and extract some indented
code into a function?

That is definitely the key question. I think I've been
dancing around that for a long time without realizing that
the holy grail of consistent indentation is to make
that step easy. Currently, if the code I'm extracting
is someone else's, my first step is to change the
name of some of the variables so that I get compiler
errors on any line that I haven't inspected and modified.
It's a bit of a pain, but I really don't trust the copy/paste
mode of working, as way too many errors get introduced
by missing little details. If it's my own code and I know
it well enough to trust that I don't need to inspect each line,
(which is probably a bad idea regardless), I re-indent
by hand so that I get at least a cursory look at each
line to make sure I haven't done something stupid.
Usually, the mistake is that I've pushed a structure
into a function and need to replace "." with "->", which
leads to yet another syle question: I almost never
use variables that are structures. Instead, I'll use
an array of length 1 so that I never use the "." dereference,
and instead always use the arrow operator. This makes
it easier to push code into a function and somewhat
cleans up function calls, as "foo(a)" looks better
than "foo(&a)".
 
H

Herbert Rosenau

<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.
Impossible mission. But I do this instead:

if (this_is_the_first_line == 5
&& this_is_the_continuation == 4
|| (another_line != last_line
&& this == that)
|| !that) {

Double indention and logical operator in front of new line when the
space of a single line is not enough to fit the complete condition.


--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
I

Ian Collins

Herbert said:
Impossible mission. But I do this instead:

if (this_is_the_first_line == 5
&& this_is_the_continuation == 4
|| (another_line != last_line
&& this == that)
|| !that) {

Double indention and logical operator in front of new line when the
space of a single line is not enough to fit the complete condition.
Same question I asked before, can this style be automated? It looks to
me like quite a lot of the ideas presented in this thread are write once
solutions.
 
J

James Dow Allen

One thing that should be noted in this thread is that different
people will have different priorities. For example, some solutions
work better with small fonts, but I can't use small fonts. (Among other
vision problems I have monocular diplopia, believe it or not.)
This is one reason I prefer True Style, which conserves vertical space.

Different style decisions interact. I tend to use ridiculously short
variable names. If I used ridiculously long variable names, I'd surely
end up preferring shorter indentation than I use now.

(Also, since I became an algorithm designer, rather than software
provider,
*my* code isn't usually a deliverable, except in finished form.
Hence catering to external style requirements is no longer a
requirement
for me.)

Richard said:
James Dow Allen said:


... Tabs being frowned
upon, I got into the 2-space indent habit for Usenet posts

I post code too, sometimes, but if more than a tiny fragment it's
usually from real code. I replace the tabs, easily, at the same time
I add the control-M's.
I have no problem matching braces (because I lay them out Allman-style, so
it's very obvious) - and anyway, vim can jump between { and } with a single
keystroke, so even if it weren't obvious it wouldn't matter that much.

Even old-fashioned vi does that, but I only do when the matching brace
is off-screen or I'm troubleshooting a missing-brace error. I like to
just
stare at code and quickly grasp it.

Andrew said:
Am I the only one who ever nests blocks more than two levels deep?
...
Running anything inside of the third loop would take 8 spaces with
2-space indentation, while it would take 32 spaces with your tabbing

You haven't looked at my code samples if you think I don't nest deeply.
:)
I have various workarounds. As one example consider the idiom
for (Foo1; Foo2; Foo2)
if (Foo3)
enchant();
which seems to come up a lot, with *nothing* done in the loop unless
Foo3.
I often omit the indentation in this case, just as in the 2-D for shown
earlier.

I also often break up complex expressions into multiple lines, which
aids
readability even when the line wouldn't have become over-long.
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).

GUI's?? Naaah.

James Dow Allen
 
R

Robert Latest

On Fri, 19 May 2006 11:43:09 GMT,
in Msg. said:
I prefer to start the broken lines with a binary operator,
if possible,

Oh yes. Absolutely. I didn't check that with the re-posted code snippet.

robert
 
R

Robert Latest

On Sat, 20 May 2006 19:00:31 +0100,
Chris Hills said:
You will.

Why not set the editor to replace tabs with spaces?

I did that for a while but didn't like haveing to step the cursor
through the individual spaces when navigating the code with arrow keys.
Of course this is an editor issue.

robert
 
H

Herbert Rosenau

Same question I asked before, can this style be automated? It looks to
me like quite a lot of the ideas presented in this thread are write once
solutions.
Currently not - but it would possible to extend the editor to get it.
On other hand such complex if's are rare in practice.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
E

ena8t8si

Richard said:
James Dow Allen said:


I use two-space indent, and I have found that it works very well. History: I
used to use tabs (with 8-stops), but that got silly fast, and I converted
to 4-stops (but still tabs). But then I got into Usenet. Tabs being frowned
upon, I got into the 2-space indent habit for Usenet posts (because it was
so much quicker!), and found that I liked it so much I adopted it for
non-Usenet code too.

I have no problem matching braces (because I lay them out Allman-style, so
it's very obvious) - and anyway, vim can jump between { and } with a single
keystroke, so even if it weren't obvious it wouldn't matter that much.

And that explains so much....
 
R

Rod Pemberton

Richard Heathfield said:
(e-mail address removed) said:


Would you be so kind as to explain what you think it explains?

Okay, now you snipped almost all the relevant context... Unbelievable!
I'm not even going to respond to your question...


Rod Pemberton
 
R

Richard Heathfield

Rod Pemberton said:
Okay, now you snipped almost all the relevant context... Unbelievable!
I'm not even going to respond to your question...

Then why reply?
 
E

ena8t8si

Richard said:
(e-mail address removed) said:


Would you be so kind as to explain what you think it explains?

It (including the context you snipped) explains that you missed
the point in reading the earlier posting.
 
R

Richard Heathfield

(e-mail address removed) said:
It (including the context you snipped) explains that you missed
the point in reading the earlier posting.

It does? Well, if you say so...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top