没有合适的资源?快使用搜索试试~ 我知道了~
首页the elements of java style
资源详情
资源评论
资源推荐

1
The Elements of Java™ Style
The Elements of Java™ Style
Al Vermeulen
Scott W. Ambler
Greg Bumgardner
Eldon Metz
Trevor Misfeldt
Jim Shur
Patrick Thompson

2
PUBLISHED BY CAMBRIDGE UNIVERSITY PRESS (VIRTUAL PUBLISHING)
FOR AND ON BEHALF OF THE PRESS SYNDICATE OF THE UNIVERSITY OF
CAMBRIDGE
PUBLISHED BY THE PRESS SYNDICATE OF THE UNIVERSITY OF
CAMBRIDGE
The Pitt Building, Trumpington Street, Cambridge, United Kingdom
CAMBRIDGE UNIVERSITY PRESS
The Edinburgh Building, Cambridge CB2 2RU, UK http://www.cup.cam.ac.uk
40 West 20th Street, New York, NY 10011-4211, USA http://www.cup.org
10 Stamford Road, Oakleigh, Melbourne 3166, Australia
Ruiz de Alarcón 13, 28014 Madrid, Spain
Published in association with SIGS Books
© Cambridge University Press 2000
This edition © Cambridge University Press (Virtual Publishing) 2001
All rights reserved.
This book is in copyright. Subject to statutory exception and to the provisions of relevant
collective licensing agreements, no reproduction of any part may take place without the
written permission of Cambridge University Press.
Any product mentioned in this book may be a trademark of its company.
First published in 2000
Reprinted in 2000
Design and composition by David Van Ness
Cover design by Andrea Cammarata
Printed in the United States of America
A catalog record for this book is available from the British Library.
Library of Congress Cataloging in Publication data is on record with the publisher.
ISBN 0 521 77768 2 paperback
e-ISBN 0 511 00339 0 virtual (netLibrary Edition)

3
The authors would like to thank
our loved ones for enduring us
while we toiled away on this book.

4
Table of Contents
Preface
ix
Audience x
Acknowledgments xi
Introduction
xiii
1. General Principles
1
2. Formatting Conventions
5
3. Naming Conventions
15
Package Names 18
Type Names 20
Class Names 20
Interface Names 22
Method Names 23
Variable Names 25
Field Names 27
Parameter Names 28
Constant Names 29
4. Documentation Conventions
31
Comment Types 32
Documentation Comments 36
Comment Style 38
Comment Content 49
Internal Comments 52
5. Programming Conventions
57
Type Safety 64
Statements and Expressions 66
Construction 70
Exception Handling 72
Assertions 75
Concurrency 79
Synchronization 80
Efficiency 85
6. Packaging Conventions
89
Summary
95
Glossary
105
Bibliography
119
Index
123

5
Preface
AT ROGUE WAVE, we sell C++ and Java software components. We have always
included source code with our products. Customers often browse through the code to get
a feeling, not just for how it works, but for how to write good software. As a result, we
have always felt pressure—maybe more pressure than most companies—to have good,
consistent style throughout our source code.
As the company grew, making sure programmers were all following the same rules
became difficult. To address this, our founder and first programmer, Tom Keffer, wrote
35 pages that explained how we write C++ code at Rogue Wave. We passed the
document around and made sure new hires got a copy. It worked. When customers asked
how we maintained consistency in our coding, we told them about Tom’s ‘‘C++ Design,
Implementation, and Style Guide,” and sent them a copy. Word spread and we turned
Tom’s document into a technical report. We sent out thousands of copies and received
terrific positive feedback.
When Java came along, we decided we needed a document like the “C++ Guide.” A note
went out to our internal javadev@roguewave.com mailing list soliciting rules for Java use
that we should be using. The resulting list of rules became the first draft of the “Rogue
Wave Java Style Guide.”
As the list of rules grew, the style guide began to look more and more like a real book.
This time, we decided to publish our guide instead of simply issuing another Rogue
Wave technical report. To our amazement, the folks at Cambridge University Press
thought this was a great idea, and The Elements of Java Style was born.
One of the first reviewers of that original draft was Scott Ambler, current president of
Ronin International (www.ronin-intl.com). Scott liked the idea of the book and suggested
we check out the coding standards for Java he’d been distributing on the Web. We liked
his standards a lot and decided we should work as a team. The result of combining
Scott’s standards and the Rogue Wave style document is this book.
Audience
We wrote this book for anyone writing Java code, but especially for programmers who
are writing Java as part of a team. For a team to be effective, everyone must be able to
read and understand everyone else’s code. Having consistent style conventions is a good
first step!
We assume you already know the basics of Java and object-oriented programming.
剩余90页未读,继续阅读

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论8