编码指南应该做什么,是否有任何良好的指导原则?

时间:2020-12-04 22:25:35

What are some good examples of coding guidelines. I'm not really looking for anything specific to a single language.

什么是编码指南的好例子。我并不是在寻找任何特定于单一语言的东西。

But what should I be doing/evaluating as I write coding guidelines? Such as how flexible should the guidelines and how much should decisions be left to the programmer or to someone else or even pre-decided by the guidelines.

但是,当我编写编码指南时,我应该做什么/评估?例如指南应该有多灵活,应该给程序员或其他人做出多少决定,甚至应该由指南预先决定。

This set of guidelines that I am working on is supposed to cover a wide range of topics: comments, database design, and even some user interface guidelines.

我正在研究的这套指南应涵盖广泛的主题:评论,数据库设计,甚至一些用户界面指南。

11 个解决方案

#1


24  

There are generally three purposes for coding standards:

编码标准通常有三个目的:

  • Reduce the likelihood of bugs
  • 减少错误的可能性

  • Reduce the time required to analyze code written by someone else
  • 减少分析其他人编写的代码所需的时间

  • Give someone a power trip
  • 给某人一个权力之旅

Obviously, the third is a waste of everyone else's time, but you do need to consider it, specifically so you don't go down that road.

显然,第三种是浪费其他人的时间,但你确实需要考虑它,特别是你不要走那条路。

Having said that, there are some definite do's and dont's that I've noticed:

话虽如此,我已经注意到了一些明确的做法和不做的事情:

  • Enforce consistent whitespace usage. Tabs, 2-spaces, 4-spaces, doesn't matter. Keep it consistent, so indent levels aren't screwed up by people using different editors. I've seen mistakes made because maintenance programmers misinterpreted the nesting level of a block of code.
  • 实施一致的空白用法。标签,2个空格,4个空格,无所谓。保持一致,因此使用不同编辑器的人不会搞砸缩进级别。我看到了错误,因为维护程序员误解了代码块的嵌套级别。

  • Enforce consistent logging methodology. It's a huge drain on support staff's time if they aren't able to skim over logs, because everyone's module logs for different reasons, and everyone has a different definition of Info vs. Warning vs. Error.
  • 实施一致的日志记录方法。如果他们无法浏览日志,那么支持人员的时间就会大量消耗,因为每个人的模块日志都有不同的原因,每个人都有不同的信息与警告与错误的定义。

  • Enforce consistent error handling. If module A throws exceptions, module B returns error codes, and module C simply logs and moves on, it'll be a pain to integrate them without letting an error slip through the cracks.
  • 实施一致的错误处理。如果模块A抛出异常,模块B返回错误代码,模块C只是记录并继续运行,将它们集成在一起并不让错误滑过裂缝将是一件痛苦的事。

  • Try to avoid petty things like placement of curly-braces. That's going to get a lot of people arguing over their pet style, and in the end, it really doesn't have a huge impact on the readability of code. On the other hand, enforcing the presence of brackets can make a difference.
  • 尽量避免像花括号那样的小事。这会让很多人争论他们的宠物风格,最后,它确实对代码的可读性没有太大的影响。另一方面,强制执行括号可能会有所不同。

  • When integrating disparate code bases, don't be tempted to change everyone's variable naming conventions to match the golden standard. You may have a standard for moving forward, but what's most important is that any localized standards that already exist are preserved consistently. If one module uses m_member, a maintenance programmer should be using m_member2 rather than applying any other standard (such as member2_ or m_lpcstrMember2 or whatever). Local consistency is king.
  • 在集成不同的代码库时,不要试图改变每个人的变量命名约定以匹配黄金标准。您可能有前进的标准,但最重要的是,已经存在的任何本地化标准都会保持一致。如果一个模块使用m_member,则维护程序员应该使用m_member2而不是应用任何其他标准(例如member2_或m_lpcstrMember2或其他)。本地一致性是王道。

  • Filesystem layout is important. Keep it consistent. Make it easy for someone to jump into a library sourcebase and instantly know where are the headers, the Makefile, the sources, etc. If you're working with Java or Python, this is a no-brainer because the package system enforces it. If you're working with C, C++, or any other myriad of scripting languages, you'll need to devise a standard layout yourself and stick with it.
  • 文件系统布局很重要。保持一致。让某人很容易跳进库源库并立即知道头文件,Makefile,源代码等等。如果你正在使用Java或Python,这是一个明智的选择因为包系统强制执行它。如果您正在使用C,C ++或任何其他无数的脚本语言,您需要自己设计标准布局并坚持使用它。

  • Don't sweat the little stuff. Variable naming conventions, spaces between parentheses or keywords or function names... most of that doesn't matter, because it doesn't reduce the likelihood of a mistake. Every rule you set should have a concrete rationale, and you shouldn't be afraid to change or remove it if you discover it's causing more grief than it's worth.
  • 不要为小东西出汗。变量命名约定,括号或关键字之间的空格或函数名称......大部分都无关紧要,因为它不会降低错误的可能性。你设定的每条规则都应该有一个具体的理由,如果你发现它引起的更多的悲伤而不是它的价值,你不应该害怕改变或删除它。

  • Don't enforce gratuitous comment blocks everywhere. They'll end up as a waste, and most comments are better off being expressed in the code itself (as variable or function names, for example).
  • 不要在任何地方强制执行无偿的评论。它们最终会成为浪费,大多数注释最好不要在代码本身中表达(例如,作为变量或函数名称)。

Finally, the most important thing is to have regular code reviews between peers. Encourage people to speak up when they see a "code smell." Also be sure people realize that constructive code criticism is not meant to be personal - the source is shared by everone on the team, it doesn't just belong to the original author. In my experience, the most heinous problems have been design problems that wouldn't have been solved by any amount of coding guidelines. Software design is still something of an art form (for better or for worse), and a pool of brains is much better than a single one.

最后,最重要的是在同行之间进行定期的代码审查。鼓励人们在看到“代码味道”时说出来。还要确保人们意识到建设性的代码批评并不是个人的 - 来源是团队中的任何人共享的,它不仅仅属于原始作者。根据我的经验,最令人发指的问题是任何编码指南都无法解决的设计问题。软件设计仍然是一种艺术形式(无论好坏),并且大脑池比单个大脑好得多。

#2


9  

if( !codingGuidelines.Followed)
{
   reason = programmer.WhyNot();
   if( reason.Acceptable)
   {
      codingGuidelines.Integrate( reason);
   }
   else
   {
      team.GiveAssKicking(programmer);
   }
}

#3


8  

It's a fairly open question, and the answer is equally as open:

这是一个相当开放的问题,答案同样公开:

Every guideline should cost less to implement than the benefit it brings.

每项指南的实施成本都应低于其带来的好处。

Be careful, because each side of the equation has some hidden parts.

要小心,因为等式的每一边都有一些隐藏的部分。

The cost of implementation can include excluding perfectly good alternatives, stifling creativty and innovation, and encouraging code reviews to degenerate into highlighting minor infractions of the style rather than addressing real issues.

实施成本可以包括排除完美的替代品,扼杀创新和创新,并鼓励代码审查堕落,突出显示风格的轻微违规,而不是解决实际问题。

The value of the benefits may be intangible (and hence frustrating) to a busy developer in a hurry, but might result in your organizations brand being stronger or bringing new staff onto the project being faster - something that might outweigh the small incremental cost of complying.

对于繁忙的开发人员来说,收益的价值可能是无形的(因而令人沮丧),但可能会导致您的组织品牌变得更强大或者让新员工更快地投入到项目中 - 这可能会超过遵守的小增量成本。

#4


4  

As a developer, I generally prefer guidelines to give basic guidance, but not be so strict that I can't code how I like... for instance, if a guideline is telling me what coding patterns must be used rather than allowing me to make my own professional judgement then it's too tight:

作为开发人员,我通常更喜欢指导方针来提供基本指导,但不要太严格以至于我无法编码我喜欢的代码...例如,如果指南告诉我必须使用哪种编码模式而不是允许我做出我自己的专业判断然后它太紧了:

For example, these are the type of things I might expect to see:

