Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Forcing yourself to indent code?

Name: Anonymous 2010-04-22 15:00

How do you do it, guys?
I seem to only really indent my code when I use python.

tl;dr how can I improve my coding style?

Name: Anonymous 2010-04-24 23:57

>>45
indent is an old and unmaintained codebase that is most definitely showing its age, and I'm not sure why you would even feel the inclination to argue otherwise, except maybe IHBT, but here's some perfectly valid C99 code that it completely fucks up:


#include <stdio.h>
struct label {
    int x, y;
    const char *s;
};
struct label labels[] = { {
    .x = 1,
    .y = 2,
    .s = "Abort",
}, {
    .x = 3,
    .y = 4,
    .s = "Retry",
}, {
    .x = 5,
    .y = 6,
    .s = "Ignore",
}, {
    .x = 7,
    .y = 8,
    .s = "Why does indent break this so badly?",
} }, another_label = {
    .x = 9,
    .y = 10,
    .s = "and it gives up entirely here",
};
void dumplabels(int n, struct label *args) {
    for (int a = 0; a < n; a++)
        printf("%d, %d: %s\n", args[a].x, args[a].y, args[a].s);
}
// slightly contrived, but really NOT much of a stretch from useful code.
int main(int argc, char **argv) {
    for (int a = 10, b = 0; b < 10; b++, a--)
        // indent crams this all together... more like obfuscate
        dumplabels(3, ((struct label[]) {
            {
                .x = a,
                .y = b,
                .s = "a and b",
            }, {
                .s = "no x/y given",
            }, {
                .y = a,
                .s = "y is a",
            },
        }));
    return 0;
}


astyle is marginally better here, but some of its styles botch the indentation fairly completely as well.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List