Contents at a Glance
Part I Laying the Foundation
1 Welcome to Software Construction 3
2 Metaphors for a Richer Understanding of Software Development 9
3 Measure Twice, Cut Once: Upstream Prerequisites 23
4 Key Construction Decisions 61
Part II Creating High-Quality Code
5 Design in Construction 73
6 Working Classes 125
7 High-Quality Routines 161
8 Defensive Programming 187
9 The Pseudocode Programming Process 215
Part III Variables
10 General Issues in Using Variables 237
11 The Power of Variable Names 259
12 Fundamental Data Types 291
13 Unusual Data Types 319
Part IV Statements
14 Organizing Straight-Line Code 347
15 Using Conditionals 355
16 Controlling Loops 367
17 Unusual Control Structures 391
18 Table-Driven Methods 411
19 General Control Issues 431
Part v Code Improvements
20 The Software-Quality Landscape 463
21 Collaborative Construction 479
22 Developer Testing 499
23 Debugging 535
24 Refactoring 563
25 Code-Tuning Strategies 587
26 Code-Tuning Techniques 609
Part vi System Considerations
27 How Program Size Affects Construction 649
28 Managing Construction 661
29 Integration 689
30 Programming Tools 709
Part vii Software Craftsmanship
31 Layout and Style 729
32 Self-Documenting Code 777
33 Personal Character 819
34 Themes in Software Craftsmanship 837
35 Where to Find More Information 855
Table of Contents
Preface xix
Acknowledgments xxvii
List of Checklists xxix
List of Tables xxxi
List of Figures xxxiii
Part I Laying the Foundation
1 Welcome to Software Construction 3
1.1 What Is Software Construction? 3
1.2 Why Is Software Construction Important? 6
1.3 How to Read This Book 8
2 Metaphors for a Richer Understanding of Software Development 9
2.1 The Importance of Metaphors 9
2.2 How to Use Software Metaphors 11
2.3 Common Software Metaphors 13
3 Measure Twice, Cut Once: Upstream Prerequisites 23
3.1 Importance of Prerequisites 24
3.2 Determine the Kind of Software You're Working On 31
3.3 Problem-Definition Prerequisite 36
3.4 Requirements Prerequisite 38
3.5 Architecture Prerequisite 43
3.6 Amount of Time to Spend on Upstream Prerequisites 55
4 Key Construction Decisions 61
4.1 Choice of Programming Language 61
4.2 Programming Conventions 66
4.3 Your Location on the Technology Wave 66
4.4
Selection of Major Construction Practices
69
Part II Creating High-Quality Code
5 Design in Construction 73
5.1 Design Challenges 74
5.2 Key Design Concepts 77
5.3 Design Building Blocks: Heuristics 87
5.4 Design Practices 110
5.5 Comments on Popular Methodologies 118
6 Working Classes 125
6.1 Class Foundations: Abstract Data Types (ADTs) 126
6.2 Good Class Interfaces 133
6.3 Design and Implementation Issues 143
6.4 Reasons to Create a Class 152
6.5 Language-Specific Issues 156
6.6 Beyond Classes: Packages 156
7 High-Quality Routines 161
7.1 Valid Reasons to Create a Routine 164
7.2 Design at the Routine Level 168
7.3 Good Routine Names 171
7.4 How Long Can a Routine Be? 173
7.5 How to Use Routine Parameters 174
7.6 Special Considerations in the Use of Functions 181
7.7 Macro Routines and Inline Routines 182
8 Defensive Programming 187
8.1 Protecting Your Program from Invalid Inputs 188
8.2 Assertions 189
8.3 Error-Handling Techniques 194
8.4 Exceptions 198
8.5 Barricade Your Program to Contain the Damage Caused by Errors 203
8.6 Debugging Aids 205
8.7 Determining How Much Defensive Programming to Leave in
Production Code 209
8.8 Being Defensive About Defensive Programming 210
9 The Pseudocode Programming Process 215
9.1 Summary of Steps in Building Classes and Routines 216
9.2 Pseudocode for Pros 218
9.3 Constructing Routines by Using the PPP 220
9.4 Alternatives to the PPP 232
Part ill Variables
10 General Issues in Using Variables 237
10.1 Data Literacy 238
10.2 Making Variable Declarations Easy 239
10.3 Guidelines for Initializing Variables 240
10.4 Scope 244
10.5 Persistence 251
10.6 Binding Time 252
10.7 Relationship Between Data Types and Control Structures 254
10.8 Using Each Variable for Exactly One Purpose 255
11 The Power of Variable Names 259
11.1 Considerations in Choosing Good Names 259
11.2 Naming Specific Types of Data 264
11.3 The Power of Naming Conventions 270
11.4 Informal Naming Conventions 272
11.5 Standardized Prefixes 279
11.6 Creating Short Names That Are Readable 282
11.7 Kinds of Names to Avoid 285
12 Fundamental Data Types 291
12.1 Numbers in General 292
12.2 Integers 293
12.3 Floating-Point Numbers 295
12.4 Characters and Strings 297
12.5 Boolean Variables 301
12.6 Enumerated Types 303
12.7 Named Constants 307
12.8 Arrays 310
12.9 Creating Your Own Types (Type Aliasing) 311