代码 line width 用 80 还是 120?

2016-03-23 21:22:59 +08:00
 029xue
有点纠结。

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

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

现在是不是有趋势用 120 宽了?
3649 次点击
所在节点    Python
15 条回复
yougg
2016-03-23 21:40:41 +08:00
已经多年不用 80 了, 宽屏显示器都能正常看 120 的.
除非你还拿代码行数卖钱...
ffffwh
2016-03-23 21:43:26 +08:00
凑个整数, 128
cxbig
2016-03-23 21:44:20 +08:00
从不限制行宽,至于代码 reformat ,公司有统一的标准, IDE 里跑一下就行了。
029xue
2016-03-23 21:49:39 +08:00
要么 100 ,要么 120 , 128 太搞了。。。
loveuqian
2016-03-23 21:54:06 +08:00
120 舒服
OC 又臭又长
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
2016-03-23 22:32:05 +08:00
python 坚持 80
Java 扩大到 120
bp0
2016-03-23 22:40:08 +08:00
@029xue 128 是“整数”,你到底是不是程序员(手动偷笑)。

现在倾向于使用一行 120 个字符。有一些人写一行代码 200 多字符,实在是受不了。
zhangchioulin
2016-03-23 22:51:01 +08:00
@loveuqian 哈哈哈哈我的 oc 现在是 80,我以前是看 Google 对 oc 的开发规范改的,现在也觉得心累方法这么长...你这么说的话,我也改成 120 的
zhangchioulin
2016-03-23 22:52:01 +08:00
@bp0 链式编程哈哈哈哈哈哈,有时候图省事我也会把 4 行代码压缩成 1 行...不过是少数时候
bp0
2016-03-23 23:30:54 +08:00
@zhangchioulin 以前链多的太多超过屏幕了,然后出个 bug 查了 3 天,最后发现是链多了。然后就再也不链了。
wsb200514
2016-03-23 23:36:09 +08:00
@yougg 哈哈,说的是。
029xue
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
2016-03-24 11:24:04 +08:00
120 自动这换行, 现在这么大的显示器你用 80 多难受的。。。
billgreen1
2016-03-25 21:30:48 +08:00
我一开始用的是 120 ,后来还是改成 80 了。

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

2.很多 github 的开源项目用的也是 80 ,有些代码你可能想贡献到 github 开源项目,默认用 80 不会出问题。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/265872

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX