现有标准样式和编码标准文档

发布于 2024-07-06 11:21:39 字数 1449 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

寂寞花火° 2024-07-13 11:21:39

C++ 编码标准:101 条规则、指南和最佳实践(C++ 深入研究)系列)
作者:赫伯·萨特 (Herb Sutter) 和安德烈·亚历山德雷斯库 (Andrei Alexandrescu)。

C++ Coding Standards: 101 Rules, Guidelines, and Best Practices (C++ In-Depth Series)
by Herb Sutter and, Andrei Alexandrescu.

最笨的告白 2024-07-13 11:21:39

我真的认为采用哪一种并不重要,只要大家都同意就可以了。 有时这可能很难,因为某些风格似乎与人们的品味不符。 也就是说,这归结为关于在所有成员变量前添加 m_ 是否漂亮的争论。

我已经使用和修改 Geosoft 标准一段时间了,这些是针对 C++ 的。 what-is-your-favorite-coding- 还有其他一些内容指南清单 线程

I really think it does not matter which one you adopt, as long as everyone goes along with it. Sometimes that can be hard as it seems that some styles don't agree with peoples tases. I.e. it comes down to arguing about whether prefixing all member variable with m_ is pretty or not.

I have been using and modifying the Geosoft standards for a while, these are for C++. There are some other at the what-is-your-favorite-coding-guidelines-checklist thread

小伙你站住 2024-07-13 11:21:39

嗯,奇怪的问题。 只需选择大多数团队成员熟悉的标准即可。 为您的团队进行某种民意调查。 不知道 SO 在这里能提供什么帮助:)

Hmm, strange question. Just choose standard which most of the team members are familiar with. Make some kind of poll for your team. Not sure how SO can help here :)

段念尘 2024-07-13 11:21:39

试试这个,它是美国宇航局戈达德太空飞行中心使用的那个。

http://software.gsfc.nasa.gov/AssetsApproved/PA2。 4.1.3.pdf

Try this one, it's the one that NASA's Goddard space flight centre uses.

http://software.gsfc.nasa.gov/AssetsApproved/PA2.4.1.3.pdf

久夏青 2024-07-13 11:21:39

我为一家英国大公司编写了一个编码标准,并且非常有意识地给出了我选择某些东西的原因,而不是仅仅让它成为一堆“你应该”的声明。 (-:

作为一种快速出路,我建议强制执行:

  • Scott Meyers 的《Effective C++ 第三版》(Amazon 链接) - 如果您能找到本书第一版的副本,请购买它以了解 OO 设计的概述,该概述已从后续版本中删除。)-:
  • Scott Meyer 的书《Effective STL》(Amazon 链接) - 您必须使用 STL 才能有效地使用 C++。
  • Steve McConnell 的书《Code Complete 2》(Amazon 链接) - 不是特定于 C++ 的,而是完整的的伟大见解。

I've written a coding standard for a major British company and was very conscious of putting reasons why I selected certain things rather than just make it a bunch of "Thou shalt" pronouncements. (-:

As a quick way out, I'd suggest mandating:

  • Scott Meyers's Effective C++ 3rd Edition (Amazon link) - if you can find a copy of the 1st edition of this book then buy it for the overview of OO design which was removed from later editions. )-:
  • Scott Meyer's book Effective STL (Amazon link) - you must use STL to use C++ efficiently.
  • Steve McConnell's book Code Complete 2 (Amazon link) - not C++ specific but full of great insights.
浅笑依然 2024-07-13 11:21:39

编码标准只有帮助您编写代码才有意义。 因此,他们只需要保持代码的一致性(即,如果有人将 m_ 用作变量成员,而有人没有,那么与他们都使用相同样式相比,理解代码可能需要更长的时间)。

这就是他们(应该)做的,所以只需选择您现有的代码并确保您的团队代码采用相同的风格即可。

