Boost logo

Boost :

From: David B. Held (dheld_at_[hidden])
Date: 2002-09-09 23:11:57

"Eric Woodruff" <Eric.Woodruff_at_[hidden]> wrote in message
> Yes, I know people do crazy things with their alignment and they think
> it provides significant value. In reality, you should never have deeply
> nested blocks, and blocks should be at THE MOST 20 lines, all of this
> alignment is moot when most methods are at the 10-15 line level.

I almost never align inside function bodies. However, I do often write
nested classes, and sometimes these are a few classes deep. I find
that aligning class definitions makes it very easy to locate items of
interest, since this is the part of code that I refer to most often.

> [...]
> Your desired spacing method is hideous.

Beauty is in the eye of the beholder. Frankly, I find it more difficult to
locate important identifiers in an unaligned class header than in an
aligned one. But that's probably because I'm not such an advanced
programmer as yourself, and such trivial things are not obvious to me.

> Note: A good editor would force the indentation automatically in a
> block, and never let it be violated.

There are an awful lot of unquestioned absolutes in your world. Must
be nice.

> The purpose of the tabbed indentation is to show the scope,
> especially since it matters so much in C++.

I agree. And for me, the purpose of alignment is to help locate the
important parts of class declarations. Here is an example:

class foo
    really_long_return_type const& bar(int);
    void baz(long, return_type const&, char const*);

It's a little contrived, but if I happened to know that I was looking for a
function taking a long and some other parameters, it's more work to
parse the class definition and locate the function of interest compared
to this layout:

class foo
    really_long_return_type const&
    void baz(long, return_type const&, char const*);

The alignment of function names makes it easy to scan the list
quickly (which is something I do quite often, when referring to my
own interfaces). I don't suggest that everyone should code this way,
but I think it's quite fascist to insist that this is a morally
way to do things.

And for the record, while the identifiers in the example are contrived,
the overall situation is not. I commonly have radically differing return
type identifier lengths which would result in rather zig-zag code were
I not to align the names. Another example is inline function definitions.
While some people would say these are altogether evil, I think it a bit
fascist to insist that simple accessor functions not be declared inline,
a la:

class foo
    int bar() const { return bar_; }
    char baz() const { return baz_; }
    int bar_;
    char baz_;

I find that unaligned inlined functions are harder to read (though that
is strictly a matter of personal preference).


Boost list run by bdawes at, gregod at, cpdaniel at, john at