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 19:50

indent -linux *.c
/thread

Name: Anonymous 2010-04-24 20:15

>>41
I think indent has been abandoned and is not very useful nowadays. It performs rather miserably with C99 syntax, and I have even seen it crash when faced with certain C++ constructs.

That and it has way too many options, with highly clunky syntax. I occasionally fantasize of having an indenter that defined its rules based on contextual analysis of code snippets -- so the config file would essentially be a short C program on which to base the reindentation of its input files.

Name: Anonymous 2010-04-24 20:17

I prefer astyle.

Name: Anonymous 2010-04-24 20:26

M-x mark-whole-buffer then M-x indent-region or [m]C-SPC M-> C-M-[m]

Name: Anonymous 2010-04-24 21:13

>>42
indent is meant for C, why would you expect it to work with a different language?
Though obviously it doesn't crash even on Sepples code, and it doesn't have any difficulty with C99.

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.

Name: Anonymous 2010-04-25 11:12

>>46
PERFECTLY VALID MY ANUS

Name: Anonymous 2010-04-26 9:04

>>47
*parses dick*

Name: Anonymous 2010-12-25 10:08

Name: Anonymous 2011-02-04 14:09

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