我喜欢把它想象成卡通。 如果你成为《辛普森一家》的漫画家,你必须以官方的方式画眼睛,否则一切看起来都是裤子,但如果你去《恶搞之家》,你必须以不同的方式画它们。 两种方式都没有错。

太多的标准都是毫无意义的限制,是由那些不自己编码(或者认为自己太优秀而无法遵守这些限制)的人编写的。 其他人试图教你如何编码。 两者都没有在良好的标准中占有一席之地,它们只是让您更容易查看某些代码并理解其功能。

例如。 我的标准包括命名目录的规则 - 您将始终将代码放在与项目同名的目录中,所有二进制文件都放在 bin 子目录中,所有配置文件都在同一位置,以及更改日志等。简单的东西,但我保证我永远不会在根目录中找到一个与其二进制文件名称不同的项目,我不知道对其进行了哪些更改。 简单、容易的事情却能带来巨大的改变。

Coding standards are only meaningful if they help you write code. So they just need to keep your code consistent (ie if someone puts m_ for variable members and someone doesn't, it can take longer to grok the code than if they all used the same style).

That's all they (should) do, so just pick up your existing code and make sure your team codes to the same style.

I like to think of it like cartoons. If you become a cartoonist on the Simpsons, you have to draw eyes in the official way or everything looks pants, but if you go to Family Guy, you have to draw them differently. Neither way is wrong.

Too many standards are about meaningless restrictions, written by people who don't code themselves (or consider themselves too good to keep to them). Others try to teach you how to code. Neither has its place in a good standard, those just make it easier for you to look at some code and understand what its doing.

eg. my standards include rules for naming directories - you will always have your code in a directory called the same name as the project, and all binaries go in the bin subdir, with all config files in the same place, and a changelog, etc. All simple stuff, but I guarantee I'll never find a project called something different with its binaries in the root directory where I don't know what changes were made to it. Simple, easy stuff that makes a huge difference.

花想c 2024-07-13 11:21:39

我同意 Harald Scheirich 的观点,最重要的是让团队就规则应该是什么达成一致,而不是仅仅选择外人推荐的一套。

我个人的建议是阅读 Steve McConnell 编写的Code Complete,第二版,其中描述了(以及许多其他有用的内容)东西)几个常见的编码标准,并对每个标准提供评论。 这可能有助于您的团队制定自己的标准。

I agree with Harald Scheirich, it is most important to have the team agree on what the rules should be rather than just picking a set that has been recommended by outsiders.

My personal recommendation would be to read Code Complete, 2nd Edition by Steve McConnell which describes (among a whole lot of other useful stuff) several common coding standards and offers commentary on each. This might help your team in setting up your own standards.

离线来电— 2024-07-13 11:21:39

Lockheed Martin 的 JSF Air Vehicle C++ Coding Standards 是一本有趣的读物,但它有点矫枉过正,除非您在错误可能致命的领域工作。 从计算机伦理的角度来看,这仍然是一个非常重要的例子,说明如何以安全性和正确性为重中之重进行编程。

对于通用 C++ 编码,我个人推荐 Herb Sutter 的C++ 编码标准。 从一开始,它就强调什么要标准化(与风格或偏好相关的事情,而不是促进安全、正确性和效率的实践)。 它也是您列表中最简单的读物之一,为每个标准提供了非常简短但简洁的论点,使其易于向您的同事展示。

Lockheed Martin's JSF Air Vehicle C++ Coding Standards is an interesting read but it's a bit overkill unless you're working in fields where a bug can kill people. It's still a very important example to look at from a computer ethics standpoint about an example of how to program with safety and correctness being top priority.

For general-purpose C++ coding, I'd personally recommend C++ Coding Standards by Herb Sutter. From the very beginning, it emphasizes what not to standardize (things relating to style or preference rather than practices that promote safety, correctness, efficiency). It's also among the easiest reads in your list giving very brief but concise arguments for each standard, making it something easy to show your co-workers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文