代码中有注释的标准格式吗? [英] Are there standard formats for comments within code?

查看:122
本文介绍了代码中有注释的标准格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道人们在他们的代码中是否有标准的注释格式。不是类似于xml的方法或类的注释,而是方法中的注释。






另请参阅:






解决方案

除了格式化之外,你应该考虑几个很好的注释。


  1. 不要简单地重述代码正在做什么。例如,




  //启动服务
StartServices();


是一个可怕的评论!


  1. 描述 为什么 。为什么代码在做什么?什么是业务假设或算法步骤?


  2. 设置您的评论的格式,以获得最大的可读性。


  3. 如果有人已经开始以标准方式发表评论,请不要违反该标准。


  4. 查看有关编写有效评论的MSDN文章: http://msdn.microsoft.com/en-us/library/aa164797.aspx



I'm wondering if people have a standard format for comments in their code. Not things like xml comments for a method or class but rather comments within a method.


See also:

Is there a standard (like phpdoc or python’s docstring) for commenting C# code?

解决方案

You should really consider a couple things to make good comments beyond formatting.

  1. Do not simply restate what the code is doing. For example,

 // Start the services
 StartServices();

is a frigging terrible comment!

  1. Describe why. Why is the code doing what it's doing? What's the business assumption or algorithm step?

  2. Format your comments for maximum readability. Tab them properly, leave spaces where necessary, etc.

  3. If someone has already started commenting in a standard way, don't break that standard.

  4. Check this article on MSDN about writing effective comments: http://msdn.microsoft.com/en-us/library/aa164797.aspx

这篇关于代码中有注释的标准格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