zoukankan      html  css  js  c++  java
  • 命名 —— 函数的命名

    • load、fetch、make
      • load:本地(磁盘)加载
      • fetch:网络爬取
      • make:一些合成数据;

    1. 函数名刻画全部的事情

    • 子程序的命名应描述所有的输出结果以及副作用(side effects)。

    2. 避免不当的动词

    • 无意义或者模糊:
      • handleCalculation、performServeices、processInput,dealwithOutput,中文上,这些动词就叫做,万能动词;
      • 当然动词 handle 有时也非用不可,比如 eventHandling,用作事件处理这一特殊上下文时;
      • 将 handleOutput 改造为 formatAndPrintOutput

    3. 动词后加不加宾语

    • 在面向对象语言中,不必在函数名中加入对象的名字,其对象本身已经包含在调用语句中了。
      • 举例:document.Print()、orderInfo.Check()、monthlyRevenues.Calc()
      • 而且,不加宾语,有时也能在继承关系中起到某种抽象的作用;
        • document.PrintDocument(),显然当有子类如 Check(支票)从 Document 类继承而来,check.PrintDocument() 就显得不伦不类了;

    4. 介词

    • of

      • pathOf:从什么什么中取得路径(参数充当介词宾语)

        public String pathOf(Arfifact artifact) 
        {
            StringBuilder path = new StringBuilder();
        
            path.append(artifact.getArtifactId()).append(PATH_SEPARATOR);       
                // PATH_SEPARATOR = '/'
            path.append(artifact.getBaseVersion()).append(PATH_SEPARATOR);
            path.append(artifact.getArtifactId()).append(ARTIFACT_SEPARATOR)
                .append(artifact.getVersion());
                        // ARTIFACT_SEPARATOR = '-'
        }   
  • 相关阅读:
    Leetcode 剑指 Offer 27(二叉树的镜像)
    Leetcode 1022从根到叶的二进制之和
    Leetcode 993二叉树的堂兄弟节点
    Leetcode 965单值二叉树
    Leetcode 938 二叉搜索树的范围和
    hdu 2082 找单词
    母函数模板
    hdu 1398 Square Coins
    hdu 1085 Holding Bin-Laden Captive!
    hdu 1028 Ignatius and the Princess III
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9421017.html
Copyright © 2011-2022 走看看