V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
029xue
V2EX  ›  Python

代码 line width 用 80 还是 120?

  •  
  •   029xue · 2016-03-23 21:22:59 +08:00 · 3599 次点击
    这是一个创建于 2953 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有点纠结。

    用 80 有 800 个理由,不多列了。

    现在情况是 inline 调用比较多,有的光函数名就 10+, 80 实在捉襟见肘,总是换行也不好看。

    现在是不是有趋势用 120 宽了?
    15 条回复    2016-03-25 21:30:48 +08:00
    yougg
        1
    yougg  
       2016-03-23 21:40:41 +08:00
    已经多年不用 80 了, 宽屏显示器都能正常看 120 的.
    除非你还拿代码行数卖钱...
    ffffwh
        2
    ffffwh  
       2016-03-23 21:43:26 +08:00 via iPad
    凑个整数, 128
    cxbig
        3
    cxbig  
       2016-03-23 21:44:20 +08:00
    从不限制行宽,至于代码 reformat ,公司有统一的标准, IDE 里跑一下就行了。
    029xue
        4
    029xue  
    OP
       2016-03-23 21:49:39 +08:00
    要么 100 ,要么 120 , 128 太搞了。。。
    loveuqian
        5
    loveuqian  
       2016-03-23 21:54:06 +08:00
    120 舒服
    OC 又臭又长
    xuboying
        6
    xuboying  
       2016-03-23 22:30:09 +08:00
    有没有不换行的
    cat .clang-format
    BasedOnStyle: LLVM
    IndentWidth: 4
    ColumnLimit: 999
    Standard: Cpp11
    TabWidth: 4
    UseTab: Never
    BreakBeforeBraces: Attach
    AllowShortFunctionsOnASingleLine: false
    PointerAlignment: Middle
    #AlignConsecutiveAssignments: true
    #AlignConsecutiveDeclarations: true
    sudoz
        7
    sudoz  
       2016-03-23 22:32:05 +08:00
    python 坚持 80
    Java 扩大到 120
    bp0
        8
    bp0  
       2016-03-23 22:40:08 +08:00
    @029xue 128 是“整数”,你到底是不是程序员(手动偷笑)。

    现在倾向于使用一行 120 个字符。有一些人写一行代码 200 多字符,实在是受不了。
    zhangchioulin
        9
    zhangchioulin  
       2016-03-23 22:51:01 +08:00
    @loveuqian 哈哈哈哈我的 oc 现在是 80,我以前是看 Google 对 oc 的开发规范改的,现在也觉得心累方法这么长...你这么说的话,我也改成 120 的
    zhangchioulin
        10
    zhangchioulin  
       2016-03-23 22:52:01 +08:00
    @bp0 链式编程哈哈哈哈哈哈,有时候图省事我也会把 4 行代码压缩成 1 行...不过是少数时候
    bp0
        11
    bp0  
       2016-03-23 23:30:54 +08:00
    @zhangchioulin 以前链多的太多超过屏幕了,然后出个 bug 查了 3 天,最后发现是链多了。然后就再也不链了。
    wsb200514
        12
    wsb200514  
       2016-03-23 23:36:09 +08:00
    @yougg 哈哈,说的是。
    029xue
        13
    029xue  
    OP
       2016-03-24 11:13:49 +08:00
    (R) On open source projects, there should be a hard 79-character limit. Our experience has shown that contributors or visitors to these projects will grumble about line length issues.
    (R) On private projects, we relax the limit to 99 characters, taking full advantage of modern mon- itors.

    Fitting the code in 79 columns is never a good reason to pick worse names for variables, functions, and classes. It ’ s much more impor- tant to have readable variable names than to t in an arbitrary limit of hardware from three decades ago.”

    感觉这说的有道理,准备用 100 。
    ThomasZ
        14
    ThomasZ  
       2016-03-24 11:24:04 +08:00
    120 自动这换行, 现在这么大的显示器你用 80 多难受的。。。
    billgreen1
        15
    billgreen1  
       2016-03-25 21:30:48 +08:00
    我一开始用的是 120 ,后来还是改成 80 了。

    1.很多编辑器的默认就是 80 ,组里其他人都没改成 120 ,结果大家都喜欢 reformat ,这样用 git 就不方便了,我总不能强行让其他人修改。

    2.很多 github 的开源项目用的也是 80 ,有些代码你可能想贡献到 github 开源项目,默认用 80 不会出问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1235 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 23:21 · PVG 07:21 · LAX 16:21 · JFK 19:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.