code review for ios

56
Code Review Cris Uy

Upload: klabcyscorpions-techblog

Post on 22-Nov-2014

422 views

Category:

Education


2 download

DESCRIPTION

Hi I’m Cris, iOS Developer in KLabCyscorpions. In this post, I want to share with you my presentation on Code Review guidelines for iOS. But, what is Code Review? According to Wikipedia: “Code Review is systematic examination (often known as peer review) of computer source code. It is intended to find and fix mistakes overlooked in the initial development phase, improving both the overall quality of software and the developers’ skills. Reviews are done in various forms such as pair programming, informal walkthroughs, and formal inspections.” Want to review code? Then First things first! For you to review code effectively, you need the basic know-how of reviewing code as both the developer and the reviewer. These slides will give some guidelines on how to think in both these roles when reviewing code.

TRANSCRIPT

Page 1: Code Review for iOS

Code ReviewCris Uy

Page 2: Code Review for iOS

Agenda• Goals• Types of Code Review• Tips for Developers during Code Review• Tips for Reviewers during Code Review• General Guidelines• Control Structures• Error Handling• Resource Leaks• Performance• Maintainability and Reusability

Page 3: Code Review for iOS

Goal

Page 4: Code Review for iOS

• To spot and fix defects early in the process

Page 5: Code Review for iOS

• Helps to maintain a level of consistency in design and implementation

Page 6: Code Review for iOS

• Better shared understanding of the code base as team members learn from each other

Page 7: Code Review for iOS

Types of Code Review

Page 8: Code Review for iOS

Formal Code Review

• Involves software developers meeting together and reviewing relevant code line by line many times taking the opportunity to analyze printed copies of the materials

Page 9: Code Review for iOS

Peer Code Review

• Can be done over the shoulder where the reviewer looks over the author’s shoulder as the other goes through the code

• Or can be done via email or version control system like Git and online conference

Page 10: Code Review for iOS

Tips for Developers during Code Review

Page 11: Code Review for iOS

• The primary reviewer is the author. • You

Page 12: Code Review for iOS

• Create a checklist for yourself of the things that the code reviews tend to focus on

Page 13: Code Review for iOS

• Understand and accept that you will make mistakes

Page 14: Code Review for iOS

• No matter how much your knowledge is, someone else will always know more than you

Page 15: Code Review for iOS

• Don’t rewrite code without consultation

Page 16: Code Review for iOS

• The only constant thing in this world is change

Page 17: Code Review for iOS

• Fight for what you believe, but gracefully accept defeat

Page 18: Code Review for iOS

• Please note that review meetings are not problem solving meetings

Page 19: Code Review for iOS

• Helping to maintain the coding standards

Page 20: Code Review for iOS

Tips for Reviewers during Code Review

Page 21: Code Review for iOS

• Critique code instead of people – be kind to the coder, not to the code

Page 22: Code Review for iOS

• Treat people who know less than you with respect, deference and patience

Page 23: Code Review for iOS

• Ask questions rather than make statements

Page 24: Code Review for iOS

• Avoid the why questions

Page 25: Code Review for iOS

• Remember to praise

Page 26: Code Review for iOS

• Make sure you have good coding standards to reference

Page 27: Code Review for iOS

• Remember that there is often more than one way to approach a solution

Page 28: Code Review for iOS

• You should not rush through a code review – but also, you need to do it promptly

Page 29: Code Review for iOS

• Review fewer than 200 – 400 lines of code at a time

Page 30: Code Review for iOS

General Guidelines

Page 31: Code Review for iOS

• Is the code following coding guidelines and naming conventions?

• Reviewer should have a reference for coding guidelines and conventions

Page 32: Code Review for iOS

• Are all compiler warnings fixed?

Page 33: Code Review for iOS

• Are there leftover code for testing/development?

Page 34: Code Review for iOS

• Is the code complexity under the maximum allowable threshold for a given metric?

• *a class is less than 500 lines• *a method does not contain more than 15

control structures

Page 35: Code Review for iOS

Control Structures

Page 36: Code Review for iOS

• Check for infinite loops?

Page 37: Code Review for iOS

• Does the loop iterate the correct number of times?

Page 38: Code Review for iOS

Error Handling

Page 39: Code Review for iOS

• Does the code check for null exceptions?

Page 40: Code Review for iOS

• Does the code check for array out of bounds exceptions?

Page 41: Code Review for iOS

Resource Leaks

Page 42: Code Review for iOS

• Are all allocated memory freed?

Page 43: Code Review for iOS

• Do all classes perform thorough cleanup on its destructor (dealloc)?

Page 44: Code Review for iOS

• Are all notification observers, event listeners, message receivers or gesture recognizers removed when not needed?

Page 45: Code Review for iOS

• Does the code accurately keep track of reference counting?

Page 46: Code Review for iOS

Performance

Page 47: Code Review for iOS

• Are you using blocking system calls when performance is involved?

Page 48: Code Review for iOS

• Will the same data be reloaded often?

Page 49: Code Review for iOS

• Will caching data improve performance?

Page 50: Code Review for iOS

• Is a large number of big objects being created and destroyed in a small amount of time?

Page 51: Code Review for iOS

• Will reusing objects improve performance?

Page 52: Code Review for iOS

• Was this optimization really needed?

Page 53: Code Review for iOS

Maintainability and Reusability

Page 54: Code Review for iOS

• Is the code using magic numbers and magic strings?

Page 55: Code Review for iOS

• Does the code comply with the DRY (Don’t Repeat Yourself) principle?

Page 56: Code Review for iOS

Thank you!