《clean code》

2018-07-29  本文已影响0人  EmilioWong

本文记录阅读《clean code》的过程中一些个人收获和疑惑,持续更新ing。

一些收获

函数

public Money calculatePay(Employee e) throws InvalidEmployeeType {
    switch (e.type) {
        case COMMISSIONED:
            return calculateCommissionedPay(e);
        case HOURLY:
            return calculateHourlyPay(e);
        case SALARIED:
            return calculateSalariedPay(e);
        default:
            throw new InvalidEmployeeType(e.type);
    }
}

注释

  1. 法律信息
  2. 对意图的解释
  3. 警示
  4. TODO
  5. 放大某些看来不合理之物的重要性。这个有点难理解,下面是原文内容。不过我觉得这个其实和“对意图的解释”有点类似。
String listItemContent = match.group(3).trim();
// the trim is real important. It removes the starting
// spaces that could cause the item to be recognized
// as another list
new ListItemWidget(this, listItemContent, this.level + 1);
return buildList(text.substring(match.end()))
  1. 公共API的javadoc(javadoc也可能存在废话。如果要求所有的变量和函数都要有注释的规则是愚蠢可笑的)
  1. 喃喃自语
  2. 多余的注释
  3. 误导性注释
  4. 循规蹈矩式注释
  5. 日志式注释
  6. 废话注释
  7. 可怕的废话(指的是javadoc)
  8. 能用函数或变量时就别用注释
  9. 位置标记(并不是所有位置标记都是烂代码,但比较容易滥用)
  10. 括号后面的注释
  11. 归属于署名(并不是@author这种,源代码控制系统是这类信息最好的归属地:svn、git等)
  12. 注释掉的代码
  13. HTML注释
  14. 非本地信息(在本地注释的上下文环境中给出系统级的信息)
  15. 信息过多
  16. 不明显的联系
  17. 函数投
  18. 非公共代码中的javadoc

对象与数据结构

一点疑惑

上一篇 下一篇

猜你喜欢

热点阅读