先是匈牙利命名法,
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 ![](https://i-blog.csdnimg.cn/blog_migrate/c6ccbc96c20bebb0d73e8e6368158ef5.gif) | ![developerWorks](https://i-blog.csdnimg.cn/blog_migrate/60cd38ab37758b403bb4b466407686b8.png) |
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.
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.
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.
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.
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
.
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
.
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
.
Resources
About the author
![](https://i-blog.csdnimg.cn/blog_migrate/c6ccbc96c20bebb0d73e8e6368158ef5.gif) |
| ![](https://i-blog.csdnimg.cn/blog_migrate/c6ccbc96c20bebb0d73e8e6368158ef5.gif) | 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. |