zoukankan      html  css  js  c++  java
  • Effective Java 56 Adhere to generally accepted naming conventions

    Typographical naming conventions

       

    Identifier Type

    Type Examples

    Package

    com.google.inject, org.joda.time.format

    Class or Interface

    Timer, FutureTask, LinkedHashMap, HttpServlet

    Method or Field

    remove, ensureCapacity, getCrc

    Constant Field

    MIN_VALUE, NEGATIVE_INFINITY

    Local Variable

    i, xref, houseNumber

    Type Parameter

    T, E, K, V, X, T1, T2

       

    Grammatical conventions

    Identifier Type

    Type Examples

    Package

    no rules

    Class or Interface

    Timer, BufferedWriter, or ChessPiece.

    Collection or Comparator. Runnable, Iterable, or Accessible.

    BindingAnnotation, Inject, ImplementedBy, or Singleton

    Method

    append or drawImage

    isDigit, isProbablePrime, isEmpty, isEnabled,

    or hasSiblings.

    size, hashCode, or getTime

    toType(toString, toArray) asType(asList) typeValue(intValue), static factories(valueOf, of, getInstance, newInstance, getType, newType)

    Field

    initialized, composite, height, digits, or bodyStyle

    Constant Field

    MIN_VALUE, NEGATIVE_INFINITY

    Local Variable

    i, xref, houseNumber

    Type Parameter

    T, E, K, V, X, T1, T2

       

    Summary

    Internalize the standard naming conventions and learn to use them as second nature. The typographical conventions are straightforward and largely unambiguous; the grammatical conventions are more complex and looser. To quote from The Java Language Specification [JLS, 6.8], "These conventions should not be followed slavishly if long-held conventional usage dictates otherwise." Use common sense.

  • 相关阅读:
    对Spring 框架 AOP(面向切面)的理解
    页面自动刷新
    页面通过ajax传值到后台,后台返回值展示在页面输入框
    java中怎么跳出两层for循环
    人的三种思维角度
    我理解的战争(程序员是需要有立场的)
    我所理解的JavaScript中的prototype与__proto__、constructor
    一个"失速"项目的总结
    TDD学习笔记
    Java SQL动态生成库
  • 原文地址:https://www.cnblogs.com/haokaibo/p/adhere-to-generally-accepted-naming-conventions.html
Copyright © 2011-2022 走看看