例如,这些是我可能期望看到的类型:

  • Style of variable names i.e. hungarian notation(not that I strictly use those)
  • 变量名称的样式,即匈牙利表示法(不是我严格使用那些)

  • Methods should be commented with their general purpose, including what they return (if anything)
  • 方法应该用它们的一般目的评论,包括它们返回的内容(如果有的话)

  • Classes should be defined with a specific layout: i.e. all private fields at the top, followed by events, public methods, private methods, whether they should be in alphabetical order
  • 应使用特定布局定义类:即顶部的所有私有字段,后跟事件,公共方法,私有方法,是否应按字母顺序排列

  • Naming conventions for namespaces, classes, methods, events and properties etc
  • 命名空间,类,方法,事件和属性等的命名约定

You get the picture. I shouldn't be restricted to stuff like:

你得到了照片。我不应该局限于:

  • Thou shalt use If notation instead of int a = (blah)? true : false;
  • 你应该使用If notation而不是int a =(blah)?真假;

Coding styles obviously need to be common across a team to allow developers to be able to work together effectively. You can't have one person way out there in left field using complex mathematical algorithms that nobody else on the team can understand and have another way out in right field who can barely comprehend the implementation of interfaces. So as a rule of thumb, they should be designed to help keep your team together while not dampening productivity and creativity.

编码风格显然需要在团队*同使用,以便开发人员能够有效地协同工作。你不可能使用复杂的数学算法让左边的一个人离开那里,团队中的其他任何人都无法理解,并且在正确的领域中有另一种方法,他们几乎无法理解接口的实现。因此,根据经验,它们应该旨在帮助您的团队保持在一起,同时不会降低生产力和创造力。

Get some input from your development team as a whole so that a "house" standard can incorporate everything it should and not include a bunch of stuff it shouldn't.

从整个开发团队获得一些意见,以便“房屋”标准可以包含它应该包含的所有内容,而不包括一堆不应该包含的东西。

#5


2  

Coding guidelines are there to make it easy for others to read your code. Even if you are writing code for yourself and are the only developer, it may be useful to find a set of guidelines commonly accepted in the industry and stick to them. It will make it easier for you to read other peoples code and for you to fit into a larger team at a later date.

编码指南可以让其他人轻松阅读您的代码。即使您正在为自己编写代码并且是唯一的开发人员,找到业界普遍接受的一套指南并坚持使用它们可能会很有用。它将使您更容易阅读其他人的代码,并让您在以后适应更大的团队。

If using .net, take a look at StyleCop. By default it contains standards that MS use themselves and used to design the .net framework around. You can get it from here:

如果使用.net,请查看StyleCop。默认情况下,它包含MS自己使用的标准,用于设计.net框架。你可以从这里得到它:

http://code.msdn.microsoft.com/sourceanalysis

