【问题标题】:Your way to write simple comments你写简单评论的方式
【发布时间】:2012-06-27 11:54:32
【问题描述】:

你们如何在一些只为自己使用的简单代码上编写 cmets?

我主要编写 JavaScript 和 PHP 代码,但我真的找不到编写 cmets 的好方法。

如果我有一小段代码,我通常会这样做:

x = doThis(getSomeValueFromSomewhere());  // This is a short line of code

我觉得这看起来很不错,但是当线路变长或多行时,它就不起作用了,

 // Dont really like this since it's not clear if it describes only line 1, or all lines.
 aLongerVariableName = (getSomeValueFromSomewhere() == "this is what I want") ? "true value" : "false value";
 x = doThis(aLongerVariableName); 

那么,你是怎么做到的呢?

【问题讨论】:

    标签: comments


    【解决方案1】:

    一种改进 javascript 中的注释/注释块的简单方法,在编程时工作起来非常简单快捷。

    当您想在 javascript 中创建评论块时,您需要添加这种众所周知的方式:

    /*
    ...
    */
    

    所以当你需要decomment时你需要改变开始/*和结束*/,但是我是这样使用的:

    /*
    ...
    //*/
    

    这样一来,将开头的 /* 改为 //* 就可以将整个块解压,只添加一个字符,无需搜索注释的结尾。

    【讨论】:

      【解决方案2】:
      (*
       * For blocks of comments that serve as important documentation
       * e.g descriptions of functions.
       *)
      

      可能被重新格式化为

       (* For blocks of comments thet serve as important documentation
        * e.g descriptions of functions. *)
      

      还有 // 像你一样的短内联 cmets。 别忘了 Ctrl-/ 是你的朋友 ;-)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-28
        • 1970-01-01
        • 2011-05-17
        • 2010-10-12
        • 2016-11-18
        相关资源
        最近更新 更多