代码缩进时 程序员更喜欢空格键还是Tab键?我是空格党.... 你呢??

功夫熊猫  •   •  45455 次浏览

缩进时使用空格键还是Tab键,这不是一个小问题。在HBO的喜剧片《硅谷》第三季中,不同的缩进风格导致了两位程序员分手(如上,或 YouTube)。在现实编程中,程序员究竟是爱用空格键还是Tab键?Google 程序员 Felipe Hoffa 分析了GitHub上的40万个代码库,10亿个文件,总共14TB数据,这些文件不包含重复的文件和代码行数低于10行的文件,分析后发现空格键远比Tab键流行。    

http://goo.gl/MYdd


16 条回复
  • 羊驼君
    #1

    空格党+1小麋鹿自己~小麋鹿自己~

  • rabbitwf
    #2

    tab设置为4个空格xmlzjxmlzj

  • 功夫熊猫 楼主
    #3

    还是插件 Tab 替换成 Space 好...

  • On
    #4

    我是用tab的跟影片里的男主角一样
    位置很重要,跟影片里的男主角一样
    位置很重要,

  • Delacroix
    #5

    缩进 indentation 跟对齐 alignment 不是一回事~理解它们的区别为本,缩进在保持一致性的情况下用 tab 或者空格都没有问题,对齐使用 tab 则可能会因为编辑器设置的不同影响代码文本的显示。在此基础之上,遵循或者制定项目代码规范。理解它们的区别为本,缩进在保持一致性的情况下用 tab 或者空格都没有问题,对齐使用 tab 则可能会因为编辑器设置的不同影响代码文本的显示。在此基础之上,遵循或者制定项目代码规范。

  • togaf8
    #6

    tabover spaceover space

  • Spring
    #7

    CodingStyleTabs are 8 characters, and thus indentations are also 8 characters.
    There are heretic movements that try to make indentations 4 (or even 2!)
    characters deep, and that is akin to trying to define the value of PI to
    be 3.

    Rationale: The whole idea behind indentation is to clearly define where
    a block of control starts and ends. Especially when you've been looking
    at your screen for 20 straight hours, you'll find it a lot easier to see
    how the indentation works if you have large indentations.

    Now, some people will claim that having 8-character indentations makes
    the code move too far to the right, and makes it hard to read on a
    80-character terminal screen. The answer to that is that if you need
    more than 3 levels of indentation, you're screwed anyway, and should fix
    your program.

    In short, 8-char indents make things easier to read, and have the added
    benefit of warning you when you're nesting your functions too deep.
    Heed that warning.

    Tabs are 8 characters, and thus indentations are also 8 characters.
    There are heretic movements that try to make indentations 4 (or even 2!)
    characters deep, and that is akin to trying to define the value of PI to
    be 3.

    Rationale: The whole idea behind indentation is to clearly define where
    a block of control starts and ends. Especially when you've been looking
    at your screen for 20 straight hours, you'll find it a lot easier to see
    how the indentation works if you have large indentations.

    Now, some people will claim that having 8-character indentations makes
    the code move too far to the right, and makes it hard to read on a
    80-character terminal screen. The answer to that is that if you need
    more than 3 levels of indentation, you're screwed anyway, and should fix
    your program.

    In short, 8-char indents make things easier to read, and have the added
    benefit of warning you when you're nesting your functions too deep.
    Heed that warning.

  • 功夫熊猫 楼主
    #8

    缩进是为了对齐~

  • github
    #9

    我觉得没有关系呀关键是代码质量,好不好维护。最好不要在这样的问题上浪费时间呢。关键是代码质量,好不好维护。最好不要在这样的问题上浪费时间呢。

  • sonatam
    #10

    用vs2015的路过,表示大部分大码程序都会自己对齐啦dittoditto

  • 羊驼君
    #11

    再加一个问题~熊猫大括号换行吗?熊猫大括号换行吗?

  • 功夫熊猫 楼主
    #12

    huan bu huan bu neng ren

  • typhoonzj
    #13

    tab设为4个空格+1,强制要求的因为不是所有的编译器支持tab,有些格式会乱因为不是所有的编译器支持tab,有些格式会乱

  • saltwater
    #14

    tab档最喜欢简洁又整齐的code,alignment真的很重要,否则会影响到心情最喜欢简洁又整齐的code,alignment真的很重要,否则会影响到心情

  • _如花_
    #15

    到minification都浮云鸟

  • Sam_Fisher
    #16

    Linus Torvalds 的Kernal Coding Style

狮城帮

狮城帮是关于分享和探索新加坡的地方

马上注册

已注册用户请 登录