You can disable rules you don't like and add your own. It can even be scripted to enforce the rules when code is checked in. The great thing about it is that if you're really new to this sort of stuff, it will tell you exactly what you're doing wrong. If you want to go one step further, take a look at Resharper. It's the same sort of thing, but does it in real time as you type (though by default it uses a slightly different standard.

您可以禁用不喜欢的规则并添加自己的规则。在签入代码时,它甚至可以编写脚本来强制执行规则。最重要的是,如果你真的对这类东西不熟悉,它会告诉你你究竟做错了什么。如果你想更进一步,看看Resharper。这是同样的事情,但是当你输入时会实时显示它(尽管默认情况下它使用的标准略有不同。

I'm sure there are similar utilities around other languages if c# is not your thing!

如果c#不是您的话,我相信其他语言也有类似的实用程序!

#6


2  

I want a coding standards document to resolve religious arguments for the team.

我想要一个编码标准文件来解决团队的宗教争论。

For the questions where there are multiple worthwhile answers, and people have a tendency to argue about them for a long time, we want to get consistency across the whole project and avoid spending much time discussing them.

对于有多个有价值的答案的问题,以及人们长期争论它们的倾向,我们希望在整个项目中保持一致性并避免花费太多时间讨论它们。

Good examples are "TABs vs. Spaces" and "K&R vs. ANSI brace placement". Take a poll in the team, make a decision, and write it down. Apply the decision to all your existing code at once, and check it in by itself. Never discuss it again.

很好的例子是“TABs vs. Spaces”和“K&R vs. ANSI大括号放置”。在团队中进行民意调查,做出决定并将其写下来。立即将决定应用于所有现有代码,并自行检查。永远不要再讨论了。

#7


1  

In general, I would want guidelines to answer the questions that you would normally ask but would take too long to answer, and that might be "personal preference" if you were just coding alone. Usually they specify pithy things like database naming conventions and spaces vs. tabs (and how many spaces) as well as commenting / documentation comment styles.

一般来说,我希望指南能够回答您通常会问的问题,但需要花费很长时间才能回答,如果您只是单独编码,那么这可能是“个人偏好”。通常它们会指定简洁的东西,如数据库命名约定和空格与制表符(以及多少空格)以及注释/文档注释样式。

UI guidelines are a different beast than the others I think.

UI指南与我认为的其他野兽不同。

One of my favorite examples of coding style guidelines is the Linux kernel coding style, although it doesn't go into the specifics that I've seen in other guides.

我最喜欢的编码风格指南之一是Linux内核编码风格,虽然它没有涉及我在其他指南中看到的细节。

#8


1  

Juval Lowy's C# coding guidelines is an excellent example of a proper guideline. I have a couple of things I'd change in it, but for the most part it's fantastic.

Juval Lowy的C#编码指南是正确指南的一个很好的例子。我有几件事我会改变它,但在大多数情况下它太棒了。

#9


1  

I also like the idea of a coding style helping developers to visually identify bad/buggy code. For example, including the type of a variable in its name can help down the road if someone should accidentally assign an int a float value or something like that.

我也喜欢编码风格的想法,帮助开发人员直观地识别错误/错误的代码。例如,如果某人不小心为某个浮点值或类似的东西分配int,那么在其名称中包含变量的类型可以帮助我们顺利进行。

#10


1  

Code Complete is an excellent book on general programming best practices and guidelines that can be applied to any language.

Code Complete是一本关于通用编程最佳实践和指南的优秀书籍,可以应用于任何语言。

It covers all aspects of programming and is a must read for the practical programmer who wants to do things the "best" way for each problem encountered.

它涵盖了编程的所有方面,对于想要为遇到的每个问题采用“最佳”方式做事的实际程序员来说,必须阅读。

#11


0  

Coding guidelines are behavioural rules for your teammembers, so that you can read eachothers code without too much trouble.

编码指南是团队成员的行为规则,因此您可以毫不费力地阅读每个代码。

It also gets the "bracket on newline or on same line" discussions out of the way at your code review sessions, which saves a lot of time ;-)

它还可以在您的代码审查会议中获得“换行或同线”的讨论,从而节省大量时间;-)

When writing code guidelines, make sure that they're there for a reason, and that they actually help your team on writing more readable code.

在编写代码指南时,请确保它们是有原因的,并且它们实际上帮助您的团队编写更易读的代码。

#1


24  

There are generally three purposes for coding standards:

编码标准通常有三个目的:

  • Reduce the likelihood of bugs
  • 减少错误的可能性

  • Reduce the time required to analyze code written by someone else
  • 减少分析其他人编写的代码所需的时间

  • Give someone a power trip
  • 给某人一个权力之旅

Obviously, the third is a waste of everyone else's time, but you do need to consider it, specifically so you don't go down that road.

显然,第三种是浪费其他人的时间,但你确实需要考虑它,特别是你不要走那条路。

Having said that, there are some definite do's and dont's that I've noticed:

话虽如此,我已经注意到了一些明确的做法和不做的事情:

  • Enforce consistent whitespace usage. Tabs, 2-spaces, 4-spaces, doesn't matter. Keep it consistent, so indent levels aren't screwed up by people using different editors. I've seen mistakes made because maintenance programmers misinterpreted the nesting level of a block of code.
  • 实施一致的空白用法。标签,2个空格,4个空格,无所谓。保持一致,因此使用不同编辑器的人不会搞砸缩进级别。我看到了错误,因为维护程序员误解了代码块的嵌套级别。

  • Enforce consistent logging methodology. It's a huge drain on support staff's time if they aren't able to skim over logs, because everyone's module logs for different reasons, and everyone has a different definition of Info vs. Warning vs. Error.
  • 实施一致的日志记录方法。如果他们无法浏览日志,那么支持人员的时间就会大量消耗,因为每个人的模块日志都有不同的原因,每个人都有不同的信息与警告与错误的定义。

  • Enforce consistent error handling. If module A throws exceptions, module B returns error codes, and module C simply logs and moves on, it'll be a pain to integrate them without letting an error slip through the cracks.
  • 实施一致的错误处理。如果模块A抛出异常,模块B返回错误代码,模块C只是记录并继续运行,将它们集成在一起并不让错误滑过裂缝将是一件痛苦的事。

  • Try to avoid petty things like placement of curly-braces. That's going to get a lot of people arguing over their pet style, and in the end, it really doesn't have a huge impact on the readability of code. On the other hand, enforcing the presence of brackets can make a difference.
  • 尽量避免像花括号那样的小事。这会让很多人争论他们的宠物风格,最后,它确实对代码的可读性没有太大的影响。另一方面,强制执行括号可能会有所不同。

  • When integrating disparate code bases, don't be tempted to change everyone's variable naming conventions to match the golden standard. You may have a standard for moving forward, but what's most important is that any localized standards that already exist are preserved consistently. If one module uses m_member, a maintenance programmer should be using m_member2 rather than applying any other standard (such as member2_ or m_lpcstrMember2 or whatever). Local consistency is king.
  • 在集成不同的代码库时,不要试图改变每个人的变量命名约定以匹配黄金标准。您可能有前进的标准,但最重要的是,已经存在的任何本地化标准都会保持一致。如果一个模块使用m_member,则维护程序员应该使用m_member2而不是应用任何其他标准(例如member2_或m_lpcstrMember2或其他)。本地一致性是王道。

  • Filesystem layout is important. Keep it consistent. Make it easy for someone to jump into a library sourcebase and instantly know where are the headers, the Makefile, the sources, etc. If you're working with Java or Python, this is a no-brainer because the package system enforces it. If you're working with C, C++, or any other myriad of scripting languages, you'll need to devise a standard layout yourself and stick with it.
  • 文件系统布局很重要。保持一致。让某人很容易跳进库源库并立即知道头文件,Makefile,源代码等等。如果你正在使用Java或Python,这是一个明智的选择因为包系统强制执行它。如果您正在使用C,C ++或任何其他无数的脚本语言,您需要自己设计标准布局并坚持使用它。

  • Don't sweat the little stuff. Variable naming conventions, spaces between parentheses or keywords or function names... most of that doesn't matter, because it doesn't reduce the likelihood of a mistake. Every rule you set should have a concrete rationale, and you shouldn't be afraid to change or remove it if you discover it's causing more grief than it's worth.
  • 不要为小东西出汗。变量命名约定,括号或关键字之间的空格或函数名称......大部分都无关紧要,因为它不会降低错误的可能性。你设定的每条规则都应该有一个具体的理由,如果你发现它引起的更多的悲伤而不是它的价值,你不应该害怕改变或删除它。

  • Don't enforce gratuitous comment blocks everywhere. They'll end up as a waste, and most comments are better off being expressed in the code itself (as variable or function names, for example).
  • 不要在任何地方强制执行无偿的评论。它们最终会成为浪费,大多数注释最好不要在代码本身中表达(例如,作为变量或函数名称)。

Finally, the most important thing is to have regular code reviews between peers. Encourage people to speak up when they see a "code smell." Also be sure people realize that constructive code criticism is not meant to be personal - the source is shared by everone on the team, it doesn't just belong to the original author. In my experience, the most heinous problems have been design problems that wouldn't have been solved by any amount of coding guidelines. Software design is still something of an art form (for better or for worse), and a pool of brains is much better than a single one.

最后,最重要的是在同行之间进行定期的代码审查。鼓励人们在看到“代码味道”时说出来。还要确保人们意识到建设性的代码批评并不是个人的 - 来源是团队中的任何人共享的,它不仅仅属于原始作者。根据我的经验,最令人发指的问题是任何编码指南都无法解决的设计问题。软件设计仍然是一种艺术形式(无论好坏),并且大脑池比单个大脑好得多。

#2


9  

if( !codingGuidelines.Followed)
{
   reason = programmer.WhyNot();
   if( reason.Acceptable)
   {
      codingGuidelines.Integrate( reason);
   }
   else
   {
      team.GiveAssKicking(programmer);
   }
}

#3


8  

It's a fairly open question, and the answer is equally as open:

这是一个相当开放的问题,答案同样公开:

Every guideline should cost less to implement than the benefit it brings.

每项指南的实施成本都应低于其带来的好处。

