开发者

What should be commented in an ASP.NET MVC application?

Here is the list of points that is interesting for me.

Should we put comments on our controller's action methods?

The reason is why I am asking this is because the action methods are very self explanatory, and the best comment I can think of would开发者_JAVA百科 be something like "Returns the view for Products." Seems to cause mess and doesn't feel much helpful.

Should we have any comments in the Views?

When visual studio generates action methods it automatically puts in comments like ...

    //
    // GET: /Products/

... is that ^ good practice?

Any advises/recommendations on commenting/documenting ASP.NET MVC applications?

I did google for information about this but didn't find anything helpful that's why I am asking here.


My practice is to never comment something unless it absolutely needs comments. Your code should be so easy to read, comments are unnecesary. If you find yourself needing to write a comment, that's a sign that perhaps you can simplify what you're doing.


I usually get rid of those auto-generated comments. I'd say you should follow the same principles with MVC code that you follow with regular code:

  • If the purpose and function of a method is obvious from its name, don't bother commenting it.
  • If it's obvious what a line of code is doing and why, don't bother commenting it.
  • If there's a possibility that the method will have expectations that aren't immediately obvious, or may have less-than-obvious secondary consequences, comment it.
  • If it's not obvious what a line of code is doing, change the code to be more clear.
  • If it's not obvious why you're doing what you're doing, add a comment.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