1.3 How to Read This Book Metaphors for a Richer Understanding of Software Development [2] 2.1 The Importance of Metaphors 2.2 How to Use Software Metaphors 2.3 Common Software Metaphors
Trang 1FRONT MATTER
Preface [Preface]
Who Should Read This Book?
Where Else Can You Find This Information?
Key Benefits of This Handbook
Why This Handbook Was Written
Book Website
Author Note
Notes about the Second Edition [new]
Acknowledgments [n/a]
LAYING THE FOUNDATION
Welcome to Software Construction [1]
1.1 What Is Software Construction?
1.2 Why Is Software Construction Important?
1.3 How to Read This Book
Metaphors for a Richer Understanding of Software Development [2]
2.1 The Importance of Metaphors
2.2 How to Use Software Metaphors
2.3 Common Software Metaphors
Measure Twice, Cut Once: Upstream Prerequisites [3]
3.6 Amount of Time to Spend on Upstream Prerequisites
Key Construction Decisions [3+new material]
4.1 Choice of Programming Language
4.2 Programming Conventions
4.3 Your Location on the Technology Wave
4.4 Selection of Major Construction Practices
CREATING HIGH QUALITY CODE
Design in Construction [mostly new material, some from 7]
5.1 Design Challenges
5.2 Key Design Concepts
5.3 Design Building Blocks: Heuristics
Trang 25.5 Comments on Popular Methodologies
Working Classes [mostly new material, a little from 6]
6.1 Class Foundations: Abstract Data Types (ADTs)
6.2 Good Class Interfaces
6.3 Design and Implementation Issues
6.4 Reasons to Create a Class
6.5 Language-Specific Issues
6.6 Beyond Classes: Packages
High-Quality Routines [5]
7.1 Valid Reasons to Create a Routine
7.2 Design at the Routine Level
7.3 Good Routine Names
7.4 How Long Can a Routine Be?
7.5 How to Use Routine Parameters
7.6 Special Considerations in the Use of Functions
7.7 Macro Routines and Inline Routines
Defensive Programming [5.6 + new material]
8.1 Protecting Your Program From Invalid Inputs
8.7 Determining How Much Defensive Programming to Leave in Production Code
8.8 Being Defensive About Defensive Programming
The Pseudocode Programming Process [4+new material]
9.1 Summary of Steps in Building Classes and Routines
9.2 Pseudocode for Pros
9.3 Constructing Routines Using the PPP
9.4 Alternatives to the PPP
VARIABLES
General Issues in Using Variables [10]
10.1 Data Literacy
10.2 Making Variable Declarations Easy
10.3 Guidelines for Initializing Variables
Trang 3The Power of Variable Names [9]
11.1 Considerations in Choosing Good Names
11.2 Naming Specific Types of Data
11.3 The Power of Naming Conventions
11.4 Informal Naming Conventions
11.5 Standardized Prefixes
11.6 Creating Short Names That Are Readable
11.7 Kinds of Names to Avoid
Fundamental Data Types [11]
12.9 Creating Your Own Types
Unusual Data Types [11.9, 10.6]
13.1 Structures
13.2 Pointers
13.3 Global Data
STATEMENTS
Organizing Straight-Line Code [13]
14.1 Statements That Must Be in a Specific Order
14.2 Statements Whose Order Doesn’t Matter
Using Conditionals [14]
15.1 if Statements
15.2 case Statements
Controlling Loops [15]
16.1 Selecting the Kind of Loop
16.2 Controlling the Loop
16.3 Creating Loops Easily—from the Inside Out
16.4 Correspondence Between Loops and Arrays
Unusual Control Structures [16]
17.1 Multiple Returns from a Routine
17.2 Recursion
17.3 goto
17.4 Perspective on Unusual Control Structures
Trang 4Table-Driven Methods [12.2]
18.1 General Considerations in Using Table-Driven Methods
18.2 Direct Access Tables
18.3 Indexed Access Tables
18.4 Stair-Step Access Tables
18.5 Other Examples of Table Lookups
General Control Issues [17]
19.1 Boolean Expressions
19.2 Compound Statements (Blocks)
19.3 Null Statements
19.4 Taming Dangerously Deep Nesting
19.5 A Programming Foundation: Structured Programming
19.6 Control Structures and Complexity
CODE IMPROVEMENTS
The Software-Quality Landscape [23]
20.1 Characteristics of Software Quality
20.2 Techniques for Improving Software Quality
20.3 Relative Effectiveness of Quality Techniques
20.4 When to Do Quality Assurance
20.5 The General Principle of Software Quality
22.1 Role of Developer Testing in Software Quality
22.2 Recommended Approach to Developer Testing
22.3 Bag of Testing Tricks
22.4 Typical Errors
22.5 Test-Support Tools
22.6 Improving Your Testing
22.7 Keeping Test Records
Debugging [26]
23.1 Overview of Debugging Issues
23.2 Finding a Defect
23.3 Fixing a Defect
23.4 Psychological Considerations in Debugging
23.5 Debugging Tools—Obvious and Not-So-Obvious
Trang 524.1 Kinds of Software Evolution
25.2 Introduction to Code Tuning
25.3 Kinds of Fat and Molasses
How Program Size Affects Construction [21]
27.1 Communication and Size
27.2 Range of Project Sizes
27.3 Effect of Project Size on Errors
27.4 Effect of Project Size on Productivity
27.5 Effect of Project Size on Development Activities
Managing Construction [22, and some from 27.4]
28.1 Encouraging Good Coding
28.2 Configuration Management
28.3 Estimating a Construction Schedule
28.4 Measurement
28.5 Treating Programmers as People
28.6 Managing Your Manager
Integration [27]
29.1 Importance of the Integration Approach
29.2 Integration Frequency—Phased or Incremental?
29.3 Incremental Integration Strategies
Trang 631.4 Laying Out Control Structures
31.5 Laying Out Individual Statements
31.6 Laying Out Comments
31.7 Laying Out Routines
31.8 Laying Out Classes
Self-Documenting Code [19]
32.1 External Documentation
32.2 Programming Style as Documentation
32.3 To Comment or Not to Comment
32.4 Keys to Effective Comments
32.5 Commenting Techniques
Personal Character [31]
33.1 Isn’t Personal Character Off the Topic?
33.2 Intelligence and Humility
33.3 Curiosity
33.4 Intellectual Honesty
33.5 Communication and Cooperation
33.6 Creativity and Discipline
34.2 Pick Your Process
34.3 Write Programs for People First, Computers Second
34.4 Program Into Your Language, Not In It
34.5 Focus Your Attention with the Help of Conventions
Trang 734.8 Iterate, Repeatedly, Again and Again
34.9 Thou Shalt Rend Software and Religion Asunder
Where to Find More Information [33]
35.1 Information About Software Construction
35.2 Topics Beyond Construction
35.3 Periodicals
35.4 A Software Developer’s Reading Plan
35.5 Joining a Professional Organization
Trang 8Notes about the Second
Trang 9Does the second edition discuss object-oriented programming?
Trang 10“The word “incremental” has never achieved the
Trang 11Has anything moved backwards?
Trang 14share what they have learned Consequently, programmers may have difficulty
Programming language books
Magazine articles
Other software books
Technology references
Trang 15Complete software-construction reference
Trang 16The examples are in multiple languages because mastering more than one
Trang 17Discussions about construction have also been hobbled by the suggestion that
Trang 18No Comparable Book Is Available
When art critics get
together they talk about
Form and Structure and
Meaning When artists
get together they talk
about where you can buy
cheap turpentine
—Pablo Picasso
CC2E.COM/ 1234
Trang 21RequirementsDevelopment
Software
Testing
DetailedDesign
Coding andDebuggingConstruction
Planning
Integration
CorrectiveMaintenance
UnitTesting
IntegrationTesting
Trang 22Detailed Design
Integration
Unit Testing
Integration Testing
Requirements Development
Problem Definition
Software Architecture
System Testing
Corrective Maintenance
Construction Planning
Coding and Debugging
Trang 23For an even fuller list of construction activities, look through the chapter titles in
details on the relationship
between project size and the
percentage of time consumed
by construction, see “Activity
Proportions and Size” in
Section 27.5
Trang 24With a focus on construction, the individual programmer’s productivity
data on variations among
programmers, see “Individual
Variation” in Section 28.5
KEY POINT
Trang 27The history of science is full of discoveries based on exploiting the power of
Trang 28Aristotelians could not discover because their model led them to look at different
reduced Learning and
education are quicker In
effect, metaphors are a
way of internalizing and
Trang 29In fact, many models that have been replaced by better models are still useful
software, see “Design is a
Heuristic Process” in Section
5.1
Trang 30instructions directly A heuristic tells you how to discover the instructions for
Trang 31favorite hunting dog to enjoy a “literate program” the way you would a good
Plan to throw one away;
you will, anyhow
— Fred Brooks
If you plan to throw one
away, you will throw
away two
— Craig Zerouni
Trang 32But extending the metaphor of “writing” software to a plan to throw one away is
maintenance, see the chapter
“On the Origins of Designer
Intuition” in Rethinking
Systems Analysis and Design
(Weinberg 1988)
Trang 34produces real output You add a little bit of code at a time until you have a fully
Trang 37Careful planning doesn’t necessarily mean exhaustive planning or over-planning
Trang 38The analogy could be extended in a variety of other directions, which is why the
FURTHER READING For
some good comments about
extending the construction
metaphor, see “What
Supports the Roof?” (Starr
design, see Section 5.3,
“Design Building Blocks:
Heuristics.”
CC2E.COM/ 0285
Trang 39Kuhn, Thomas S The Structure of Scientific Revolutions, 3d Ed., Chicago: The
Trang 41jewel, you have to start with a diamond in the rough If you start with plans for a
Pay-ing attention to quality is also
the best way to improve
pro-ductivity For details, see
Section 20.5, “The General
Principle of Software
Qual-ity.”
KEY POINT
Trang 42Since construction is in the middle of a software project, by the time you get to
The methodology used
should be based on choice
of the latest and best, and
not based on ignorance
It should also be laced
liberally with the old and
development program that
that cultivates these skills,
see Chapter 16 of
Profes-sional Software Development
(McConnell 2004)
Trang 43do upstream work, the recommendation to “do more upstream work” sounds like
FURTHER READING For
many entertaining variations
on this theme, read Gerald
Weinberg’s classic, The
Psy-chology of Computer
Pro-gramming (Weinberg 1998)
Trang 44Second, you can pretend to be coding when you’re not Put an old program
Trang 45to find out what they really want But that’s cheaper than building the wrong
Trang 46site, map out sewer and electrical lines, and so on If the builder doesn’t prepare
quire-tecture
Archi-struc-tion
Con-System Test
Re-lease
Trang 47We Have Learned About Fighting Defects” (Shull et al 2002), and Balancing Agility
Introduced
RequirementsArchitectureConstruction
Trang 48Which of these statements are self-fulfilling prophecies?
Business Systems
Mission-Critical Systems
Embedded Critical Systems
Trang 49Life-Typical Good Practices
Kind of Software
Business Systems
Mission-Critical Systems
Embedded Critical Systems
Life-Typical plications
ap-Internet site Intranet site Inventory manage-ment
Games Management infor-mation systems Payroll system
Embedded software Games
Internet site Packaged software Software tools Web services
Avionics software Embedded software Medical devices Operating systems Packaged software
Lifecycle models
Agile development (extreme program-ming, scrum, time-box development, and so on) Evolutionary proto-typing
Staged delivery Evolutionary deliv-ery
Spiral development
Staged delivery Spiral development Evolutionary deliv-ery
Planning and management
Incremental project planning
As-needed test and
QA planning Informal change con-trol
Basic up-front ning
plan-Basic test planning As-needed QA plan-ning
Formal change trol
con-Extensive up-front planning
Extensive test ning
Extensive QA ning
plan-Rigorous change control
ments
Require-Informal ments specification
requiSemi-formal quirements specifica-tion
re-As-needed ments reviews
require-Formal requirements specification Formal requirements inspections
Design Design and coding
are combined
Architectural design Informal detailed design
As-needed design reviews
Architectural design Formal architecture inspections Formal detailed de-sign
Formal detailed sign inspections Construction Pair programming or
de-individual coding Informal check-in procedure or no check-in procedure
Pair programming or individual coding Informal check-in procedure As-needed code re-views
Pair programming or individual coding Formal check-in pro-cedure
Formal code tions
Trang 50inspec-Typical Good Practices
Kind of Software
Business Systems
Mission-Critical Systems
Embedded Critical Systems
develop-Little or no testing by
a separate test group
Developers test their own code
Test-first ment
develop-Separate testing group
Developers test their own code
Test-first ment
develop-Separate testing group
Separate QA group Deployment Informal deployment
procedure
Formal deployment procedure
Formal deployment procedure
Project tion status
comple-Cost of Work
Cost of Rework
Cost of Work
Cost of Rework
Trang 51comple-Cost of Work
Cost of Rework
Cost of Work
Cost of Rework
10% $100,000 $20,000 $100,000 $10,000 20% $100,000 $20,000 $100,000 $10,000
Trang 5230% $100,000 $20,000 $100,000 $10,000 40% $100,000 $20,000 $100,000 $10,000 50% $100,000 $20,000 $100,000 $10,000 60% $100,000 $20,000 $100,000 $10,000 70% $100,000 $20,000 $100,000 $10,000 80% $100,000 $20,000 $100,000 $10,000 90% $100,000 $20,000 $100,000 $10,000 100% $100,000 $20,000 $100,000 $10,000 End-of-Project
Trang 53The extent to which prerequisites need to be satisfied up front will vary with the
details on how to adapt your
development approach for
programs of different sizes,
see Chapter 27, “How
Pro-gram Size Affects
Construc-tion.”
Trang 54whether each specific construction prerequisite has been “prereq’d” or
FutureImprovements
If the ‘box’ is the
bound-ary of constraints and
conditions, then the trick
is to find the box Don’t
think outside the box—
find the box.”
—Andy Hunt and Dave
Thomas
Trang 55The problem definition should be in user language, and the problem should be
Trang 56Explicit requirements help to ensure that the user rather than the programmer
Trang 57Requirements are like
water They’re easier to
build on when they’re
frozen
—Anon
HARD DATA
Trang 58accounts for 70 to 85 percent of the rework on a typical project (Leffingwell
details on handling changes
to design and code, see
Sec-tion 28.2, “ConfiguraSec-tion
Management.”
Trang 59is their suggesting changes so frequently that you can’t keep up Having a
FURTHER READING For
details on development
ap-proaches that support flexible
requirements, see Rapid
De-velopment (McConnell
1996)
CROSS-REFERENCE For
details on iterative
develop-ment approaches, see
“Iter-ate” in Section 5.4 and
Sec-tion 29.3, “Incremental
Inte-gration Strategies.”
CROSS-REFERENCE For
details on the differences
between formal and informal
projects (often caused by
differences in project size),
see Chapter 27, “How
Pro-gram Size Affects
Construc-tion.”
CC2E.COM/ 0323
Trang 60Are all the external hardware and software interfaces specified?
Trang 61more information on design
at all levels, see Chapters 5
through 9
KEY POINT
Trang 62details on lower-level
pro-gram design, see Chapters 5
Trang 63ganizational alternatives, the architecture provides the rationale for the system
details on different size
build-ing blocks in design, see
“Levels of Design” in Section
5.2
CROSS-REFERENCE Mini
mizing what each building
block knows about other
building blocks is a key part
of information hiding For
details, see “Hide Secrets
details on working with
vari-ables, see Chapters 10
through 13