TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Linux kernel coding style

82 点作者 e19293001大约 8 年前

14 条评论

nolemurs大约 8 年前
Other people are complaining about the 80 character line limit, but personally, I&#x27;m shocked and dismayed by the preference for no braces on `if` statements with single line blocks. It is <i>so</i> easy to accidentally add a line to what looks like an `if` block (but isn&#x27;t since there are no braces), and then you have a bug that is visually very difficult to spot. I&#x27;m pretty strongly against this rule!
评论 #13974587 未加载
评论 #13973634 未加载
评论 #13973715 未加载
评论 #13974338 未加载
评论 #13973466 未加载
评论 #13974110 未加载
danilocesar大约 8 年前
2017 and contributors still need to discuss about coding style =&#x2F;<p>If you want to enforce codding style (which is OK) you need to provide developers the tools to ease that process.<p>Contributing with patches to 15 different projects, using 15 different rules for styling makes it impossible to keep up.<p>FOSS projects should start using tools like clang-format so developers don&#x27;t need care if a project use 2&#x2F;4&#x2F;6&#x2F;8 spaces instead of tab. The tool should be able to automatically format the code before committing.<p>Some projects even use git hooks to compare the commit with auto-generated styling tools to check if it follows the rules.
评论 #13973713 未加载
评论 #13976445 未加载
nunofgs大约 8 年前
Only thing I really don&#x27;t agree with is the 80 char max.<p>I&#x27;m not suggesting unlimited but isn&#x27;t it time we revisit this?<p>It really feels like one of those &quot;we&#x27;ve always done it this way so just leave it&quot;
评论 #13973419 未加载
评论 #13973492 未加载
评论 #13973365 未加载
评论 #13973362 未加载
评论 #13973632 未加载
评论 #13973496 未加载
terrywang大约 8 年前
Indentation war is ON again ;-)<p>TL;DR - Linux kernel source code use TABs (8 characters) instead of spaces. The rationale behind is that the maintainers believe that large indentation makes code easier to read on screen (especially for long hours), makes sense.<p>Personally I (not a programmer but Linux SysAdmin&#x2F;Ops&#x2F;Infra Architect background) tend to use 4 spaces everywhere else (e.g. Shell, Ruby, Java and all sorts of configuration files). Not to pick a fight (sounds familiar? ;-) but 2 spaces in general make readability worse.<p>Anyway, the most important point is to honour what is already established&#x2F;in place and stick to it, whatever you work on.
评论 #13973119 未加载
评论 #13973171 未加载
评论 #13973120 未加载
corndoge大约 8 年前
Have to agree with the comment on GNU coding style, I work on a project that uses it and it really sucks. Braces on a newline and indented two spaces...
Trufa大约 8 年前
Offtopic question, what documentation tool is used for this? I&#x27;ve seen it a lot of times but I&#x27;m not sure how to search for it. Thanks!
评论 #13973087 未加载
评论 #13973074 未加载
评论 #13973108 未加载
评论 #13973073 未加载
评论 #13973071 未加载
skybrian大约 8 年前
It seems like sensible advice but with gratuitous insults interspersed, just to make sure you&#x27;re really clear that the natives are not friendly.
评论 #13973475 未加载
sverige大约 8 年前
The writing style of this document seems somewhat casual (&quot;Please at least consider the points made here.&quot;) and a little confusing compared to OpenBSD&#x27;s style guide. [1]<p>The LibreSSL team spent months putting the OpenSSL code into KNF. It makes a big difference, even though it may seem trivial.<p>[1] <a href="http:&#x2F;&#x2F;man.openbsd.org&#x2F;style" rel="nofollow">http:&#x2F;&#x2F;man.openbsd.org&#x2F;style</a>
geofft大约 8 年前
This is from Documentation&#x2F;process&#x2F;coding-style.rst (formerly Documentation&#x2F;CodingStyle) in the kernel source tree; an unrendered version is canonically at <a href="https:&#x2F;&#x2F;www.kernel.org&#x2F;doc&#x2F;Documentation&#x2F;process&#x2F;coding-style.rst" rel="nofollow">https:&#x2F;&#x2F;www.kernel.org&#x2F;doc&#x2F;Documentation&#x2F;process&#x2F;coding-styl...</a>
评论 #13974893 未加载
hughes大约 8 年前
What is K&amp;R? It&#x27;s referenced several times but not defined.
评论 #13973059 未加载
评论 #13973067 未加载
s3arch大约 8 年前
&gt;First off, I’d suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it’s a great symbolic gesture.<p>Should I be aware of something from GNU coding standards?
评论 #13980888 未加载
reynoldsbd大约 8 年前
&gt; Tabs are 8 characters...<p>The madman!<p>&#x2F;s<p>Actually, now that I think about it, he has a point. Having a little more horizontal space seems like it would be easier on the eyes.
评论 #13973208 未加载
azaras大约 8 年前
I like gofmt which avoids this problem in golang.
pyed大约 8 年前
Coding style wars will die with the rise of *fmt.
评论 #13973788 未加载