Upload
klabcyscorpions-techblog
View
423
Download
2
Embed Size (px)
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.
Citation preview
Code ReviewCris Uy
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
Goal
• To spot and fix defects early in the process
• Helps to maintain a level of consistency in design and implementation
• Better shared understanding of the code base as team members learn from each other
Types of Code Review
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
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
Tips for Developers during Code Review
• The primary reviewer is the author. • You
• Create a checklist for yourself of the things that the code reviews tend to focus on
• Understand and accept that you will make mistakes
• No matter how much your knowledge is, someone else will always know more than you
• Don’t rewrite code without consultation
• The only constant thing in this world is change
• Fight for what you believe, but gracefully accept defeat
• Please note that review meetings are not problem solving meetings
• Helping to maintain the coding standards
Tips for Reviewers during Code Review
• Critique code instead of people – be kind to the coder, not to the code
• Treat people who know less than you with respect, deference and patience
• Ask questions rather than make statements
• Avoid the why questions
• Remember to praise
• Make sure you have good coding standards to reference
• Remember that there is often more than one way to approach a solution
• You should not rush through a code review – but also, you need to do it promptly
• Review fewer than 200 – 400 lines of code at a time
General Guidelines
• Is the code following coding guidelines and naming conventions?
• Reviewer should have a reference for coding guidelines and conventions
• Are all compiler warnings fixed?
• Are there leftover code for testing/development?
• 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
Control Structures
• Check for infinite loops?
• Does the loop iterate the correct number of times?
Error Handling
• Does the code check for null exceptions?
• Does the code check for array out of bounds exceptions?
Resource Leaks
• Are all allocated memory freed?
• Do all classes perform thorough cleanup on its destructor (dealloc)?
• Are all notification observers, event listeners, message receivers or gesture recognizers removed when not needed?
• Does the code accurately keep track of reference counting?
Performance
• Are you using blocking system calls when performance is involved?
• Will the same data be reloaded often?
• Will caching data improve performance?
• Is a large number of big objects being created and destroyed in a small amount of time?
• Will reusing objects improve performance?
• Was this optimization really needed?
Maintainability and Reusability
• Is the code using magic numbers and magic strings?
• Does the code comply with the DRY (Don’t Repeat Yourself) principle?
Thank you!