zoukankan      html  css  js  c++  java
  • 《编写可读代码的艺术》第6章 写出言简意赅的注释

    1. 让注释保持紧凑

    1 //反面示例
    2 // The int is the CategoryType.
    3 // The first float in the inner pair is the 'score',
    4 // the second is the 'weight'.
    5 typedef hash_map<int, pair<float, float> > ScoreMap;
    6 
    7 //正面示例
    8 // CategoryType -> (score, weight)
    9 typedef hash_map<int, pair<float, float> > ScoreMap;

    2. 避免使用不明确的代词

    1 // Insert the data into the cache, but check if it's too big first.
    2 
    3 //1. 把it改成data
    4 // Insert the data into the cache, but check if the data is too big first.
    5 
    6 //2. 重组以使it更明确
    7 // If the data is small enough, insert it into the cache.

    3. 润色粗糙的句子

    1 // Depending on whether we've already crawled this URL before, give it a different priority.
    2 
    3 //更简单直接,且包含“优先级”相关的信息
    4 // Give higher priority to URLs we've never crawled before.

    4. 用精心挑选的例子进行说明

    1 // Example: Strip("abba/a/ba", "ab") returns "/a/"
    2 String Strip(String src, String chars) { ... }

    5. ”具名参数函数“的注释

    # Python
    # Call the function using named parameters
    Connect(timeout = 10, use_encryption = False)
    
    // C++
    // Call the function with commented parameters
    Connect(/* timeout_ms = */ 10, /* use_encryption = */ false);

    6. 采用信息量高的词

    1 // This class acts as a caching layer to the database.
    2 
    3 // Canonicalize the street address (remove extra spaces, "Avenue" -> "Ave.", etc.)
  • 相关阅读:
    连接数据库及出现System.AccessViolationException错误的解决方法
    WCF REST 工作总结
    jquery easyui 扩展验证
    正则表达式语法
    SQL select语句执行顺序
    添加头文件afxwin.h后引起异常的解决办法
    imagej基本操作
    医学图像处理(一)
    灰度图像的自动阈值分割(Otsu 法)
    关于glog使用中遇到的问题
  • 原文地址:https://www.cnblogs.com/yyqng/p/14227320.html
Copyright © 2011-2022 走看看