Be careful, because each side of the equation has some hidden parts.

要小心,因为等式的每一边都有一些隐藏的部分。

The cost of implementation can include excluding perfectly good alternatives, stifling creativty and innovation, and encouraging code reviews to degenerate into highlighting minor infractions of the style rather than addressing real issues.

实施成本可以包括排除完美的替代品,扼杀创新和创新,并鼓励代码审查堕落,突出显示风格的轻微违规,而不是解决实际问题。

The value of the benefits may be intangible (and hence frustrating) to a busy developer in a hurry, but might result in your organizations brand being stronger or bringing new staff onto the project being faster - something that might outweigh the small incremental cost of complying.

对于繁忙的开发人员来说,收益的价值可能是无形的(因而令人沮丧),但可能会导致您的组织品牌变得更强大或者让新员工更快地投入到项目中 - 这可能会超过遵守的小增量成本。

#4


4  

As a developer, I generally prefer guidelines to give basic guidance, but not be so strict that I can't code how I like... for instance, if a guideline is telling me what coding patterns must be used rather than allowing me to make my own professional judgement then it's too tight:

作为开发人员,我通常更喜欢指导方针来提供基本指导,但不要太严格以至于我无法编码我喜欢的代码...例如,如果指南告诉我必须使用哪种编码模式而不是允许我做出我自己的专业判断然后它太紧了:

For example, these are the type of things I might expect to see:

例如,这些是我可能期望看到的类型:

  • Style of variable names i.e. hungarian notation(not that I strictly use those)
  • 变量名称的样式,即匈牙利表示法(不是我严格使用那些)

  • Methods should be commented with their general purpose, including what they return (if anything)
  • 方法应该用它们的一般目的评论,包括它们返回的内容(如果有的话)

  • Classes should be defined with a specific layout: i.e. all private fields at the top, followed by events, public methods, private methods, whether they should be in alphabetical order
  • 应使用特定布局定义类:即顶部的所有私有字段,后跟事件,公共方法,私有方法,是否应按字母顺序排列

  • Naming conventions for namespaces, classes, methods, events and properties etc
  • 命名空间,类,方法,事件和属性等的命名约定

You get the picture. I shouldn't be restricted to stuff like:

你得到了照片。我不应该局限于:

  • Thou shalt use If notation instead of int a = (blah)? true : false;
  • 你应该使用If notation而不是int a =(blah)?真假;

Coding styles obviously need to be common across a team to allow developers to be able to work together effectively. You can't have one person way out there in left field using complex mathematical algorithms that nobody else on the team can understand and have another way out in right field who can barely comprehend the implementation of interfaces. So as a rule of thumb, they should be designed to help keep your team together while not dampening productivity and creativity.

编码风格显然需要在团队*同使用,以便开发人员能够有效地协同工作。你不可能使用复杂的数学算法让左边的一个人离开那里,团队中的其他任何人都无法理解,并且在正确的领域中有另一种方法,他们几乎无法理解接口的实现。因此,根据经验,它们应该旨在帮助您的团队保持在一起,同时不会降低生产力和创造力。

Get some input from your development team as a whole so that a "house" standard can incorporate everything it should and not include a bunch of stuff it shouldn't.

从整个开发团队获得一些意见,以便“房屋”标准可以包含它应该包含的所有内容,而不包括一堆不应该包含的东西。

#5


2  

Coding guidelines are there to make it easy for others to read your code. Even if you are writing code for yourself and are the only developer, it may be useful to find a set of guidelines commonly accepted in the industry and stick to them. It will make it easier for you to read other peoples code and for you to fit into a larger team at a later date.

编码指南可以让其他人轻松阅读您的代码。即使您正在为自己编写代码并且是唯一的开发人员,找到业界普遍接受的一套指南并坚持使用它们可能会很有用。它将使您更容易阅读其他人的代码,并让您在以后适应更大的团队。

If using .net, take a look at StyleCop. By default it contains standards that MS use themselves and used to design the .net framework around. You can get it from here:

如果使用.net,请查看StyleCop。默认情况下,它包含MS自己使用的标准,用于设计.net框架。你可以从这里得到它:

http://code.msdn.microsoft.com/sourceanalysis

