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 = '-'
        }   
  • 相关阅读:
    urlrewrite地址重写的使用
    算法学习
    数据库之Case When
    速卖通返回503错误
    概述:软件开发工具
    c#将List<T>转换成DataSet
    表单域规范写法
    ant打包和jar包混淆
    Node.js文档和教程
    webpack开发和生产两个环境的配置详解
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9421017.html
Copyright © 2011-2022 走看看