Author(s): Steve McConnell
Edition: 2nd Edition
Publisher: Microsoft Press
Year: 2004
Language: English
Pages: 952
Cover......Page 1
Copyright......Page 0
Further Praise for Code Complete......Page 4
Contents at a Glance......Page 7
Table of Contents......Page 9
Who Should Read This Book?......Page 19
Where Else Can You Find This Information?......Page 20
Key Benefits of This Handbook......Page 21
Why This Handbook Was Written......Page 23
Author Note......Page 25
Acknowledgments......Page 27
Checklists......Page 29
Tables......Page 31
Figures......Page 33
Part I: Laying the Foundation......Page 38
1.1 What Is Software Construction?......Page 40
1.2 Why Is Software Construction Important?......Page 43
Key Points......Page 45
2.1 The Importance of Metaphors......Page 46
2.2 How to Use Software Metaphors......Page 48
2.3 Common Software Metaphors......Page 50
Additional Resources......Page 57
Key Points......Page 58
Chapter 3: Measure Twice, Cut Once: Upstream Prerequisites......Page 60
3.1 Importance of Prerequisites......Page 61
3.2 Determine the Kind of Software You’re Working On......Page 68
3.3 Problem-Definition Prerequisite......Page 73
3.4 Requirements Prerequisite......Page 75
3.5 Architecture Prerequisite......Page 80
3.6 Amount of Time to Spend on Upstream Prerequisites......Page 92
Additional Resources......Page 93
Key Points......Page 96
4.1 Choice of Programming Language......Page 98
4.3 Your Location on the Technology Wave......Page 103
4.4 Selection of Major Construction Practices......Page 106
Key Points......Page 107
Part II: Creating High-Quality Code......Page 108
Chapter 5: Design in Construction......Page 110
5.1 Design Challenges......Page 111
5.2 Key Design Concepts......Page 114
5.3 Design Building Blocks: Heuristics......Page 124
5.4 Design Practices......Page 147
5.5 Comments on Popular Methodologies......Page 155
Additional Resources......Page 156
Key Points......Page 160
Chapter 6: Working Classes......Page 162
6.1 Class Foundations: Abstract Data Types (ADTs)......Page 163
6.2 Good Class Interfaces......Page 170
6.3 Design and Implementation Issues......Page 180
6.4 Reasons to Create a Class......Page 189
6.6 Beyond Classes: Packages......Page 193
Additional Resources......Page 196
Key Points......Page 197
Chapter 7: High-Quality Routines......Page 198
7.1 Valid Reasons to Create a Routine......Page 201
7.2 Design at the Routine Level......Page 205
7.3 Good Routine Names......Page 208
7.4 How Long Can a Routine Be?......Page 210
7.5 How to Use Routine Parameters......Page 211
7.6 Special Considerations in the Use of Functions......Page 218
7.7 Macro Routines and Inline Routines......Page 219
Key Points......Page 223
Chapter 8: Defensive Programming......Page 224
8.1 Protecting Your Program from Invalid Inputs......Page 225
8.2 Assertions......Page 226
8.3 Error-Handling Techniques......Page 231
8.4 Exceptions......Page 235
8.5 Barricade Your Program to Contain the Damage Caused by Errors......Page 240
8.6 Debugging Aids......Page 242
8.7 Determining How Much Defensive Programming to Leave in Production Code......Page 246
8.8 Being Defensive About Defensive Programming......Page 247
Additional Resources......Page 249
Key Points......Page 250
Chapter 9: The Pseudocode Programming Process......Page 252
9.1 Summary of Steps in Building Classes and Routines......Page 253
9.2 Pseudocode for Pros......Page 255
9.3 Constructing Routines by Using the PPP......Page 257
9.4 Alternatives to the PPP......Page 269
Key Points......Page 271
Part III: Variables......Page 272
Chapter 10: General Issues in Using Variables......Page 274
10.1 Data Literacy......Page 275
10.2 Making Variable Declarations Easy......Page 276
10.3 Guidelines for Initializing Variables......Page 277
10.4 Scope......Page 281
10.5 Persistence......Page 288
10.6 Binding Time......Page 289
10.7 Relationship Between Data Types and Control Structures......Page 291
10.8 Using Each Variable for Exactly One Purpose......Page 292
Key Points......Page 295
11.1 Considerations in Choosing Good Names......Page 296
11.2 Naming Specific Types of Data......Page 301
11.3 The Power of Naming Conventions......Page 307
11.4 Informal Naming Conventions......Page 309
11.5 Standardized Prefixes......Page 316
11.6 Creating Short Names That Are Readable......Page 319
11.7 Kinds of Names to Avoid......Page 322
Key Points......Page 326
Chapter 12: Fundamental Data Types......Page 328
12.1 Numbers in General......Page 329
12.2 Integers......Page 330
12.3 Floating-Point Numbers......Page 332
12.4 Characters and Strings......Page 334
12.5 Boolean Variables......Page 338
12.6 Enumerated Types......Page 340
12.7 Named Constants......Page 344
12.8 Arrays......Page 347
12.9 Creating Your Own Types (Type Aliasing)......Page 348
Key Points......Page 355
13.1 Structures......Page 356
13.2 Pointers......Page 360
13.3 Global Data......Page 372
Additional Resources......Page 380
Key Points......Page 381
Part IV: Statements......Page 382
14.1 Statements That Must Be in a Specific Order......Page 384
14.2 Statements Whose Order Doesn’t Matter......Page 388
Key Points......Page 390
15.1 if Statements......Page 392
15.2 case Statements......Page 398
Key Points......Page 403
16.1 Selecting the Kind of Loop......Page 404
16.2 Controlling the Loop......Page 410
16.3 Creating Loops Easily—From the Inside Out......Page 422
16.4 Correspondence Between Loops and Arrays......Page 424
Key Points......Page 426
17.1 Multiple Returns from a Routine......Page 428
17.2 Recursion......Page 430
17.3 goto......Page 435
Additional Resources......Page 445
Key Points......Page 447
18.1 General Considerations in Using Table-Driven Methods......Page 448
18.2 Direct Access Tables......Page 450
18.3 Indexed Access Tables......Page 462
18.4 Stair-Step Access Tables......Page 463
18.5 Other Examples of Table Lookups......Page 466
Key Points......Page 467
19.1 Boolean Expressions......Page 468
19.2 Compound Statements (Blocks)......Page 480
19.3 Null Statements......Page 481
19.4 Taming Dangerously Deep Nesting......Page 482
19.5 A Programming Foundation: Structured Programming......Page 491
19.6 Control Structures and Complexity......Page 493
Key Points......Page 497
Part V: Code Improvements......Page 498
20.1 Characteristics of Software Quality......Page 500
20.2 Techniques for Improving Software Quality......Page 503
20.3 Relative Effectiveness of Quality Techniques......Page 506
20.4 When to Do Quality Assurance......Page 510
20.5 The General Principle of Software Quality......Page 511
Additional Resources......Page 513
Key Points......Page 514
Chapter 21: Collaborative Construction......Page 516
21.1 Overview of Collaborative Development Practices......Page 517
21.2 Pair Programming......Page 520
21.3 Formal Inspections......Page 522
21.4 Other Kinds of Collaborative Development Practices......Page 529
21.5 Comparison of Collaborative Construction Techniques......Page 532
Additional Resources......Page 533
Key Points......Page 534
Chapter 22: Developer Testing......Page 536
22.1 Role of Developer Testing in Software Quality......Page 537
22.2 Recommended Approach to Developer Testing......Page 540
22.3 Bag of Testing Tricks......Page 542
22.4 Typical Errors......Page 554
22.5 Test-Support Tools......Page 560
22.6 Improving Your Testing......Page 565
22.7 Keeping Test Records......Page 566
Additional Resources......Page 567
Key Points......Page 570
23.1 Overview of Debugging Issues......Page 572
23.2 Finding a Defect......Page 577
23.3 Fixing a Defect......Page 587
23.4 Psychological Considerations in Debugging......Page 591
23.5 Debugging Tools—Obvious and Not-So-Obvious......Page 593
Additional Resources......Page 598
Key Points......Page 599
Chapter 24: Refactoring......Page 600
24.1 Kinds of Software Evolution......Page 601
24.2 Introduction to Refactoring......Page 602
23.3 Specific Refactorings......Page 608
23.4 Refactoring Safely......Page 616
23.5 Refactoring Strategies......Page 619
Key Points......Page 622
Chapter 25: Code-Tuning Strategies......Page 624
25.1 Performance Overview......Page 625
25.2 Introduction to Code Tuning......Page 628
25.3 Kinds of Fat and Molasses......Page 634
25.4 Measurement......Page 640
25.5 Iteration......Page 642
Additional Resources......Page 643
Key Points......Page 645
Chapter 26: Code-Tuning Techniques......Page 646
26.1 Logic......Page 647
26.2 Loops......Page 653
26.3 Data Transformations......Page 661
26.4 Expressions......Page 667
26.5 Routines......Page 676
26.6 Recoding in a Low-Level Language......Page 677
26.7 The More Things Change, the More They Stay the Same......Page 680
Additional Resources......Page 681
Key Points......Page 682
Part VI: System Considerations......Page 684
Chapter 27: How Program Size Affects Construction......Page 686
27.1 Communication and Size......Page 687
27.3 Effect of Project Size on Errors......Page 688
27.4 Effect of Project Size on Productivity......Page 690
27.5 Effect of Project Size on Development Activities......Page 691
Additional Resources......Page 695
Key Points......Page 696
Chapter 28: Managing Construction......Page 698
28.1 Encouraging Good Coding......Page 699
28.2 Configuration Management......Page 701
28.3 Estimating a Construction Schedule......Page 708
28.4 Measurement......Page 714
28.5 Treating Programmers as People......Page 717
28.6 Managing Your Manager......Page 723
Additional Resources on Managing Construction......Page 724
Key Points......Page 725
29.1 Importance of the Integration Approach......Page 726
29.2 Integration Frequency—Phased or Incremental?......Page 728
29.3 Incremental Integration Strategies......Page 731
29.4 Daily Build and Smoke Test......Page 739
Additional Resources......Page 744
Key Points......Page 745
Chapter 30: Programming Tools......Page 746
30.2 Source-Code Tools......Page 747
30.3 Executable-Code Tools......Page 753
30.4 Tool-Oriented Environments......Page 757
30.5 Building Your Own Programming Tools......Page 758
30.6 Tool Fantasyland......Page 759
Additional Resources......Page 761
Key Points......Page 762
Part VII: Software Craftsmanship......Page 764
Chapter 31: Layout and Style......Page 766
31.1 Layout Fundamentals......Page 767
31.2 Layout Techniques......Page 773
31.3 Layout Styles......Page 775
31.4 Laying Out Control Structures......Page 782
31.5 Laying Out Individual Statements......Page 790
31.6 Laying Out Comments......Page 800
31.7 Laying Out Routines......Page 803
31.8 Laying Out Classes......Page 805
Additional Resources......Page 811
Key Points......Page 812
32.1 External Documentation......Page 814
32.2 Programming Style as Documentation......Page 815
32.3 To Comment or Not to Comment......Page 818
32.4 Keys to Effective Comments......Page 822
32.5 Commenting Techniques......Page 829
32.6 IEEE Standards......Page 850
Additional Resources......Page 852
Key Points......Page 854
Chapter 33: Personal Character......Page 856
33.1 Isn’t Personal Character Off the Topic?......Page 857
33.2 Intelligence and Humility......Page 858
33.3 Curiosity......Page 859
33.4 Intellectual Honesty......Page 863
33.5 Communication and Cooperation......Page 865
33.6 Creativity and Discipline......Page 866
33.8 Characteristics That Don’t Matter As Much As You Might Think......Page 867
3.9 Habits......Page 870
Additional Resources......Page 871
Key Points......Page 872
34.1 Conquer Complexity......Page 874
34.2 Pick Your Process......Page 876
34.3 Write Programs for People First, Computers Second......Page 878
34.4 Program into Your Language, Not in It......Page 880
34.5 Focus Your Attention with the Help of Conventions......Page 881
34.6 Program in Terms of the Problem Domain......Page 882
34.7 Watch for Falling Rocks......Page 885
34.8 Iterate, Repeatedly, Again and Again......Page 887
34.9 Thou Shalt Rend Software and Religion Asunder......Page 888
Key Points......Page 890
Chapter 35: Where to Find More Information......Page 892
35.1 Information About Software Construction......Page 893
35.2 Topics Beyond Construction......Page 894
35.3 Periodicals......Page 896
35.4 A Software Developer’s Reading Plan......Page 897
35.5 Joining a Professional Organization......Page 899
Bibliography......Page 900
Index......Page 922
About the Author......Page 952