Re: reformat to tool/editor-compliant C style?
- From: Nick Keighley <nick_keighley_nospam@xxxxxxxxxxx>
- Date: Mon, 7 Jul 2008 00:55:29 -0700 (PDT)
On 6 Jul, 17:52, Hallvard B Furuseth <h.b.furus...@xxxxxxxxxxx> wrote:
Mark McIntyre writes:
I should have clarified: The code was _originally_ written with tab
width 4. But by now it's sprinkled with quite a bit written with tab
widht 8. Open-source project, several authors... So it gets wrong
either way.
That doesn't make sense to me. A Tab is a tab - your editor should
convert 0x09 into whatever tabspace you've defined in your editor.
Yes, and either way existing code gets displayed misaligned.
Presumably you mean that some moron has tab-to-spaced your code twice,
once at 4s/t and once at 8s/t.
Maybe some places, but mostly "some moron" has written code which looks
fine with tab-width 8 but not 4. Maybe because it wasn't documented
anywhere that the code was written with tab-width 4.
If someone writes this with tab-width = indentation = 4, it gets aligned
fine:
int foo; /* ... */
struct Bar bar[256]; /* ... */
And if someone else writes this with tab-width = indentation = 8, it
gets aligned fine:
int baz; /* ... */
struct Bar quux[256]; /* ... */
but when you have both variants mixed up in the code base, there is no
tab-width which will align all of the code fine. With tab-width 8, the
first example looks like
int foo; /* ... */
struct Bar bar[256]; /* ... */
I think I could live with that...
With tab-width 4, the 2nd example looks like
int baz; /* ... */
struct Bar quux[256]; /* ... */
Also, of course, occasional lines are indented with tabs+spaces
(tab-width 8, indentation 4).
In which case why not just run it through indent, setting appropriate
tabs (not spaces)?
no. *remove* all the tabs. Its the tabs that cause the problem.
First, I don't know how other people _write_ code, in particular with
non-Emacs. Thus the question of what kind of style is easy to produce
with other editors.
Does emacs format your code that much? The editor I use fiddles
with the indentation a bit but otherwise leaves things alone
(if it tried to do anything else the feature would be rapidly
disabled- or the editoe dumped).
Second, because indent isn't smart enough. With macro magic, multiline
macros, too creative formatting and macros etc. So I'll have to walk
through the result and clean up.
I havn't used indent for a while but generally I thought it was pretty
good.
It tended to messs up some of my comment blocks.
Like this piece of formatting which
is just semantically wrong:
*semantically* wrong? Why? I hate K&R style { on the same
line as the code and comments outside the block. But the semantics
seem
plain enough.
/* try foo */
if (foo) {
handle foo;
/* otherwise try bar */
} else if (bar) {
handle bar;
/* oh dear */
} else {
error();
}
with my layout this would look like this.
if (foo)
{
handle foo;
}
else if (bar)
{
handle bar;
}
else
{
error();
}
or even
if (foo)
handle foo;
else if (bar)
handle bar;
else
error();
is *that* "semantically* wrong? I'm beginning to wonder
if one of us has a non-standard meaning for "semantic"...
Also indent doesn't really understand C,
ok...
so I suppose it could make
semantic changes.
not by *my* definition of "semantic". I've never seen
indent screw up a correct peoce of code. The layout may
be strange but in my experience the code did the same thing
before and after.
Not sure that's worth worrying about though.
it would sure worry me if it was happening!
Probably more likely that I'd make a typo when cleaning up.
yes
--
Nick Keighley
"To every complex problem there is a simple solution... and it is
wrong."
-- Turski
.
- Follow-Ups:
- Re: reformat to tool/editor-compliant C style?
- From: Hallvard B Furuseth
- Re: reformat to tool/editor-compliant C style?
- References:
- reformat to tool/editor-compliant C style?
- From: Hallvard B Furuseth
- Re: reformat to tool/editor-compliant C style?
- From: Nick Keighley
- Re: reformat to tool/editor-compliant C style?
- From: Hallvard B Furuseth
- Re: reformat to tool/editor-compliant C style?
- From: Mark McIntyre
- Re: reformat to tool/editor-compliant C style?
- From: Hallvard B Furuseth
- Re: reformat to tool/editor-compliant C style?
- From: Mark McIntyre
- reformat to tool/editor-compliant C style?
- Prev by Date: Re: a[i] = a[j]... Dangerous?
- Next by Date: Re: reformat to tool/editor-compliant C style?
- Previous by thread: Re: reformat to tool/editor-compliant C style?
- Next by thread: Re: reformat to tool/editor-compliant C style?
- Index(es):
Relevant Pages
|