没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
73页
是英文的This white paper describes a collection of standards, conventions, and guidelines for writing solid Java code. They are based on sound, proven software engineering principles that lead to code that is easy to understand, to maintain, and to enhance. Furthermore, by following these coding standards your productivity as a Java developer should increase remarkably – Experience shows that by taking the time to write high-quality code right from the start you will have a much easier time modifying it during the development process. Finally, following a common set of coding standards leads to greater consistency, making teams of developers significantly more productive
资源推荐
资源详情
资源评论
www.AmbySoft.com/javaCodingStandards.pdf
Copyright 1998-1999 AmbySoft Inc.
Writing Robust Java Code
The AmbySoft Inc. Coding Standards for Java
v17.01c
Scott W. Ambler
Software Process Mentor
A good developer knows that there
is more to development than programming.
A great developer knows that there
is more to development than development.
This Version: January 2, 1999
www.AmbySoft.com/javaCodingStandards.pdf
Copyright 1998-1999 AmbySoft Inc.
This page left unintentionally blank.
(yuk yuk yuk)
www.AmbySoft.com/javaCodingStandards.pdf
Copyright 1998-1999 AmbySoft Inc.
Purpose of this White Paper
This white paper describes a collection of standards, conventions, and guidelines for writing solid Java
code. They are based on sound, proven software engineering principles that lead to code that is easy to
understand, to maintain, and to enhance. Furthermore, by following these coding standards your
productivity as a Java developer should increase remarkably – Experience shows that by taking the time to
write high-quality code right from the start you will have a much easier time modifying it during the
development process. Finally, following a common set of coding standards leads to greater consistency,
making teams of developers significantly more productive.
Important Features of This White Paper
• Existing standards from the industry are used wherever possible – You can reuse more than just code.
• The reasoning behind each standard is explained so that you understand why you should follow it.
• Viable alternatives, where available, are also presented along with their advantages and disadvantages
so that you understand the tradeoffs that have been made.
• The standards presented in this white paper are based on real-world experience from numerous object-
oriented development projects. This stuff works in practice, not just theory.
• These standards are based on proven software-engineering principles that lead to improved
development productivity, greater maintainability, and greater enhancability.
Target Audience
Professional software developers who are interested in:
• Writing Java code that is easy to maintain and to enhance
• Increasing their productivity
• Working as productive members of a Java development team
Help Me Improve These Standards
Because I welcome your input and feedback, please feel free to email me at scott@ambysoft.com with
your comments and suggestions. Let’s work together and learn from one another.
Acknowledgments
The following people have provided valuable input into the development and improvement of these
standards, and I would like to recognize them for it.
Stephan Marceau Lyle Thompson
Eva Greff Wayne Conrad
Graham Wright Alex Santos
Larry Allen Dick Salisbury
John Pinto Vijay Eluri
Bill Siggelkow Camille Bell
Kathy Eckman Guy Sharf
Kyle Larson Robert Marshall
Mark Brouwer
Gerard Broeksteeg
Scott W. Ambler
December 1998
www.AmbySoft.com/javaCodingStandards.pdf
Copyright 1998-1999 AmbySoft Inc.
This page also left unintentionally blank.
(although now it isn’t quite as funny)
www.AmbySoft.com/javaCodingStandards.pdf
Copyright 1998 AmbySoft Inc.
i
Table of Contents
GENERAL CONCEPTS.............................................................................................................................. 1
WHY CODING STANDARDS ARE IMPORTANT ............................................................................................... 1
THE PRIME DIRECTIVE ................................................................................................................................ 1
WHAT MAKES UP A GOOD NAME................................................................................................................ 2
GOOD DOCUMENTATION ............................................................................................................................. 3
The Three Types of Java Comments ....................................................................................................... 4
A Quick Overview of javadoc ................................................................................................................. 5
AMBLER’S LAW OF STANDARDS.................................................................................................................. 6
STANDARDS FOR MEMBER FUNCTIONS........................................................................................... 7
NAMING MEMBER FUNCTIONS .................................................................................................................... 7
Naming Accessor Member Functions..................................................................................................... 7
Getters ................................................................................................................................................................. 7
Alternative Naming Convention for Getters – Has and Can ........................................................................... 8
Setters.................................................................................................................................................................. 8
Constructors......................................................................................................................................................... 8
MEMBER FUNCTION VISIBILITY................................................................................................................... 9
DOCUMENTING MEMBER FUNCTIONS.......................................................................................................... 9
The Member Function Header................................................................................................................ 9
Internal Documentation........................................................................................................................ 11
TECHNIQUES FOR WRITING CLEAN CODE.................................................................................................. 12
Document Your Code............................................................................................................................ 12
Paragraph/Indent Your Code............................................................................................................... 12
Use Whitespace in Your Code .............................................................................................................. 13
Follow The Thirty-Second Rule............................................................................................................ 13
Write Short, Single Command Lines..................................................................................................... 13
Specify the Order of Operations........................................................................................................... 13
STANDARDS FOR FIELDS (FIELDS/PROPERTIES)......................................................................... 14
NAMING FIELDS......................................................................................................................................... 14
Naming Components (Widgets) ............................................................................................................ 14
Alternative for Naming Components – Hungarian Notation ............................................................................. 14
Alternative for Naming Components – Postfix-Hungarian Notation................................................................. 15
Naming Constants................................................................................................................................. 15
Naming Collections .............................................................................................................................. 16
Alternative for Naming Collections – The ‘Some’ Approach............................................................................ 16
FIELD VISIBILITY ....................................................................................................................................... 16
Do Not “Hide” Names.......................................................................................................................... 17
DOCUMENTING A FIELD............................................................................................................................. 17
THE USE OF ACCESSOR MEMBER FUNCTIONS........................................................................................... 17
Naming Accessors................................................................................................................................. 18
Advanced Techniques for Accessors..................................................................................................... 19
Lazy Initialization.............................................................................................................................................. 19
Getters for Constants ......................................................................................................................................... 20
Accessors for Collections .................................................................................................................................. 21
Accessing Several Fields Simultaneously.......................................................................................................... 22
Visibility of Accessors........................................................................................................................... 23
Why Use Accessors?............................................................................................................................. 24
Why Shouldn’t You Use Accessors? ..................................................................................................... 24
ALWAYS INITIALIZE STATIC FIELDS........................................................................................................... 25
STANDARDS FOR LOCAL VARIABLES ............................................................................................. 26
剩余72页未读,继续阅读
资源评论
jzzhuhyfu
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功