关于java命名的约定

先是匈牙利命名法,
http://www.land-of-kain.de/hnc4java/

Hungarian Naming Convention for Java

@for Java Developers
@author Kai Ruhl
@since 1997-07

Intro

A HNC, or hungarian naming convention (hungarian because reportedly the first inventor was hungarian programmer Charles Simonyie at Microsoft), is the methodology of prefixing variables with one or more letters to indicate their type. The Sun Coding Conventions do not use HNC.

The HNC variant presented in this article applies only to variables, not to methods; methods should make their type clear thru their names, e.g. isXXX for booleans, getXXXValue for numericals, etc. It is designed for ease of application and minimal visual clutter, which results in the usage of as few letters as possible.

The HNC for Java

 
 Letter  Description  Example
 
 
 a<x> Array of <x> Object[] aoVals
 b byte, short byte bVal
 c char char cLetter
 d double double dVal
 e Enumeration, Iterator Enumeration eVals
 f float float fVal
 g GUI component JComboBox gChoice
 h Hashtable, HashMap HashMap hData
 i int int iVal
 j - -
 k - -
 l long long lDate
 m - -
 n Numerical (Date, Dimension, BigInteger, ...) BigDecimal nVal
 o Object (whenever nothing else applicates) MidiChannel oChannel
 p - -
 q - -
 r - -
 s String, StringBuffer String sLine
 t boolean (truth value) boolean tRunning
 u - -
 v Vector, ArrayList ArrayList vData
 w - -
 x - -
 y - -
 z - -


然后是ibm上关于命名的一个文章:
http://www-128.ibm.com/developerworks/library/ws-tip-namingconv.html

Java naming conventions

Make your life easier

developerWorks
Document options
<script type="text/javascript" language="JavaScript"> </script>
Set printer orientation to landscape mode

Print this page

<script type="text/javascript" language="JavaScript"> </script>
Email this page

E-mail this page


Rate this page

Help us improve this content


Level: Introductory

Scott Ambler (scott.ambler@ronin-intl.com), President, Ronin International

13 Jul 2000

In this first tip from Scott Ambler, he presents some guidelines for naming various Java elements, to make your job easier.
<script type="text/javascript" language="JavaScript"> </script>

Use full descriptors that accurately describe the variable, field, or class

For example, use names like firstName, grandTotal, or CorporateCustomer. Although names like x1, y1, or fn are easy to type because they're short, they do not provide any indication of what they represent and result in code that is difficult to understand, maintain, and enhance.



Back to top


Use terminology applicable to the domain

If your users refer to their clients as customers, then use the term Customer for the class, not Client. Many developers make the mistake of creating generic terms for concepts when perfectly good terms already exist in the industry or domain.



Back to top


Use mixed case to make names readable

You should use lowercase letters in general, but capitalize the first letter of class names and interface names, as well as the first letter of any non-initial word.



Back to top


Use abbreviations sparingly and intelligently

This means you should maintain a list of standard short forms (abbreviations), you should choose them wisely, and you should use them consistently. For example, if you want to use a short form for the word number, then choose one of nbr, no, or num, document the one you choose (it doesn't really matter which one), and use only that one.



Back to top


Avoid long names (15 characters max is a good idea)

Although the class name PhysicalOrVirtualProductOrService might seem to be a good class name at the time (OK, I'm stretching it on this example), this name is simply too long and you should consider renaming it to something shorter -- perhaps something like Offering.



Back to top


Avoid names that are too similar or that differ only in case

The variable names persistentObject and persistentObjects should not be used together, nor should anSqlDatabase and anSQLDatabase.



Back to top


Capitalize the first letter of standard acronyms

Names will often contain standard abbreviations, such as SQL for Standard Query Language. Names such as sqlDatabase for an attribute or SqlDatabase for a class are easier to read than sQLDatabase and SQLDatabase.



Back to top


Resources



Back to top


About the author

 

Scott W. Ambler is President of Ronin International, a consulting firm specializing in object-oriented software process mentoring, architectural modeling, and Enterprise JavaBeans (EJB) development. He has authored or co-authored several books about object-oriented development, including the recently released The Object Primer 2nd Edition, which covers, in detail, the subjects summarized in this article. He can be reached at scott.ambler@ronin-intl.com and at his Web site at www.ambysoft.com.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值