高品質軟體的基本動作 101 + 102 for NUU
-
Upload
su-jan -
Category
Engineering
-
view
50 -
download
6
Transcript of 高品質軟體的基本動作 101 + 102 for NUU
![Page 1: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/1.jpg)
⾼高品質軟體的基本動作- 如何寫 "好的" 程式
Guidelines in How to Create High Quality Code
bookjan
⾃自由軟體鑄造場 蘇展2015/04/15
Code Complete 101 + 102
![Page 2: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/2.jpg)
bookjan
Linkedin:https://www.linkedin.com/in/bookjan E-mail:[email protected]
TEL: (02) 2788-3799 ext. 1478
![Page 3: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/3.jpg)
In This Talk• We will discuss
• How to use Code Complete
• What is high code quality
• How to create high quality code
• Basic concepts of Software Construction
• We will not discuss
• Part VI - Software Craftsmanship
• Detail of any programing language
• Detail of how to deal with code
• Any useful tools
![Page 4: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/4.jpg)
Agenda
1. What is High Quality Code?
2. Variables (Good and Bad Examples)
3. Statements (Good and Bad Examples)
4. Self-Documenting code
5. How to create High Quality Code?
![Page 5: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/5.jpg)
Before we start…
![Page 6: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/6.jpg)
Have you ever thought…?
• What are others’ code doing?
• Why others’ code looks like so dirty?
• How to improve/create more readable and
High quality code?
• and more…?
![Page 7: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/7.jpg)
Have you ever thought…?
•看不懂別⼈人的 Code 在做什麼?
•為什麼別⼈人寫的 Code 很凌亂?
•如何寫出 “品質好”, “可讀性⾼高” 的 Code?
• Or more…?
![Page 8: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/8.jpg)
Here’s your answer.
![Page 9: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/9.jpg)
Guidance Code Complete 2nd
If you are… • Junior Developer
• Chapter 11, 18
• Senior Developer • Chapter 4~9
• Project Manager • Chapter 2, 33
• Standard Maker • Chapter 32
![Page 10: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/10.jpg)
Guidance Code Complete 2nd
If you are… • Junior Developer
• Chapter 11, 18
• Senior Developer • Chapter 4~9
• Project Manager • Chapter 2, 33
• Standard Maker • Chapter 32
THE
REFEERENCE
BOOK
![Page 11: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/11.jpg)
Guidance Code Complete 2nd
THE
REFEERENCE
BOOK
![Page 12: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/12.jpg)
• Complete software-construction reference • Ready-to-use checklists • Larger perspective on software development • Absence of hype • Concepts applicable to most common language • Numerous code examples • Access to other sources of information
THE
REFEERENCE
BOOK
Key Benefits of This Handbook
![Page 13: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/13.jpg)
Agenda
1. What is High Quality Code?
2. Variables (Good and Bad Examples)
3. Statements (Good and Bad Examples)
4. Self-Documenting Code
5. How to create High Quality Code?
6. Tips to improve Code Quality
![Page 14: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/14.jpg)
What is High Quality Code?
![Page 15: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/15.jpg)
Software Quality?
![Page 16: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/16.jpg)
Software Quality
External• Correctness • Usability • Efficiency • Reliability • Integrity • Adaptability • Accuracy • Robustness
Internal• Maintainability
• Flexibility
• Portability
• Reusability
• Readability
• Testability
• Understandability
![Page 17: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/17.jpg)
This talk, we focus on
Code Quality
![Page 18: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/18.jpg)
Software Quality
External• Correctness • Usability • Efficiency • Reliability • Integrity • Adaptability • Accuracy • Robustness
Internal• Maintainability
• Flexibility
• Portability
• Reusability
• Readability
• Testability
• Understandability
![Page 19: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/19.jpg)
Code Quality
Understandability Maintainability
Flexibility
PortabilityReusability
Readability
Testability
![Page 20: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/20.jpg)
Code Quality
Flexibility
PortabilityReusability
Testability
Self-documenting
![Page 21: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/21.jpg)
Self-documenting
Code QualityConstruction
![Page 22: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/22.jpg)
Self-documenting
Code QualityConstruction
![Page 23: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/23.jpg)
Self-documenting
Code QualityConstruction
![Page 24: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/24.jpg)
Agenda
1. What is High Quality Code?
2. Variables (Good and Bad Examples)
3. Statements (Good and Bad Examples)
4. Self-Documenting Code
5. How to create High Quality Code?
![Page 25: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/25.jpg)
VariablesGood and Bad Examples
Code Complete 2nd Part III Variables
![Page 26: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/26.jpg)
VariablesGood and Bad Examples
Code Complete 2nd Part III Variables
Good Bad
![Page 27: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/27.jpg)
Making Variable Declarations Easy
• Turn off implicit declarations
• Declare all variables
• Use naming conventions
• Check variable names
Chapter 10
![Page 28: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/28.jpg)
Initializing Variables
Chapter 10
![Page 29: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/29.jpg)
Initializing Variables
Chapter 10
![Page 30: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/30.jpg)
Keep Variables “Live” for as Short a Time as Possible
Chapter 10
![Page 31: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/31.jpg)
Group related statements
Chapter 10
![Page 32: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/32.jpg)
Group related statements
Chapter 10
![Page 33: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/33.jpg)
Use each variable for one purpose only
Chapter 10
![Page 34: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/34.jpg)
Use each variable for one purpose only
Chapter 10
![Page 35: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/35.jpg)
Considerations in Choosing Good Names
Chapter 11
![Page 36: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/36.jpg)
Chapter 11
![Page 37: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/37.jpg)
Naming Loop Indexes
Chapter 11
![Page 38: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/38.jpg)
Naming Loop Indexes
Chapter 11
![Page 39: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/39.jpg)
Naming Loop Indexes
Chapter 11
![Page 40: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/40.jpg)
Naming Status Variables
Chapter 11Chapter 11
![Page 41: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/41.jpg)
Naming Status Variables
Chapter 11
![Page 42: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/42.jpg)
Naming Temporary Variables
Chapter 11
![Page 43: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/43.jpg)
Naming Temporary Variables
Chapter 11
![Page 44: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/44.jpg)
Kinds of Names to Avoid
• Avoid misleading names or abbreviations • e.g. FALSE, TRUE
• Avoid names with similar meanings • e.g. Input and inputValue;
recordNum and numRecords; fileNumber and fileIndex
• Avoid variables with different meanings but similar names
• Bad: clientRecs and clientReps • Better: clientRecords and clientReports
• Avoid names that sound similar, such as wrap and rap
Chapter 11
![Page 45: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/45.jpg)
Kinds of Names to Avoid
Chapter 11
• Avoid numerals in names • Avoid file1 and file2, or total1 and total2
• Avoid misspelled words in names • Avoid misspelling highlight as hilite • Was it highlite? hilite? hilight? hilit? jai-a-lai-t? Who
knows?
• Avoid words that are commonly misspelled in English
• e.g. Absense, acummulate, acsend, calender, concieve, defferred, definate, independance, occassionally
![Page 46: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/46.jpg)
Kinds of Names to Avoid
Chapter 11
• Don’t differentiate variable names solely by capitalization
• Names are unique • Avoid to use frd for fired,
FRD for final review duty, and Frd for full revenue disbursal.
• Avoid multiple natural languages • Avoid “color” or “colour” and “check” or “cheque”
• Avoid the names of standard types, variables, and routines
![Page 47: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/47.jpg)
Kinds of Names to Avoid
Chapter 11
• Don’t use names that are totally unrelated to what the variables represent
• Bad: margaret and pookie. Who know? • Better: boyfriend, wife, and favoriteBeer are superior!
• Avoid names containing hard-to-read characters
![Page 48: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/48.jpg)
Avoid “magic numbers”
Chapter 12
![Page 49: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/49.jpg)
Avoid “magic numbers”
Chapter 12
![Page 50: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/50.jpg)
Boolean Variables
Chapter 12
![Page 51: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/51.jpg)
Boolean Variables
Chapter 12
![Page 52: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/52.jpg)
Boolean Variables
Chapter 12
![Page 53: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/53.jpg)
Boolean Variables
Chapter 12
![Page 54: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/54.jpg)
Use enumerated types for readability
Chapter 12
![Page 55: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/55.jpg)
Use enumerated types for readability
Chapter 12
![Page 56: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/56.jpg)
Avoid literals, even “safe” ones
Chapter 12Chapter 12
![Page 57: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/57.jpg)
Avoid literals, even “safe” ones
Chapter 12Chapter 12
![Page 58: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/58.jpg)
Avoid literals, even “safe” ones
Chapter 12Chapter 12
![Page 59: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/59.jpg)
Avoid literals, even “safe” ones
Chapter 12
![Page 60: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/60.jpg)
Use structures to clarify data relationships
Chapter 12
![Page 61: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/61.jpg)
Use structures to clarify data relationships
Chapter 12
![Page 62: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/62.jpg)
Agenda
1. What is High Quality Code?
2. Variables (Good and Bad Examples)
3. Statements (Good and Bad Examples)
4. Self-Documenting Code
5. How to create High Quality Code?
![Page 63: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/63.jpg)
StatementsGood and Bad Examples
Code Complete 2nd Part IV – Statements
Good Bad
![Page 64: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/64.jpg)
Making Code Read from Top to Bottom
Chapter 12
![Page 65: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/65.jpg)
Making Code Read from Top to Bottom
Chapter 12
![Page 66: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/66.jpg)
Grouping Related Statements
Chapter 12
![Page 67: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/67.jpg)
Chapter 15
Follow the if clause with a meaningful statement
Chapter 12
![Page 68: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/68.jpg)
Chapter 15
Follow the if clause with a meaningful statement
Chapter 12
![Page 69: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/69.jpg)
Chapter 15
Follow the if clause with a meaningful statement
![Page 70: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/70.jpg)
Don’t make up phony variables to be able to use the case statement
Chapter 15
![Page 71: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/71.jpg)
Don’t make up phony variables to be able to use the case statement
Chapter 15
![Page 72: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/72.jpg)
In C++ and Java, avoid dropping through the end of a case statement
Chapter 15
![Page 73: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/73.jpg)
73
In C++, clearly and unmistakably identify flow-throughs at the end of a case statement
![Page 74: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/74.jpg)
Abnormal Loop-With-Exit Loops
Chapter 16
![Page 75: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/75.jpg)
Don’t monkey with the loop index of a for loop to make the loop terminate
Chapter 16
![Page 76: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/76.jpg)
Use meaningful variable names to make nested loops readable
Chapter 16
![Page 77: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/77.jpg)
Use meaningful variable names to make nested loops readable
Chapter 16
![Page 78: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/78.jpg)
Don’t use recursion for factorials or Fibonacci numbers
Chapter 17
![Page 79: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/79.jpg)
Don’t use recursion for factorials or Fibonacci numbers
Chapter 17
![Page 80: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/80.jpg)
Using true and false for Boolean Tests
Chapter 19
![Page 81: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/81.jpg)
Using true and false for Boolean Tests
Chapter 19
![Page 82: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/82.jpg)
Using true and false for Boolean Tests
Chapter 19
![Page 83: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/83.jpg)
Agenda
1. What is High Quality Code?
2. Variables (Good and Bad Examples)
3. Statements (Good and Bad Examples)
4. Self-Documenting Code
5. How to create High Quality Code?
![Page 84: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/84.jpg)
Self-Documenting CodeGood and Bad Examples
Code Complete 2nd Part VII
Good Bad
![Page 85: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/85.jpg)
Programming Style as Documentation
Chapter 32
![Page 86: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/86.jpg)
Programming Style as Documentation
Chapter 32
![Page 87: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/87.jpg)
Commenting Style - Hard to Maintain
Chapter 32
![Page 88: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/88.jpg)
Commenting Style - Easy to Maintain
Chapter 32
![Page 89: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/89.jpg)
Endline Comment
Chapter 32
![Page 90: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/90.jpg)
Endline Comment
Chapter 32
![Page 91: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/91.jpg)
Good Comment & Good Code
Chapter 32
![Page 92: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/92.jpg)
Good Comment & Good Code
Chapter 32
![Page 93: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/93.jpg)
Don’t comment tricky code, rewrite it
Chapter 32
![Page 94: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/94.jpg)
Commenting Routines
Chapter 32
![Page 95: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/95.jpg)
Commenting Routines - input and output
Chapter 32
![Page 96: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/96.jpg)
Agenda
1. What is High Quality Code?
2. Variables (Good and Bad Examples)
3. Statements (Good and Bad Examples)
4. Self-Documenting Code
5. How to create High Quality Code?
![Page 97: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/97.jpg)
How to create High Quality Code?
Code Complete 2nd Part II – Creating High-Quality Code
![Page 98: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/98.jpg)
Before we start…
Let’s talk about Software Construction first.
![Page 99: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/99.jpg)
What Is Software Construction?
http://www.newhealthguide.org/images/10421225/mental%20retardation.jpg
![Page 100: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/100.jpg)
Software Construction Activities
100
![Page 101: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/101.jpg)
This book focuses on…
101
![Page 102: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/102.jpg)
Specific Tasks in Construction• Verifying that the groundwork has been laid so
that construction can proceed successfully
102
![Page 103: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/103.jpg)
Specific Tasks in Construction• Verifying that the groundwork has been laid so
that construction can proceed successfully • Determining how your code will be tested
103
![Page 104: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/104.jpg)
Specific Tasks in Construction• Verifying that the groundwork has been laid so
that construction can proceed successfully • Determining how your code will be tested • Designing and writing classes and routines
104
![Page 105: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/105.jpg)
Specific Tasks in Construction• Verifying that the groundwork has been laid so
that construction can proceed successfully • Determining how your code will be tested • Designing and writing classes and routines • Creating and naming variables and named
constants
105
![Page 106: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/106.jpg)
Specific Tasks in Construction• Verifying that the groundwork has been laid so
that construction can proceed successfully • Determining how your code will be tested • Designing and writing classes and routines • Creating and naming variables and named
constants • Selecting control structures and organizing
blocks of statements
106
![Page 107: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/107.jpg)
Specific Tasks in Construction• Verifying that the groundwork has been laid so
that construction can proceed successfully • Determining how your code will be tested • Designing and writing classes and routines • Creating and naming variables and named
constants • Selecting control structures and organizing
blocks of statements • Unit testing, integration testing, and
debugging your own code 107
![Page 108: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/108.jpg)
Specific Tasks in Construction• Reviewing other team members’ low-level
designs and code and having them review yours
108
![Page 109: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/109.jpg)
Specific Tasks in Construction• Reviewing other team members’ low-level
designs and code and having them review yours
• Polishing code by carefully formatting and commenting it
109
![Page 110: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/110.jpg)
Specific Tasks in Construction• Reviewing other team members’ low-level
designs and code and having them review yours
• Polishing code by carefully formatting and commenting it
• Integrating software components that were created separately
110
![Page 111: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/111.jpg)
Specific Tasks in Construction• Reviewing other team members’ low-level
designs and code and having them review yours
• Polishing code by carefully formatting and commenting it
• Integrating software components that were created separately
• Tuning code to make it faster and use fewer resources
111
![Page 112: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/112.jpg)
Why Software Construction
Is So Important?
![Page 113: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/113.jpg)
Here’s Why• Construction is a large part of software
development
113
![Page 114: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/114.jpg)
Here’s Why• Construction is a large part of software
development • Construction is the central activity in software
development
114
![Page 115: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/115.jpg)
Here’s Why• Construction is a large part of software
development • Construction is the central activity in software
development • With a focus on construction, the individual
programmer’s productivity can improve enormously
115
![Page 116: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/116.jpg)
Here’s Why• Construction is a large part of software
development • Construction is the central activity in software
development • With a focus on construction, the individual
programmer’s productivity can improve enormously
• Construction’s product, the source code, is often the only accurate description of the software
116
![Page 117: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/117.jpg)
Here’s Why• Construction is a large part of software
development • Construction is the central activity in software
development • With a focus on construction, the individual
programmer’s productivity can improve enormously
• Construction’s product, the source code, is often the only accurate description of the software
• Construction is the only activity that’s guaranteed to be done
117
![Page 118: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/118.jpg)
OK! I got it…
Should I need to care about before the construction?
![Page 119: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/119.jpg)
Most Important of All - Problem Definition
119
![Page 120: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/120.jpg)
Wrong Problem Definition
120
![Page 121: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/121.jpg)
Right Problem Without Good Requirements
121
![Page 122: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/122.jpg)
Right Problem Without Good Software Architecture
122
![Page 123: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/123.jpg)
123
DVCS(Distributed Version Control System )
Made by Linus Torvalds for Linux
He spent about 10 DAYS to commit kernel code using git…
He said that it all depended on getting the basic ideas right…
I'd seen the problems others had, and I wanted to avoid doing.
http://www.linux.com/news/featured-blogs/185-jennifer-cloer/821541-10-years-of-git-an-interview-with-git-creator-linus-torvalds
![Page 124: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/124.jpg)
One more thing…
![Page 125: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/125.jpg)
Construction is an…
Iterative process
Chapter 5
![Page 126: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/126.jpg)
126
https://www.flickr.com/photos/j_sherman/6128691125/
Design Mental Picture
![Page 127: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/127.jpg)
Design is …
• A Wicked Problem
• A Sloppy Process (Even If it Produces a Tidy Result)
• About Tradeoffs and Priorities
• A Heuristic Process
• And more…
Chapter 5
![Page 128: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/128.jpg)
Desirable Characteristics of a Design
• Minimal complexity
• Ease of maintenance
• Loose coupling • Extensibility
• Reusability
• High fan-in
• Low-to-medium fan-out
• Portability
• Leanness
• Stratification
• Standard techniques
Chapter 5
![Page 129: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/129.jpg)
Form Consistent Abstractions
Chapter 5
![Page 130: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/130.jpg)
Software’s Primary Technical Imperative: Managing
Complexity
Accidental and Essential Difficulties
Importance of Managing Complexity
Chapter 5
![Page 131: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/131.jpg)
Hide Secrets (Information Hiding)
A good class interface
is like the tip of an
iceberg, leaving most
of the class unexposed.
Chapter 5
![Page 132: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/132.jpg)
Hide Secrets (Information Hiding)
Hiding ComplexityHiding Sources
![Page 133: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/133.jpg)
Value of Information Hiding
Chapter 5
• Asking “What does this class need to hide?”
If you can put a Function or Data into the class’s public interface without compromising its secrets, do. Otherwise, don’t.
![Page 134: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/134.jpg)
Encapsulate Implementation Details
Chapter 5
![Page 135: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/135.jpg)
Levels of Design1.Software system
2.Subsystem/packages
3.Classes within packages
4.Data and routines within
classes
5.Internal routine design
Chapter 5
![Page 136: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/136.jpg)
Top-Down and Bottom-Up Design Approaches
Argument for Bottom Up
Argument for Top Down
Chapter 5
![Page 137: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/137.jpg)
Top-Down and Bottom-Up Design Approaches
Argument for Bottom UpArgument for Top Down
No Argument, Really
Chapter 5
![Page 138: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/138.jpg)
Design also is an…
Iterative process
Chapter 5
![Page 139: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/139.jpg)
How to create High Quality Code?
Code Complete 2nd Part II – Creating High-Quality Code
Let’s beginning~
![Page 140: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/140.jpg)
140
Packages & Classes & Functions
Package
Class
add() contains() equals() getBounds2d() … getSize() isEmpty() …
Functions
![Page 141: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/141.jpg)
Reasons to Create a Class
• Model real-world objects
• Model abstract objects
• Reduce complexity
• Isolate complexity
• Hide implementation details
• Limit effects of changes
• Hide global data
• Streamline parameter passing
• Make central points of control
• Facilitate reusable code
• Plan for a family of programs
• Package related operations
• Accomplish a specific refactoring
Chapter 6
![Page 142: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/142.jpg)
Class Foundations: Abstract Data Types (ADTs)
Picture from: Auto Transport Company ScamsChapter 6
![Page 143: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/143.jpg)
Example of the Need for an ADT
Chapter 6
If you need to change to a 12-point font size
![Page 144: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/144.jpg)
If you need to change to a 12-point font size
Chapter 6
Benefits of Using ADT
![Page 145: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/145.jpg)
• Avoid creating god classes
• Eliminate irrelevant classes
• Avoid classes named after verbs
Classes to Avoid
Chapter 6
![Page 146: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/146.jpg)
Class Interface - Poor Abstraction
Chapter 6
![Page 147: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/147.jpg)
Class Interface - Good Abstraction
Chapter 6
![Page 148: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/148.jpg)
Class Interface - Better Abstraction
Chapter 6
![Page 149: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/149.jpg)
Class Interface - Mixed Levels of Abstraction
Chapter 6
![Page 150: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/150.jpg)
Class Interface - Consistent Levels of Abstraction
Chapter 6
![Page 151: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/151.jpg)
Exposing Class’s Implementation Details
Chapter 6
![Page 152: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/152.jpg)
Hiding Class’s Implementation Details
Chapter 6
![Page 153: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/153.jpg)
What is the routines?
Chapter 6
![Page 154: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/154.jpg)
What is the routines?
Chapter 6
Routines = Functions
![Page 155: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/155.jpg)
Valid Reasons to Create a Routine
• Reduce complexity
• Intermediate, understandable abstraction
• Avoid duplicate code
• Support subclassing
• Hide sequences
• Hide pointer operations
• Improve portability
• Simplify complicated Boolean tests
• Improve performance
• To ensure all routines are small?
Chapter 6
![Page 156: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/156.jpg)
Operations That Seem Too Simple to Put Into Routines
Chapter 7Chapter 7
![Page 157: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/157.jpg)
Operations That Seem Too Simple to Put Into Routines
Chapter 7Chapter 7
![Page 158: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/158.jpg)
Operations That Seem Too Simple to Put Into Routines
Chapter 7Chapter 7
![Page 159: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/159.jpg)
Operations That Seem Too Simple to Put Into Routines
Chapter 7
![Page 160: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/160.jpg)
Good Routine Names
• Describe everything the routine does • Bad: ComputeReportTotals() • Silly Names: ComputeReportTotalsAndOpenOutputFile()
• Avoid meaningless, vague, or wishy-washy verbs • Bad: HandleCalculation(), PerformServices(),OutputUser(),
ProcessInput(), and DealWithOutput()… • HandleOutput() → FormatAndPrintOutput()
• Make names of routines as long as necessary
Chapter 7
![Page 161: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/161.jpg)
Good Routine Names• Don’t differentiate routine names solely by number
• Bad: Part1, Part2, OutputUser0, OutputUser1, and OutputUser2
• To name a function, use a description of the return value
• e.g. cos(), customerId.Next(), printer.IsReady(), and pen.CurrentColor()
• To name a procedure, use a strong verb followed by an object
• e.g. PrintDocument(), CalcMonthlyRevenues(), CheckOrderlnfo(), and
RepaginateDocument()
Chapter 7
![Page 162: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/162.jpg)
Good Routine Names
• Establish conventions for common operations
• e.g. employee.id.Get(), dependent.GetId(), supervisor(), candidate.id()
• Use opposites precisely
Chapter 7
![Page 163: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/163.jpg)
How Long Can a Routine Be?
100
200Less then 200 lines is better.
Chapter 7
![Page 164: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/164.jpg)
Don’t use routine parameters as working variables
Chapter 7
![Page 165: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/165.jpg)
Don’t use routine parameters as working variables
Chapter 7
![Page 166: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/166.jpg)
Limit the number of a routine’s parameters to about
Seven
Chapter 7
7
![Page 167: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/167.jpg)
What is Pseudocode?
Chapter 5
Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm.
![Page 168: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/168.jpg)
Pseudocode Principles
Chapter 5
![Page 169: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/169.jpg)
Pseudocode Programming Process: Classes
Chapter 5
![Page 170: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/170.jpg)
Pseudocode Programming Process: Routines
Chapter 5
![Page 171: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/171.jpg)
Constructing Routines by Using the PPP
Chapter 5
Design the routine.
Code the routine.
Check the code.
Clean up loose ends.
Repeat as needed.
1
23
4
5
![Page 172: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/172.jpg)
Code the Routine
Chapter 5
1
2
3
4
5
![Page 173: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/173.jpg)
Write the routine declaration
Chapter 5
1
![Page 174: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/174.jpg)
Writing the First and Last Statements Around Pseudocode
Chapter 5
2
Chapter 5
![Page 175: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/175.jpg)
Turn the Pseudocode into High-level comments
Chapter 5Chapter 5
2
![Page 176: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/176.jpg)
Chapter 5
The code for each comment has been filled in from here down.
3
![Page 177: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/177.jpg)
Chapter 15
Example of a Complete Routines Overview
Routine Header
Routine Interface
The code for each comment has been filled in from here down.
The last paragraph of Routine
![Page 178: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/178.jpg)
Self-documenting
Code QualityConstruction
![Page 179: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/179.jpg)
Thank You!
![Page 180: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/180.jpg)
Q & A
![Page 181: 高品質軟體的基本動作 101 + 102 for NUU](https://reader030.fdocuments.net/reader030/viewer/2022020116/55a862951a28abdc628b48c1/html5/thumbnails/181.jpg)
本簡報授權聲明
除另有聲明外,本簡報內容採⽤用 Creative Commons「姓名標⽰示 - ⾮非商業性」台灣 3.0 版授權條款。 歡迎⾮非商業⺫⽬目的的重製、散布或修改本簡報的內容,但請標明:(1)原作者姓名;(2)本簡報標題;(3)演講⽇日期。 簡報中所取⽤用的圖形創作乃截取⾃自網際網路,僅供演講者於⾃自由軟體推廣演講時主張合理使⽤用,請讀者不得對其再⾏行取⽤用,除⾮非您本⾝身⾃自忖亦符合主張合理使⽤用之情狀,且⾃自負相關法律責任。
THANK YOU Website: www.openfoundry.org Phone: 02-2788-3799 ext. 1478