You can disable rules you don't like and add your own. It can even be scripted to enforce the rules when code is checked in. The great thing about it is that if you're really new to this sort of stuff, it will tell you exactly what you're doing wrong. If you want to go one step further, take a look at Resharper. It's the same sort of thing, but does it in real time as you type (though by default it uses a slightly different standard.

您可以禁用不喜欢的规则并添加自己的规则。在签入代码时,它甚至可以编写脚本来强制执行规则。最重要的是,如果你真的对这类东西不熟悉,它会告诉你你究竟做错了什么。如果你想更进一步,看看Resharper。这是同样的事情,但是当你输入时会实时显示它(尽管默认情况下它使用的标准略有不同。

I'm sure there are similar utilities around other languages if c# is not your thing!

如果c#不是您的话,我相信其他语言也有类似的实用程序!

#6


2  

I want a coding standards document to resolve religious arguments for the team.

我想要一个编码标准文件来解决团队的宗教争论。

For the questions where there are multiple worthwhile answers, and people have a tendency to argue about them for a long time, we want to get consistency across the whole project and avoid spending much time discussing them.

对于有多个有价值的答案的问题,以及人们长期争论它们的倾向,我们希望在整个项目中保持一致性并避免花费太多时间讨论它们。

Good examples are "TABs vs. Spaces" and "K&R vs. ANSI brace placement". Take a poll in the team, make a decision, and write it down. Apply the decision to all your existing code at once, and check it in by itself. Never discuss it again.

很好的例子是“TABs vs. Spaces”和“K&R vs. ANSI大括号放置”。在团队中进行民意调查,做出决定并将其写下来。立即将决定应用于所有现有代码,并自行检查。永远不要再讨论了。

#7


1  

In general, I would want guidelines to answer the questions that you would normally ask but would take too long to answer, and that might be "personal preference" if you were just coding alone. Usually they specify pithy things like database naming conventions and spaces vs. tabs (and how many spaces) as well as commenting / documentation comment styles.

一般来说,我希望指南能够回答您通常会问的问题,但需要花费很长时间才能回答,如果您只是单独编码,那么这可能是“个人偏好”。通常它们会指定简洁的东西,如数据库命名约定和空格与制表符(以及多少空格)以及注释/文档注释样式。

UI guidelines are a different beast than the others I think.

UI指南与我认为的其他野兽不同。

One of my favorite examples of coding style guidelines is the Linux kernel coding style, although it doesn't go into the specifics that I've seen in other guides.

我最喜欢的编码风格指南之一是Linux内核编码风格,虽然它没有涉及我在其他指南中看到的细节。

#8


1  

Juval Lowy's C# coding guidelines is an excellent example of a proper guideline. I have a couple of things I'd change in it, but for the most part it's fantastic.

Juval Lowy的C#编码指南是正确指南的一个很好的例子。我有几件事我会改变它,但在大多数情况下它太棒了。

#9


1  

I also like the idea of a coding style helping developers to visually identify bad/buggy code. For example, including the type of a variable in its name can help down the road if someone should accidentally assign an int a float value or something like that.

我也喜欢编码风格的想法,帮助开发人员直观地识别错误/错误的代码。例如,如果某人不小心为某个浮点值或类似的东西分配int,那么在其名称中包含变量的类型可以帮助我们顺利进行。

#10


1  

Code Complete is an excellent book on general programming best practices and guidelines that can be applied to any language.

Code Complete是一本关于通用编程最佳实践和指南的优秀书籍,可以应用于任何语言。

It covers all aspects of programming and is a must read for the practical programmer who wants to do things the "best" way for each problem encountered.

它涵盖了编程的所有方面,对于想要为遇到的每个问题采用“最佳”方式做事的实际程序员来说,必须阅读。

#11


0  

Coding guidelines are behavioural rules for your teammembers, so that you can read eachothers code without too much trouble.

编码指南是团队成员的行为规则,因此您可以毫不费力地阅读每个代码。

It also gets the "bracket on newline or on same line" discussions out of the way at your code review sessions, which saves a lot of time ;-)

它还可以在您的代码审查会议中获得“换行或同线”的讨论,从而节省大量时间;-)

When writing code guidelines, make sure that they're there for a reason, and that they actually help your team on writing more readable code.

在编写代码指南时,请确保它们是有原因的,并且它们实际上帮助您的团队编写更易读的代码。