缩进偏好和个性

发布于 2024-08-24 23:29:17 字数 383 浏览 7 评论 0原文

这个问题在精神上类似于:

https://stackoverflow.com/ questions/492178/links- Between-personality-types-and-language-technology-preferences

但它专门基于缩进(空格与制表符以及空格数量)。

我在这里询问而不是搜索的原因是因为我记得看到一个特定文档写了这件事。如果我没记错的话,它还谈到了为什么 Linus 更喜欢八个空格。

This question is similar in spirit to :

https://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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱纠缠 2024-08-31 23:29:17

我相信您所指的文档是 Linux 内核编码标准:
https://computing.llnl.gov/linux/slurm/coding_style.pdf

就我个人而言,我更喜欢四个空格。我尝试将其保持在每行 79 个字符,除非我不喜欢它或者字符串很长。当括号内的语句或注释溢出时,我会将开头对齐到第一行的下一个制表位(或者如果需要,则将其对齐到下一个缩进级别),然后再对齐。这是我的一些代码的示例(取自我正在处理的一些随机代码库。)请注意我对多行条件的处理。

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;
    }
}

我认为这来自于作为一名 Python 程序员。它相当于我经常使用的 IDLE 编辑器中默认缩进方案的 C 语言。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文