Re: reformat to tool/editor-compliant C style?



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

.



Relevant Pages

  • Re: AfxGetApp() returns NULL
    ... VS to edit my code, it gets the identation right, following my indentation ... OPTION of whether to use spaces or tabs. ... me, and written using my editor, and given away free to others as a courtesy, I see no ... of my automation; worse still, the creators of VS think that there is no ...
    (microsoft.public.vc.mfc)
  • Re: Coding Style: indenting with tabs vs. spaces
    ... While I respect you opinion about tabs, I find tab indentation the most ... Tabs become "logical indentation". ... isn't forced on anotherone's editor. ... any patches to the Linux kernel will have tabs used correctly. ...
    (Linux-Kernel)
  • Re: Using TABs vs. spaces II. (the Philosophy flamewar reloaded ;-))
    ... I read somewhere that good-style Ruby code is indented by 2 spaces. ... code if the indentation is only at 2 spaces. ... spaces or just tabs rather than switching between the two. ... You can alter tab length in your editor (for at least most editors, ...
    (comp.lang.ruby)
  • Re: A stylistic question.
    ... spaces of indentation is almost too little for my taste. ... something other than 8 means that anything containing tabs will look ... My preferred text editor, vi, has ... I don't "mess around with spaces"; ...
    (comp.lang.c)
  • Re: Request for comment on my tiny learning project: dfighterdb (mytree)
    ... -In most of your code I looked at, your closing braces line up with ... -Your code uses tabs for indentation. ... The cast is unnecessary. ... I don't do the indentation myself. ...
    (comp.lang.c)