The document discusses the importance of code quality and provides tips for improving code quality. It defines code quality as how well software is designed and implemented. It recommends code reviews, static analysis tools like Clang, AppCode, and OCLint to identify code smells and defects. It also discusses refactoring code to improve simplicity, clarity and reduce technical debt. Maintaining high code quality makes software easier to change and evolve over time.
2. • Graduate Student
Computer Science, University of Houston
Advisor: Dr. Venkat Subramaniam
• Mobile and Web Developer
ChaiONE
• http://www.longyiqi.com
lqi@longyiqi.com
@longyiqi
2
3. Why Care About Code Quality?
• We keep changing and evolving our software
based on feedback, if our code quality is poor,
it’s hard to do so.
• A high code quality is a very important aspect
that leads to a success app.
3
4. Code Quality (1/3)
Programs should be written for people to
read, and only incidentally for machines to
execute.
4
6. Code Quality (3/3)
Quality is a measurement of how well the
software is designed and implemented.
Who cares?
6
7. First Law of Programming
• Lowering quality lengthens development time.
• Agile development is a long-term gain
• Keep codebase healthy
7
8. Software Defect Reduction Top 10 List (1/2)
• Finding and fixing a software problem after delivery is
often 100 times more expensive than finding and fixing
it during the requirements and design phase
• Current software projects spend about 40 to 50 percent
of their effort on avoidable rework.
• About 80 percent of avoidable rework comes from 20
percent of the defects.
• About 80 percent of the defects come from 20 percent
of the modules, and about half the modules are defect
free.
• About 90 percent of the downtime comes from, at most,
10 percent of the defects.
8
9. Software Defect Reduction Top 10 List (2/2)
• Peer reviews catch 60 percent of the defects.
• Perspective-based reviews catch 35 percent more defects
than non directed reviews.
• Disciplined personal practices can reduce defect
introduction rates by up to 75 percent.
• All other things being equal, it costs 50 percent more per
source instruction to develop high-dependability software
products than to develop low-dependability software
products. However, the investment is more than worth it if
the project involves significant operations and maintenance
costs.
• About 40 to 50 percent of user programs contain nontrivial
defects.
9
10. Technical Debt
• All comprises in software development are
technical debts
– Don’t update dependent libraries
– Postpone code refactoring
– Write “quick and dirty” code to meet deadline
• As soon as a technical debt is owed, the
interests will incur.
10
11. Broken Window Theory
• If there is a broken window in the building,
and nobody repairs it for a while, it could
arouse the feeling of being abandoned.
• Gradually, more and more windows get
broken.
• Consequently, this type of disorder leads to
additional crimes and anti-social behaviors.
11
12. Measure Quality
• Is code simple enough?
• Is code easy to read?
• Is code easy to understand?
• Is method size small?
• Is class size small?
• Are variable names, method names, class names
meaningful?
• Is the code testable? Has tests?
• Is code following code standard? Code
convention?
12
13. Code Smells
• Code smells are symptoms that indicate deeper
problems in the source code.
13
14. Code Smell Samples
• Duplicated code
• Constant if statement
• Unreachable code
• Long method
• High cyclomatic complexity
• …
14
15. Dealing with Code Smells
• Keep an eye on it
• Indicate code that needs either refactoring or
some serious redesign
• Pay off technical debts
• Take effort to clear the air frequently
15
25. Code Refactoring
• The process of changing a software system
• Does not alter the external behavior of the
code
• Improves its internal structure
25
26. Ultimate Goal of Refactoring Code
• Simplicity
• Clarity
• Brevity
• Humanity
--- William Zinsser, On Writing Well
26