Slides for Houston iPhone Developers' Meetup (April 2012)


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Slides for Houston iPhone Developers' Meetup (April 2012)

  1. 1. Caring About YourObjective-C Code Quality Longyi Qi April 17, 2012 1
  2. 2. • Graduate Student Computer Science, University of Houston Advisor: Dr. Venkat Subramaniam• Mobile and Web Developer ChaiONE• @longyiqi 2
  3. 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. 4. Code Quality (1/3)Programs should be written for people toread, and only incidentally for machines toexecute. 4
  5. 5. Code Quality (2/3)Image Source: 5
  6. 6. Code Quality (3/3)Quality is a measurement of how well thesoftware is designed and implemented.Who cares? 6
  7. 7. First Law of Programming• Lowering quality lengthens development time.• Agile development is a long-term gain• Keep codebase healthy 7
  8. 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. 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. 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. 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. 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. 13. Code Smells• Code smells are symptoms that indicate deeper problems in the source code. 13
  14. 14. Code Smell Samples• Duplicated code• Constant if statement• Unreachable code• Long method• High cyclomatic complexity• … 14
  15. 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
  16. 16. Code Analysis• Code reviews• Pair programming• Static code analysis 16
  17. 17. Static Code Analysis• Examines the source code and identifies the problems without running the program. 17
  18. 18. Static Code Analysis Tools• Observe source code, match against predefined error patterns, and indicate potential errors.• Objective-C Static Code Analysis Tools – Clang Static Analyzer – JetBrains AppCode – OCLint 18
  19. 19. Clang Static Analyzer• Apple LLVM compiler infrastructure team•• Xcode IDE integration 19
  20. 20. Clang Static Analyzer Demo 20
  21. 21. JetBrains AppCode• On-the-fly code analysis• Code inspection• 21
  22. 22. AppCode Demo 22
  23. 23. OCLint• Improve quality• Reduce defects• 23
  24. 24. OCLint Demo 24
  25. 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. 26. Ultimate Goal of Refactoring Code• Simplicity• Clarity• Brevity• Humanity--- William Zinsser, On Writing Well 26
  27. 27. Refactoring Demo 27
  28. 28. Questions? 28
  29. 29. OCLint Future Work• Accuracy and false positive• Better code quality inspections• Extended rules• Compatibility• Performance• User experiences• IDE integrations 29
  30. 30. Thank You!• Contact OCLint Project @oclint_project• Contact Longyi Qi @longyiqi 30