Pragmatic Programmer
Estimating (提升专业素养)
DRY rule - Repeat or Reuse (提炼经验)
Control Structures & Complexity (简洁就是美)
Table Driven (善于运用算法)
Design for CHANGE (完善设计、争取主动)
Refactoring (追求卓越,勇于改进)
Automation (一切都要自动化)
Resource
Who is working for you (找个巨人的肩膀)
Accessories for you
Process and Methods
Process enhances confidence
Thought Disorder(最容易欺骗的人是自己)
Conceptual Blockbusting
Career anchors
How to define the VALUE (价值不等式)
Professionalism
3. Agenda
Pragmatic Programmer
Estimating (提升专业素养)
DRY rule - Repeat or Reuse (提炼经验)
Control Structures & Complexity (简洁就是美)
Table Driven (善于运用算法)
Design for CHANGE (完善设计、争取主动)
Refactoring (追求卓越,勇于改进)
Automation (一切都要自动化)
Resource
Who is working for you (找个巨人的肩膀)
Accessories for you
Process and Methods
Process enhances confidence
Thought Disorder(最容易欺骗的人是自己)
Conceptual Blockbusting
Career anchors
How to define the VALUE (价值不等式)
Professionalism
Q&A
3
9. Control Structure
Need a loop that executes a specified number of times
To use a for loop
If change the index value of a for loop force it to
terminate, use a while loop instead.
Else to use a while loop.
Reference:
Write Solid Code, Maguire, 1993
9
10. Controlling the loop
Major principles
简化循环体相关连的因素(所引用的变量或数据),判
断或结束条件一定要简单。
循环也是另类的子程序,可以视其为Black box.
Entering the Loop
Put initialization code directly before the loop
Use while ( true ) for infinite loops
Don’t use a for loop when a while loop is more
appropriate
10
12. Processing the middle of the loop
Use { and } to enclose the statements in a loop
Avoid empty loops
Keep loop-housekeeping chores at either the beginning or the
end of the loop
Make each loop perform only one function
可以做,但不代表应该做。正确的代码不代表是好的代码!
12
13. Exiting the loop
Existing loops early
According to an article in Software Engineering Notes, the software error that 7
brought down the New York City phone systems for 9 hours on January 15, 8
1990 was due to an extra break statement (SEN 1990)
break的分散代表逻辑上的分散,会带来维护上的风险!大量的return出现在函数
体,多个深层嵌套,变量中途转为它用,多处理重复功能相近的代码,都预示者
开发者的逻辑可能已经出现问题!
13
14. Checking endpoints
Willingness to perform this kind of check is a key
difference between efficient and inefficient
programmers.
How to check
Hand calculations
Mental simulations
Calculate by Excel
What are benefits?
You understand how your code works rather than
guessing about it!
14
15. How long should a loop be
Make your loops short enough to view all at once.
Limit nesting to three levels
Move loop innards of long loops into routines
Make long loops especially clear.
Single exit.
15
17. Control Structure and Complexity
The control flow is at least one of the largest
contributors to complexity, if not the largest.
HP apply McCabe’s complexity metric, that is helpful
to improve coding quality.
General guideline for reducing complexity
Improve your own mental juggling abilities
You can decrease the complexity of your programs and
the amount of concentration required to understand
them.
17
18. How to measure complexity
Techniques for counting the decision points in a routine
Start with 1 for the straight pat through the routine
Add 1 for each of the following keywords, or their equivalents: if
while repeat for and or
Add 1 for each case in a case statement
Exercise
if ( ( (status = Success ) and done) or
( not done and ( numLines >= maxLines ) ) )
then …
*Cyclomatic Complexity 18
19. Table Driven
Advantage:
Simplify codes and enhance the performance
Enhance the system customization capability.
Weakness:
Not everyone know it well, it may bring extra efforts.
Virtually anything you can select with logic
statements, you can select with tables instead.
19
22. Example
static unsigned int chooseDPI(unsigned int
original_dpi, int datatype)
{
int i, d, diff, k;
static Support_Mode support_mode[] = {
{4, 0}, //support two modes
{150, 2},
{300, 3}, //300DPI with color and gray
{600, 3}, //600DPI with color and gray
{1200, 2}
};
diff = -1;
k = 1;
for (i = 1; i <= support_mode[0].dpi; ++i)
{
if (support_mode[i].support_mode & datatype)
{
d = abs(support_mode[i].dpi - original_dpi);
if (diff == -1)
{
diff = d;
k = i;
}
else
{
if (d <= diff)
{
diff = d;
k = i;
}
else
break;
}
}
}
return support_mode[k].dpi;
}
22
43. Two critical issues
DLL building failed
Customer get corrupted release package
Side-effect for function parameter with default value
43
44. Enhance the process with tool
DLL building failed
Create one script to check version number for each DLL
Customer get corrupted release package while testing
Provides the MD5 Checksum
Side-effect for function parameter with default value
Define in coding rule
44
53. Study Plan for Programmer
Level 10
Code Complete 2nd Edition, Steve McConnell
Programming Pearls 2nd Edition, Jon Bentley
Refactoring, Martin Fowler
UML Distilled, Martin Fowler
Applying UML & Patterns 2nd Ed, Craig Larman
Testing Computer Software, Cem Kaner et all
Conceptual Blockbusting, James Adams
Software Creativity, Robert Glass
Software Project Survival Guide, Steve McConnell
Level 11
Mastering the Requirements Process, Robertson and Robertson
Software Requirements, Karl Wiegers
"Manager's Handbook for Software Development", NASA Goddard Space Flight Center
Writing Efficient Programs, John Bentley
Writing Solid Code, Steve Maquire
Software Implementation, Michael Marcotty
More Programming Pearls, John Bentley
A Practitioner's Guide to Software Testing Design, Lee Copeland
Rapid Development, Steve McConnell
Level 12
Design Patterns, Erich Gamma et all
Object Oriented Software Construction, Bertrand Meyer
Object Oriented Analysis and Design, Grady Booch
Software Architecture in Practice, Bass et all
"Manager's Handbook for Software Development", NASA Goddard Space Flight Center
"Software Measurement Guidebook", NASA Goddard Space Flight Center
53
54. Level 10
Rapid Development, Steve McConnell
"Manager's Handbook for Software Development", NASA Goddard Space Flight Center
Mastering the Requirements Process, Robertson and Robertson
Software Requirements, Karl Wiegers
Level 11
Agile and Iterative Development: A Managers Guide, Craig Larman
Balancing Agility with Discipline, Barry Boehm and Richard Turner
Creating a Software Engineering Culture, Karl Wiegers
Peopleware, DeMarco and Lister
A Practitioner's Guide to Software Test Design, Lee Copeland
"Recommended Approach to Software Development, NASA Goddard Space Flight Center
"Software Measurement Guidebook", NASA Goddard Space Flight Center
Level 12
Agile Modeling, Scott Adams
Requirements by Collaboration: Workshops for Defining Needs, Ellen Gottesdiener
Scenarios, Stories, Use Cases, Ian Alexander
Writing Effective Use Cases, Alistair Cockburn
Peer Reviews, Karl Wiegers
The Logic of Failure: Recognizing and Avoiding Error in Complex Situations, Domer Dietrich
Customer Oriented Software Quality Assurance, Frank Ginac
Code Complete 2nd Edition, Steve McConnell
Applying UML & Patterns 2nd Ed, Craig Larman
Study Plan for Manager
54