My whitespace style

Giorgos Keramidas keramida at ceid.upatras.gr
Wed Apr 15 00:40:20 PDT 2009


On Wed, 15 Apr 2009 06:48:12 +0200, deeptech71 at gmail.com wrote:
> Could you please give me a (preferrably widely used) example of
> columnizing calls which cross different levels of indentation?

It's not so uncommon as it may initially seem...

I've seen switch() cases in several programs indented like this:

        switch (value) {
        case SOME_CONSTANT_NAME:            do_stuff_here();        break;
        case ANOTHER_CONSTANT_NAME:         do_some_other_stuff();  break;
        default:                            default_stuff();        break;
        }

I find this style horrible to read, but it does come with its own
variation of TAB- and space-related issues and it is apparently
attractive to a lot of people.

Composite structure initializations also use a style similar to this,
and will almost invariably end up looking horrendously misformatted when
TAB sizes are 'elastic', i.e.:

    struct foo {
        long magic;
        const char *name;
        struct {
            int curr;
            int next;
        } nested;
    };

    const struct foo statetab[] = {
        { 1,     "one",     {    1,     2}, },
        { 1,     "one",     {    2,     2}, },
        { 1,     "one",     {    3,     1}, },
        { 1,     "one",     {65535,     1}, },

        { 2,     "two",     {    1,     1}, },
        { 2,     "two",     {    2,     2}, },
        { 2,     "two",     {    3, 65535}, },
        { 2,     "two",     {65535,     1}, },

        ...

        { 65535, "invalid", {    1,     1}, },
        { 65535, "invalid", {    2,     1}, },
        { 65535, "invalid", {    3,     1}, },
        { 65535, "invalid", {65535,     1}, },
    };

This sort of alignment tends to generate *lots* of diff output when the
alignment of a column changes, but it is often used for state transition
tables of automata, and similar constructs.



More information about the freebsd-chat mailing list