|
|
<noscript></noscript>
<noscript><tr valign="top"><td width="8"><img alt="" height="1" width="8" src="//www.ibm.com/i/c.gif"/></td><td width="16"><img alt="" width="16" height="16" src="//www.ibm.com/i/c.gif"/></td><td class="small" width="122"><p><span class="ast">Document options requiring JavaScript are not displayed</span></p></td></tr></noscript>
|
<!--START RESERVED FOR FUTURE USE INCLUDE FILES--><!-- 11/29/06 commented out by Jill--><!--<br />
<table border="0" cellpadding="0" cellspacing="0" width="150">
<tr>
<td class="v14-header-2-small">Using XML, but need to do more?</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" class="v14-gray-table-border">
<tr>
<td width="150" class="no-padding">
<table border="0" cellpadding="0" cellspacing="0" width="143">
<tr valign="top">
<td width="8"><img src="//www.ibm.com/i/c.gif" width="8" height="1" alt="" /></td>
<td><img src="//www.ibm.com/i/v14/icons/fw_bold.gif" height="16" width="16" border="0" vspace="3" alt="" /></td>
<td width="125">
<p><a href="http://www.ibm.com/developerworks/kickstart/database.html?S_TACT=105AGX01&S_CMP=SIMPLEART" class="smallplainlink">Download DB2 Express-C 9</a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
--><!--END RESERVED FOR FUTURE USE INCLUDE FILES-->
|
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.
<!--START RESERVED FOR FUTURE USE INCLUDE FILES-->
<script type="text/javascript" language="JavaScript">
<!--
if (document.referrer&&document.referrer!="") {
// document.write(document.referrer);
var q = document.referrer;
var engine = q;
var isG = engine.search(/google/.com/i);
var searchTerms;
//var searchTermsForDisplay;
if (isG != -1) {
var i = q.search(/q=/);
var q2 = q.substring(i+2);
var j = q2.search(/&/);
j = (j == -1)?q2.length:j;
searchTerms = q.substring(i+2,i+2+j);
if (searchTerms.length != 0) {
searchQuery(searchTerms);
document.write("<div id=/"contents/"></div>");
}
}
}
//-->
</script>
<!--END RESERVED FOR FUTURE USE INCLUDE FILES-->
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
|
|
|
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.
|
|
相关推荐
1. 模块命名、数据库表命名、域模型命名、各分层的类/方法命名、页面的命名; 模块命名: a. 包命名:com.project_name.module_name.action/service/dao/ws; service的实现都置于...
本资源提供编程命名规范模版,给刚走进IT行业的人士一个很好的指引
通过遵循有意义的名称、使用适当的命名约定(如小驼峰和大驼峰命名法)、避免使用保留字以及保持名称的简洁性,开发人员可以创建出清晰、易读和可维护的代码。这不仅提高了代码的可读性,还有助于减少错误、提高开发...
一个非常简单的MyBatis辅助工具,可以基于DAO的命名约定帮你生成并维护SQL语句。pndao是票牛Java团队实践一年演化出来的工具。在实际生产中减少了80%以上的重复SQL编写工作,从而把关注力转移到模型本身的制定上。...
【游戏中变量命名约定】 游戏常量约定: 游戏中有貂蝉,张飞,两位主角 敌人有长兵,短兵,探马,张辽四种类型的兵种。张辽是boss级的敌人。 涉及角色的常量命名规则,凡是在常量相应字母意思含义为:...
知道了标识符的组成规则和注意事项后,这里我们再说一下起名字常用的命名约定: 小驼峰命名法 约定1:标识符一个单词的时候,首字母小写 范例1:name 约定2:标识符是多个单词的时候,第一个单词首字母小写,其他...
必须养成优秀程序员的编写习惯:缩进(用空格)、注释、命名约定。 大小写敏感。 单独的“;”代表一条空语句。 main函数是我们整个程序的执行入口所以必须是静态公开的。 必须写成这样: public static void main...
java、svn、mysql、dubbr、venus-common-monitor、venus-restful、公共码、日志、代码规范、命名、配置文件、Code+Review建议、postman等等等等;各类规范文档
java编程规范 编程原则 命名约定 MVC规范 其它规范
你可以看到这个类对属性的存取方法(getter and setter method)使用了标准JavaBean命名约定,同时把类属性(field)的访问级别设成私有的(private)。这是推荐的设计,但并不是必须的。Hibernate也可以直接访问...
Pndao是一个轻量级的MyBatis SQL自动化生成工具,旨在通过遵循DAO的命名约定来简化SQL语句的生成与维护过程。该项目完全采用Java语言开发,为开发者提供了一个高效的数据库操作解决方案。 技术构成: - 主要编程...
java开发必须的规范 代码撰写规范 命名约定 Java文件的组织 编码格式 程序注释 一些建议
欢迎-命名公约项目 ...命名约定主题列表: 会费 该项目的存在要归功于我们所有的贡献者:{%GitHubContributors%} {%endGitHubContributors%} 帮助我们用您的贡献创建更好的约定。 只需阅读我们的开始使用!
Java编码约定 56 运算符的优先级 58 升级和表达式的类型转换 62 独立实践 70 第五章:数组 71 学习目标 71 数组的描述 72 创建数组 72 多维数组 78 拷贝数组 80 内容总结 83 独立实践 84 第六章:继承 86 学习目标:...
目录 1. 前言 2. 源文件基础 3. 源文件结构 4. 格式 5. 命名约定 6. 编程实践 7. Javadoc 8. 后记
Play Framework(Java)应用程序中的程序包命名空间示例在播放框架2.4.x中如何使用非默认包名称空间并不是很明显。 只包含一个衬里: 请注意,在Play中,控制器,模型和视图包的名称约定现在就这样,并且可以根据...
1.2 相关知识 1.2.1 文件后缀名 1.2.2 源文件样式约定 1.2.3 注释规范 1.2.4 命名规范 Java高级程序设计实战教程第一章-Java编码规范全文共13页,当前为第3页。 1.2.1 文件后缀名 表1-1 Java程序使用的文件后缀名 ...
有很多命令行(cli)解析库。 尽管它们工作出色,但我发现它们都不容易使用和直接使用。 在处理项目时,我梦想着可以使用以下库: ...java Invitor --name "John Smith" --money 5000 invite 然后魔术发生了。
}JavaBean convention如果值类型遵循 JavaBean 命名约定,只需在访问器方法前面加上'get'(或者,布尔访问器是'is')。 FreeBuilder 会跟随,并在 setter 方法上添加“set”前缀,以及从 toString 输出中删除前缀。@...
然而,有一些常见的做法和约定可以帮助你更好地组织和管理你的Java代码。以下是一些建议: 使用包(Packages):Java使用包来组织类。你可以将相关的类放在同一个包中,以便更好地管理和访问它们。包也可以防止命名...