views:

58

answers:

1

This question is similar in spirit to :

http://stackoverflow.com/questions/492178/links-between-personality-types-and-language-technology-preferences

But it is based specifically on indentation (spaces vs tabs and the number of spaces).

The reason I am asking here instead of searching is because I remember seeing a specific document writing about this. If I remember correctly, it also talked about why Linus prefers eight spaces.

+1  A: 

The document you are referring to is, I believe, the Linux Kernel Coding Standard: https://computing.llnl.gov/linux/slurm/coding_style.pdf

Personally, I prefer four spaces, straight up. I try to keep it to 79 characters per line, unless I don't feel like it or there's a long string. When parenthetical statements or comments spill, I align the beginning to the next tab stop on the first line (or one past the next indentation level if I have to,) then align thereafter. Here is a sample of some of my code (taken from some random codebase I'm working on.) Notice what I do with that multi-line conditional.

void R_RecursiveWorldNode (mnode_t *node, int clipflags){
    msurface_t      *surf;
    static vec3_t   oldviewangle,       oldorigin;
    vec3_t          deltaorigin,        net_movement_angle;
    float           len_deltaorigin;
    float           movement_view_diff; //difference between the net movement
                                        //angle and the view angle (0 when
                                        //movement during frame was straight
                                        //ahead.)

    VectorSubtract (r_origin, oldorigin, deltaorigin);
    len_deltaorigin = abs(len_deltaorigin);

    VectorCopy (deltaorigin, net_movement_angle);
    VectorNormalize(net_movement_angle);

    VectorSubtract (net_movement_angle, vpn, net_movement_angle);
    movement_view_diff = abs (movement_view_diff);


    // if we have either a new PVS or a significant amount of 
    // movement/rotation, we should actually recurse the BSP again.
    if (        (r_oldviewcluster != r_viewcluster && r_viewcluster != -1)  ||
                len_deltaorigin > 12.0 || vpn[YAW] != oldviewangle[YAW]     ||
                movement_view_diff > 1.0    ) {
        VectorCopy (vpn, oldviewangle);
        VectorCopy (r_origin, oldorigin);
        r_ordinary_surfaces = NULL;
        r_alpha_surfaces = NULL;
        r_special_surfaces = NULL;
        __R_RecursiveWorldNode (node, clipflags);
    } 

    surf = r_ordinary_surfaces;
    while (surf){
        GL_RenderLightmappedPoly( surf );
        surf = surf->ordinarychain;
    }
}

This comes, I think, from being a Python programmer. It's C equivalent of the default indentation scheme in the IDLE editor which I used to use a lot.

Max E.