SlideShare a Scribd company logo
Improving Code Quality Through
Effective Review Process
By
Dr. Syed Hassan Amin
 The objective of code review exercise is to ensure highest
code quality.
 Quality code ensures that your code is :
 Understandable
 Extendable and easily modified with changing business
requirements
 Scalability : Covers performance, maintainability and fault
tolerance
 Reliable : Does not easily breakdown
 In this discussion, we look at commonly found problems in
code, and find ways of overcoming them.
Code Quality
 Coding Guidelines
 Understanding and Avoiding Common Coding and Design Mistakes
 Memory Leaks
 Bad smells of code
 Excessive and un-necessary API calls
 Best Practices
 Centralized Server Communication
 Following Single Responsibility Principle
 Centralized Threading
 Optimizing Use of Images in terms of file access, storage, and draw calls
 Reducing Code Complexity
 Static Code Analysis
 Profiling
Path to High Quality Code
 Coding conventions are a set of guidelines for a specific
programming language that recommend programming style,
practices and methods for each aspect of a piece program
written in this language.
 These conventions usually cover file organization, indentation,
comments, declarations, statements, white space, naming
conventions, programming practices, programming principles,
programming rules of thumb, etc.
Coding Guidelines
 Redundant Code
 Writing functions which span many pages
 Writing functions with deeply nested if’s, case's
 Writing badly typed functions
 Function names which do not reflect what the functions do
 Variable names which are meaningless
 Using processes when they are not needed
 Badly chosen data structures (Bad representations).
 Bad comments or no comments at all (always document arguments
and return value).
 Hard coded values
 Unindented code.
 Inaccessible parts of code (Dead Code)
The Most Common Mistakes
 Leads to lack of reusability
 Can lead in unforeseen results
 Example:
 Code to perform sell operation added at 21 different places.
 As a consequence, coins or virtual money being used in the
project ends up being negative in a multi threaded game.
Redundant Code
 Long functions may not always be bad
 Especially when a single algorithm is implemented
 Long functions are bad when they have too many if blocks
 Seriously consider dividing those functions
 Extremely long functions are definitely bad
 General rule of thumb is consider sub dividing your method
when more than 50 lines of code
Don’t Write Very Long Function’s
 Nested code is code containing case/if/receive statements
within other case/if/receive statements.
 It is bad programming style to write deeply nested code - the
code has a tendency to drift across the page to the right and
soon becomes unreadable.
 Try to limit most of your code to a maximum of two levels of
indentation.
 This can be achieved by dividing the code into shorter
functions.
Don't Write Deeply Nested Code
 A module should not contain more than 400 lines of
source code.
 It is better to have several small modules than one
large one.
 A module is also very long when it has too many
subroutines/functions
Don't Write
Very Large Modules
 Comments should be clear and concise and avoid
unnecessary wordiness.
 Make sure that comments are kept up to date with
the code.
 Comments should add to the understanding of the
code.
Comments
 The important things to document are:
 The purpose of the function.
 The domain of valid inputs to the function. That is, data structures
of the arguments to the functions together with their meaning.
 The domain of the output of the function. That is, all possible data
structures of the return value together with their meaning.
 If the function implements a complicated algorithm, describe it.
 The possible causes of failure and exit signals which may be
generated by exit/1, throw/1 or any non-obvious run time errors.
Note the difference between failure and returning an error.
 Any side effect of the function.
Comments About Function/Method
 Example:
%%--------------------------------------------------------
%% Function: get_server_statistics/2
%% Purpose: Get various information from a process.
%% Args: Option is normal|all.
%% Returns: A list of {Key, Value}
%% or {error, Reason} (if the process is dead)
%% Modification History:
%%--------------------------------------------------------------
Comments About Function/Method
(Cont’d)
 Never leave commented code when
submitting/committing code
 Remember the source code control system will help
you!
Do Not Comment Out Old Code –
Remove It
 Many errors go unnoticed until runtime at client site.
 Exceptions provide a powerful and flexible way to handle issues in
your code,
 Use them wisely.
 Common examples of such errors include:
 Sending messages an object doesn’t respond to
 Going out of bounds of an array
 Accessing invalid data
 File not found
 Unable to save/retrieve file on a network server because of incorrect
encodling e.g. ASCII on client side and Unicode on server side
 Losing the connection to the window server
Exception Handling
 When reviewing code, please make sure that you do not
have any segments/blocks of code where control will never
be transferred.
 Inaccessible code is also called dead code.
 Examples include a function that is never used.
 An if/else block that is never supposed to be get control
transferred to it.
 Use exception handling to cover unexpected scenarios
rather than leaving inaccessible code for end of world type
scenarios.
Inaccessible Code
 Avoid hardcoding values into the source code
 Hard coding requires the program's source code to be
changed any time the input data changes
 Constants may be put in a separate configuration file when
necessary
Avoid Hard Coded Values
 How efficient is an algorithm or piece of code?
 CPU (time) Usage
 Memory Usage
 Disk Usage
 Network Usage
 We express complexity of our algorithms using big-O
notation.
 For a problem of size N:
 a constant-time method is "order 1": O(1)
 a linear-time method is "order N": O(N)
 a quadratic-time method is "order N squared": O(N2)
Code Complexity
 In 1976, Tom McCabe published a paper arguing that code
complexity is defined by its control flow.
 It seems to be generally accepted that control flow is one of
the most useful measurements of complexity
 High complexity scores have been shown to be a strong
indicator of low reliability and frequent errors.
 The Cyclomatic Complexity computation based on Tom
McCabe's work and is defined in Steve McConnell's book,
Code Complete on page 395 :
 Start with 1 for the straight path through the routine
 Add 1 for each of the following keywords or their equivalents:
if, while, repeat, for, and, or
 Add 1 for each case in a case statement
Code Complexity(Cont’d)
 So, if we have this C# example:
 while (nextPage != true)
 {
 if ((lineCount <= linesPerPage) && (status != Status.Cancelled) &&
(morePages == true))
 {
 // ...
 }
 }

 In the code above, we start with 1 for the routine, add 1 for the while,
add 1 for the if, and add 1 for each && for a total calculated complexity
of 5.
 Anything with a greater complexity than 10 or so is an excellent
candidate for simplification and refactoring.
 Minimizing complexity is a great goal for writing high-quality,
maintainable code.
Code Complexity(Cont’d)
 Some advantages of McCabe's Cyclomatic Complexity
include:
 It is very easy to compute, as illustrated in the example
 It can be computed immediately in the development lifecycle
(which makes it Agile-friendly)
 It provides a good indicator of the ease of code maintenance
 It can help focus testing efforts
 It makes it easy to find complex code for formal review
Code Complexity(Cont’d)
 Formal code review coupled with complexity measurements
provide a very compelling technique for quality improvement,
and it is something that can easily be adopted by an Agile
team.
 So, what can you do to implement this technique for your
project?
 Find a tool that computes code metrics (specifically complexity)
for your language and toolset
 Schedule the tool so that it automatically runs and captures
metrics every day
 Use the code complexity measurement to help identify
candidates for formal code review
 Capture the results of the code review and monitor their follow-
up (too many teams forget about the follow-up)
Code Complexity(Cont’d)
 Programmers love to write loops !
 Loops can significantly increase code complexity while
decreasing code quality.
 Common mistakes to avoid in loops are :
 Memory allocations in loops
 Variable declarations in loops
 Function calls that just return constant value
Loops
 Example
 In this for loop, we are calling array count function multiple
function multiple times, although it remains fixed throughout the
execution of the loop.
for (int i = 0; i< [landPatchesArray count]; i++)
for (int j=0;………)
{
}
Alternatively
Int i=0; int j=0;
landPatchArrayCount=[landPatchesArray count];
for (i = 0; i<landPatchArrayCount; i++)
for (j=0;………)
Loops(Cont’d)
 Pay careful attention to memory allocation and deallocation.
 Always run profiler to check for memory leaks.
Memory Leaks
 Its difficult to think of applications that do not have use of
multiple threads.
 Threads are horrible:
 They tend to make behavior of your programs as
unpredictable
 As soon as you notice unpredictable behavior then you
start putting synchronized blocks around your code and
data.
 Developers just start creating threads without ever
thinking about organizing/managing their threads.
Centralized Threading Model
 Grand Central Dispatch is a mechanism for controlling
multiple threads of execution.
 It is an implementation of task parallelism based on
the thread pool pattern.
 GCD works by allowing specific tasks in a program
that can be run in parallel to be queued up for
execution and, depending on availability of
processing resources, scheduling them to execute on
any of the available processor cores[11].
Centralized Threading Model
(Cont’d)
 Centralized server communication is important because we
need to ensure consistent behavior of the system when
updating or retrieving its state from the server.
 A common mistake is to allow individual modules to update
their own state with the server.
 Example
 In one scenario, inconsistent game state udpation resulted
because of non-adherence to single responsibility principle
because many classes were managing their own
NSURLConnections, and none of the instances really do much
error handling or robust retry logic.
Centralized Server Communication
 Pay careful attention to optimizing use of Images in terms of
file access, storage, and draw calls.
 PNG and JPG formats are highly inefficient, because the data
must be parsed into bitmap form on the fly at load time.
 iOS Specific Image Formats can come to your rescue in such a
scenario
 One of the better format is pvr.ccz, which cocos2d natively
supports,
 Pvr.ccz image are faster to read from disk, and require no
parsing to load into memory.
 Use spritesheets to minimize image loading and faster
rendering through batch sprites.
Optimizing Image Use
 Static code analysis is the process of detecting errors and
defects in software's source code.
 Static analysis can be viewed as an automated code review
process.
Static Code Analysis
 Static analysis is usually poor regarding diagnosing memory
leaks and concurrency errors.
 To detect such errors you actually need to execute a part of
the program virtually. It requires extra effort and
carefulness.
 A static analysis tool warns you about odd fragments. It
means that the code can actually be quite correct.
 It is called false-positive reports.
Disadvantages of Static Code
Analysis
 Profiling is a form of dynamic program analysis that
measures, for example, the usage of memory, the usage of
particular instructions, or frequency and duration of
function calls.
 The most common use of profiling information is to aid
program optimization.
 Profiling is achieved by instrumenting either the program
source code or its binary executable form using a tool called
a profiler (or code profiler).
Profiling
 http://www.erlang.se/doc/programming_rules.shtml#REF321
41
 http://blogs.msdn.com/b/mswanson/archive/2004/06/12/1544
60.aspx
 http://en.wikipedia.org/wiki/Cyclomatic_complexity
Links

More Related Content

What's hot

Code coverage
Code coverageCode coverage
Code coverage
Return on Intelligence
 
On to code review lessons learned at microsoft
On to code review lessons learned at microsoftOn to code review lessons learned at microsoft
On to code review lessons learned at microsoft
Michaela Greiler
 
Build security into CI/CD pipelines for effective security automation on AWS ...
Build security into CI/CD pipelines for effective security automation on AWS ...Build security into CI/CD pipelines for effective security automation on AWS ...
Build security into CI/CD pipelines for effective security automation on AWS ...
Amazon Web Services
 
Track code quality with SonarQube
Track code quality with SonarQubeTrack code quality with SonarQube
Track code quality with SonarQube
Dmytro Patserkovskyi
 
Refactoring
RefactoringRefactoring
Refactoring
Artem Tabalin
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & tools
Rajesh Kumar
 
Continuous Inspection of Code Quality: SonarQube
Continuous Inspection of Code Quality: SonarQubeContinuous Inspection of Code Quality: SonarQube
Continuous Inspection of Code Quality: SonarQube
Emre Dündar
 
How to successfully grow a code review culture
How to successfully grow a code review cultureHow to successfully grow a code review culture
How to successfully grow a code review culture
Nina Zakharenko
 
Container Security
Container SecurityContainer Security
Container Security
Salman Baset
 
Container security
Container securityContainer security
Container security
Anthony Chow
 
Code Quality Lightning Talk
Code Quality Lightning TalkCode Quality Lightning Talk
Code Quality Lightning Talk
Jonathan Gregory
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
Lars Thorup
 
Code Quality Management Best Practices
Code Quality Management Best Practices Code Quality Management Best Practices
Code Quality Management Best Practices
Perforce
 
API Management - Why it matters!
API Management - Why it matters!API Management - Why it matters!
API Management - Why it matters!
Sven Bernhardt
 
Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...
Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...
Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...
Edureka!
 
Kubernetes: A Short Introduction (2019)
Kubernetes: A Short Introduction (2019)Kubernetes: A Short Introduction (2019)
Kubernetes: A Short Introduction (2019)
Megan O'Keefe
 
Kks sre book_ch1,2
Kks sre book_ch1,2Kks sre book_ch1,2
Kks sre book_ch1,2
Chris Huang
 
Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)
Chris Aniszczyk
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
Ankur Goyal
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
Lalit Kale
 

What's hot (20)

Code coverage
Code coverageCode coverage
Code coverage
 
On to code review lessons learned at microsoft
On to code review lessons learned at microsoftOn to code review lessons learned at microsoft
On to code review lessons learned at microsoft
 
Build security into CI/CD pipelines for effective security automation on AWS ...
Build security into CI/CD pipelines for effective security automation on AWS ...Build security into CI/CD pipelines for effective security automation on AWS ...
Build security into CI/CD pipelines for effective security automation on AWS ...
 
Track code quality with SonarQube
Track code quality with SonarQubeTrack code quality with SonarQube
Track code quality with SonarQube
 
Refactoring
RefactoringRefactoring
Refactoring
 
Code coverage & tools
Code coverage & toolsCode coverage & tools
Code coverage & tools
 
Continuous Inspection of Code Quality: SonarQube
Continuous Inspection of Code Quality: SonarQubeContinuous Inspection of Code Quality: SonarQube
Continuous Inspection of Code Quality: SonarQube
 
How to successfully grow a code review culture
How to successfully grow a code review cultureHow to successfully grow a code review culture
How to successfully grow a code review culture
 
Container Security
Container SecurityContainer Security
Container Security
 
Container security
Container securityContainer security
Container security
 
Code Quality Lightning Talk
Code Quality Lightning TalkCode Quality Lightning Talk
Code Quality Lightning Talk
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Code Quality Management Best Practices
Code Quality Management Best Practices Code Quality Management Best Practices
Code Quality Management Best Practices
 
API Management - Why it matters!
API Management - Why it matters!API Management - Why it matters!
API Management - Why it matters!
 
Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...
Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...
Kubernetes Networking | Kubernetes Services, Pods & Ingress Networks | Kubern...
 
Kubernetes: A Short Introduction (2019)
Kubernetes: A Short Introduction (2019)Kubernetes: A Short Introduction (2019)
Kubernetes: A Short Introduction (2019)
 
Kks sre book_ch1,2
Kks sre book_ch1,2Kks sre book_ch1,2
Kks sre book_ch1,2
 
Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)Cloud Native Landscape (CNCF and OCI)
Cloud Native Landscape (CNCF and OCI)
 
Software development best practices & coding guidelines
Software development best practices & coding guidelinesSoftware development best practices & coding guidelines
Software development best practices & coding guidelines
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
 

Viewers also liked

Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
Paul Gower
 
Code review in practice
Code review in practiceCode review in practice
Code review in practice
Edorian
 
Code quality
Code qualityCode quality
Code quality
Provectus
 
Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015
Stacy Kvernmo
 
Improving code quality using CI
Improving code quality using CIImproving code quality using CI
Improving code quality using CI
Martin de Keijzer
 
Improving code quality
Improving code qualityImproving code quality
Improving code quality
Jano Suchal
 
Effective Code Review (Or How To Alienate Your Coworkers)
Effective Code Review (Or How To Alienate Your Coworkers)Effective Code Review (Or How To Alienate Your Coworkers)
Effective Code Review (Or How To Alienate Your Coworkers)
Perforce
 
JDD Effective Code Review In Agile Teams
JDD Effective Code Review In Agile TeamsJDD Effective Code Review In Agile Teams
JDD Effective Code Review In Agile Teams
Wojciech Seliga
 
Why you should integrate peer code reviews in your software company
Why you should integrate peer code reviews in your software companyWhy you should integrate peer code reviews in your software company
Why you should integrate peer code reviews in your software company
Matts Devriendt
 
Code Review: An apple a day
Code Review: An apple a dayCode Review: An apple a day
Code Review: An apple a day
Kathryn Rotondo
 
Improving code quality with continuous integration (PHPBenelux Conference 2011)
Improving code quality with continuous integration (PHPBenelux Conference 2011)Improving code quality with continuous integration (PHPBenelux Conference 2011)
Improving code quality with continuous integration (PHPBenelux Conference 2011)
Martin de Keijzer
 
Peer Code Review: In a Nutshell
Peer Code Review: In a NutshellPeer Code Review: In a Nutshell
Peer Code Review: In a Nutshell
Atlassian
 
Code review
Code reviewCode review
Code review
Raquel Pau
 
Crucible
CrucibleCrucible
Crucible
Brian Repko
 
Code review process checklist by VINTAGE
Code review process checklist by VINTAGECode review process checklist by VINTAGE
Code review process checklist by VINTAGE
Denis Kurylenko
 
Best of tata crucible handa
Best of tata crucible   handaBest of tata crucible   handa
Best of tata crucible handajain_rohit
 
Code reviews
Code reviewsCode reviews
Code reviews
Juan Maiz
 
FishEye and Crucible Presentation
FishEye and Crucible PresentationFishEye and Crucible Presentation
FishEye and Crucible Presentation
Ellen Feaheny
 
Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptMark Daggett
 
Points.com fisheye crucible code reviews 2011
Points.com fisheye crucible code reviews 2011Points.com fisheye crucible code reviews 2011
Points.com fisheye crucible code reviews 2011
pointstechgeeks
 

Viewers also liked (20)

Code Review: How and When
Code Review: How and WhenCode Review: How and When
Code Review: How and When
 
Code review in practice
Code review in practiceCode review in practice
Code review in practice
 
Code quality
Code qualityCode quality
Code quality
 
Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015Sass Code Reviews - How one code review changed my life #SassConf2015
Sass Code Reviews - How one code review changed my life #SassConf2015
 
Improving code quality using CI
Improving code quality using CIImproving code quality using CI
Improving code quality using CI
 
Improving code quality
Improving code qualityImproving code quality
Improving code quality
 
Effective Code Review (Or How To Alienate Your Coworkers)
Effective Code Review (Or How To Alienate Your Coworkers)Effective Code Review (Or How To Alienate Your Coworkers)
Effective Code Review (Or How To Alienate Your Coworkers)
 
JDD Effective Code Review In Agile Teams
JDD Effective Code Review In Agile TeamsJDD Effective Code Review In Agile Teams
JDD Effective Code Review In Agile Teams
 
Why you should integrate peer code reviews in your software company
Why you should integrate peer code reviews in your software companyWhy you should integrate peer code reviews in your software company
Why you should integrate peer code reviews in your software company
 
Code Review: An apple a day
Code Review: An apple a dayCode Review: An apple a day
Code Review: An apple a day
 
Improving code quality with continuous integration (PHPBenelux Conference 2011)
Improving code quality with continuous integration (PHPBenelux Conference 2011)Improving code quality with continuous integration (PHPBenelux Conference 2011)
Improving code quality with continuous integration (PHPBenelux Conference 2011)
 
Peer Code Review: In a Nutshell
Peer Code Review: In a NutshellPeer Code Review: In a Nutshell
Peer Code Review: In a Nutshell
 
Code review
Code reviewCode review
Code review
 
Crucible
CrucibleCrucible
Crucible
 
Code review process checklist by VINTAGE
Code review process checklist by VINTAGECode review process checklist by VINTAGE
Code review process checklist by VINTAGE
 
Best of tata crucible handa
Best of tata crucible   handaBest of tata crucible   handa
Best of tata crucible handa
 
Code reviews
Code reviewsCode reviews
Code reviews
 
FishEye and Crucible Presentation
FishEye and Crucible PresentationFishEye and Crucible Presentation
FishEye and Crucible Presentation
 
Understanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScriptUnderstanding, measuring and improving code quality in JavaScript
Understanding, measuring and improving code quality in JavaScript
 
Points.com fisheye crucible code reviews 2011
Points.com fisheye crucible code reviews 2011Points.com fisheye crucible code reviews 2011
Points.com fisheye crucible code reviews 2011
 

Similar to Improving Code Quality Through Effective Review Process

Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codeshermiraguilar
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)Yogesh Deshpande
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
ikram_ahamed
 
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
KomalSinghGill
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
Vivek chan
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Engineering Software Lab
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
guest5de1a5
 
Qat09 presentations dxw07u
Qat09 presentations dxw07uQat09 presentations dxw07u
Qat09 presentations dxw07uShubham Sharma
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithmshccit
 
[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysis[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysis
Weverton Timoteo
 
Survelaine murillo ppt
Survelaine murillo pptSurvelaine murillo ppt
Survelaine murillo ppt
Survelaine Murillo
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
Cherimay Batallones
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis technique
Andrey Karpov
 

Similar to Improving Code Quality Through Effective Review Process (20)

Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)FPL -Part 2 ( Sem - I 2013)
FPL -Part 2 ( Sem - I 2013)
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
Parasoft .TEST, Write better C# Code Using  Data Flow Analysis Parasoft .TEST, Write better C# Code Using  Data Flow Analysis
Parasoft .TEST, Write better C# Code Using Data Flow Analysis
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Qat09 presentations dxw07u
Qat09 presentations dxw07uQat09 presentations dxw07u
Qat09 presentations dxw07u
 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
 
[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysis[Gophercon 2019] Analysing code quality with linters and static analysis
[Gophercon 2019] Analysing code quality with linters and static analysis
 
7-CodingAndUT.ppt
7-CodingAndUT.ppt7-CodingAndUT.ppt
7-CodingAndUT.ppt
 
Survelaine murillo ppt
Survelaine murillo pptSurvelaine murillo ppt
Survelaine murillo ppt
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis technique
 
Abcxyz
AbcxyzAbcxyz
Abcxyz
 

More from Dr. Syed Hassan Amin

Greenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparisonGreenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparison
Dr. Syed Hassan Amin
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
Dr. Syed Hassan Amin
 
Multitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq RecognitionMultitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq Recognition
Dr. Syed Hassan Amin
 
Understandig PCA and LDA
Understandig PCA and LDAUnderstandig PCA and LDA
Understandig PCA and LDA
Dr. Syed Hassan Amin
 
Agile Scrum Methodology
Agile Scrum MethodologyAgile Scrum Methodology
Agile Scrum Methodology
Dr. Syed Hassan Amin
 
Thin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better CodeThin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better Code
Dr. Syed Hassan Amin
 
Software Project Management Tips and Tricks
Software Project Management Tips and TricksSoftware Project Management Tips and Tricks
Software Project Management Tips and Tricks
Dr. Syed Hassan Amin
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
Dr. Syed Hassan Amin
 
Learning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve JobsLearning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve Jobs
Dr. Syed Hassan Amin
 
Understanding and Managing Technical Debt
Understanding and Managing Technical DebtUnderstanding and Managing Technical Debt
Understanding and Managing Technical Debt
Dr. Syed Hassan Amin
 
An OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq FontAn OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq FontDr. Syed Hassan Amin
 

More from Dr. Syed Hassan Amin (12)

Greenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparisonGreenplum versus redshift and actian vectorwise comparison
Greenplum versus redshift and actian vectorwise comparison
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Multitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq RecognitionMultitier holistic Approach for urdu Nastaliq Recognition
Multitier holistic Approach for urdu Nastaliq Recognition
 
Understandig PCA and LDA
Understandig PCA and LDAUnderstandig PCA and LDA
Understandig PCA and LDA
 
Agile Scrum Methodology
Agile Scrum MethodologyAgile Scrum Methodology
Agile Scrum Methodology
 
Thin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better CodeThin Controllers Fat Models - How to Write Better Code
Thin Controllers Fat Models - How to Write Better Code
 
Software Project Management Tips and Tricks
Software Project Management Tips and TricksSoftware Project Management Tips and Tricks
Software Project Management Tips and Tricks
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
Learning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve JobsLearning Technology Leadership from Steve Jobs
Learning Technology Leadership from Steve Jobs
 
Understanding and Managing Technical Debt
Understanding and Managing Technical DebtUnderstanding and Managing Technical Debt
Understanding and Managing Technical Debt
 
An OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq FontAn OCR System for recognition of Urdu text in Nastaliq Font
An OCR System for recognition of Urdu text in Nastaliq Font
 

Recently uploaded

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 

Recently uploaded (20)

Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 

Improving Code Quality Through Effective Review Process

  • 1. Improving Code Quality Through Effective Review Process By Dr. Syed Hassan Amin
  • 2.  The objective of code review exercise is to ensure highest code quality.  Quality code ensures that your code is :  Understandable  Extendable and easily modified with changing business requirements  Scalability : Covers performance, maintainability and fault tolerance  Reliable : Does not easily breakdown  In this discussion, we look at commonly found problems in code, and find ways of overcoming them. Code Quality
  • 3.  Coding Guidelines  Understanding and Avoiding Common Coding and Design Mistakes  Memory Leaks  Bad smells of code  Excessive and un-necessary API calls  Best Practices  Centralized Server Communication  Following Single Responsibility Principle  Centralized Threading  Optimizing Use of Images in terms of file access, storage, and draw calls  Reducing Code Complexity  Static Code Analysis  Profiling Path to High Quality Code
  • 4.  Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices and methods for each aspect of a piece program written in this language.  These conventions usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices, programming principles, programming rules of thumb, etc. Coding Guidelines
  • 5.  Redundant Code  Writing functions which span many pages  Writing functions with deeply nested if’s, case's  Writing badly typed functions  Function names which do not reflect what the functions do  Variable names which are meaningless  Using processes when they are not needed  Badly chosen data structures (Bad representations).  Bad comments or no comments at all (always document arguments and return value).  Hard coded values  Unindented code.  Inaccessible parts of code (Dead Code) The Most Common Mistakes
  • 6.  Leads to lack of reusability  Can lead in unforeseen results  Example:  Code to perform sell operation added at 21 different places.  As a consequence, coins or virtual money being used in the project ends up being negative in a multi threaded game. Redundant Code
  • 7.  Long functions may not always be bad  Especially when a single algorithm is implemented  Long functions are bad when they have too many if blocks  Seriously consider dividing those functions  Extremely long functions are definitely bad  General rule of thumb is consider sub dividing your method when more than 50 lines of code Don’t Write Very Long Function’s
  • 8.  Nested code is code containing case/if/receive statements within other case/if/receive statements.  It is bad programming style to write deeply nested code - the code has a tendency to drift across the page to the right and soon becomes unreadable.  Try to limit most of your code to a maximum of two levels of indentation.  This can be achieved by dividing the code into shorter functions. Don't Write Deeply Nested Code
  • 9.  A module should not contain more than 400 lines of source code.  It is better to have several small modules than one large one.  A module is also very long when it has too many subroutines/functions Don't Write Very Large Modules
  • 10.  Comments should be clear and concise and avoid unnecessary wordiness.  Make sure that comments are kept up to date with the code.  Comments should add to the understanding of the code. Comments
  • 11.  The important things to document are:  The purpose of the function.  The domain of valid inputs to the function. That is, data structures of the arguments to the functions together with their meaning.  The domain of the output of the function. That is, all possible data structures of the return value together with their meaning.  If the function implements a complicated algorithm, describe it.  The possible causes of failure and exit signals which may be generated by exit/1, throw/1 or any non-obvious run time errors. Note the difference between failure and returning an error.  Any side effect of the function. Comments About Function/Method
  • 12.  Example: %%-------------------------------------------------------- %% Function: get_server_statistics/2 %% Purpose: Get various information from a process. %% Args: Option is normal|all. %% Returns: A list of {Key, Value} %% or {error, Reason} (if the process is dead) %% Modification History: %%-------------------------------------------------------------- Comments About Function/Method (Cont’d)
  • 13.  Never leave commented code when submitting/committing code  Remember the source code control system will help you! Do Not Comment Out Old Code – Remove It
  • 14.  Many errors go unnoticed until runtime at client site.  Exceptions provide a powerful and flexible way to handle issues in your code,  Use them wisely.  Common examples of such errors include:  Sending messages an object doesn’t respond to  Going out of bounds of an array  Accessing invalid data  File not found  Unable to save/retrieve file on a network server because of incorrect encodling e.g. ASCII on client side and Unicode on server side  Losing the connection to the window server Exception Handling
  • 15.  When reviewing code, please make sure that you do not have any segments/blocks of code where control will never be transferred.  Inaccessible code is also called dead code.  Examples include a function that is never used.  An if/else block that is never supposed to be get control transferred to it.  Use exception handling to cover unexpected scenarios rather than leaving inaccessible code for end of world type scenarios. Inaccessible Code
  • 16.  Avoid hardcoding values into the source code  Hard coding requires the program's source code to be changed any time the input data changes  Constants may be put in a separate configuration file when necessary Avoid Hard Coded Values
  • 17.  How efficient is an algorithm or piece of code?  CPU (time) Usage  Memory Usage  Disk Usage  Network Usage  We express complexity of our algorithms using big-O notation.  For a problem of size N:  a constant-time method is "order 1": O(1)  a linear-time method is "order N": O(N)  a quadratic-time method is "order N squared": O(N2) Code Complexity
  • 18.  In 1976, Tom McCabe published a paper arguing that code complexity is defined by its control flow.  It seems to be generally accepted that control flow is one of the most useful measurements of complexity  High complexity scores have been shown to be a strong indicator of low reliability and frequent errors.  The Cyclomatic Complexity computation based on Tom McCabe's work and is defined in Steve McConnell's book, Code Complete on page 395 :  Start with 1 for the straight path through the routine  Add 1 for each of the following keywords or their equivalents: if, while, repeat, for, and, or  Add 1 for each case in a case statement Code Complexity(Cont’d)
  • 19.  So, if we have this C# example:  while (nextPage != true)  {  if ((lineCount <= linesPerPage) && (status != Status.Cancelled) && (morePages == true))  {  // ...  }  }   In the code above, we start with 1 for the routine, add 1 for the while, add 1 for the if, and add 1 for each && for a total calculated complexity of 5.  Anything with a greater complexity than 10 or so is an excellent candidate for simplification and refactoring.  Minimizing complexity is a great goal for writing high-quality, maintainable code. Code Complexity(Cont’d)
  • 20.  Some advantages of McCabe's Cyclomatic Complexity include:  It is very easy to compute, as illustrated in the example  It can be computed immediately in the development lifecycle (which makes it Agile-friendly)  It provides a good indicator of the ease of code maintenance  It can help focus testing efforts  It makes it easy to find complex code for formal review Code Complexity(Cont’d)
  • 21.  Formal code review coupled with complexity measurements provide a very compelling technique for quality improvement, and it is something that can easily be adopted by an Agile team.  So, what can you do to implement this technique for your project?  Find a tool that computes code metrics (specifically complexity) for your language and toolset  Schedule the tool so that it automatically runs and captures metrics every day  Use the code complexity measurement to help identify candidates for formal code review  Capture the results of the code review and monitor their follow- up (too many teams forget about the follow-up) Code Complexity(Cont’d)
  • 22.  Programmers love to write loops !  Loops can significantly increase code complexity while decreasing code quality.  Common mistakes to avoid in loops are :  Memory allocations in loops  Variable declarations in loops  Function calls that just return constant value Loops
  • 23.  Example  In this for loop, we are calling array count function multiple function multiple times, although it remains fixed throughout the execution of the loop. for (int i = 0; i< [landPatchesArray count]; i++) for (int j=0;………) { } Alternatively Int i=0; int j=0; landPatchArrayCount=[landPatchesArray count]; for (i = 0; i<landPatchArrayCount; i++) for (j=0;………) Loops(Cont’d)
  • 24.  Pay careful attention to memory allocation and deallocation.  Always run profiler to check for memory leaks. Memory Leaks
  • 25.  Its difficult to think of applications that do not have use of multiple threads.  Threads are horrible:  They tend to make behavior of your programs as unpredictable  As soon as you notice unpredictable behavior then you start putting synchronized blocks around your code and data.  Developers just start creating threads without ever thinking about organizing/managing their threads. Centralized Threading Model
  • 26.  Grand Central Dispatch is a mechanism for controlling multiple threads of execution.  It is an implementation of task parallelism based on the thread pool pattern.  GCD works by allowing specific tasks in a program that can be run in parallel to be queued up for execution and, depending on availability of processing resources, scheduling them to execute on any of the available processor cores[11]. Centralized Threading Model (Cont’d)
  • 27.  Centralized server communication is important because we need to ensure consistent behavior of the system when updating or retrieving its state from the server.  A common mistake is to allow individual modules to update their own state with the server.  Example  In one scenario, inconsistent game state udpation resulted because of non-adherence to single responsibility principle because many classes were managing their own NSURLConnections, and none of the instances really do much error handling or robust retry logic. Centralized Server Communication
  • 28.  Pay careful attention to optimizing use of Images in terms of file access, storage, and draw calls.  PNG and JPG formats are highly inefficient, because the data must be parsed into bitmap form on the fly at load time.  iOS Specific Image Formats can come to your rescue in such a scenario  One of the better format is pvr.ccz, which cocos2d natively supports,  Pvr.ccz image are faster to read from disk, and require no parsing to load into memory.  Use spritesheets to minimize image loading and faster rendering through batch sprites. Optimizing Image Use
  • 29.  Static code analysis is the process of detecting errors and defects in software's source code.  Static analysis can be viewed as an automated code review process. Static Code Analysis
  • 30.  Static analysis is usually poor regarding diagnosing memory leaks and concurrency errors.  To detect such errors you actually need to execute a part of the program virtually. It requires extra effort and carefulness.  A static analysis tool warns you about odd fragments. It means that the code can actually be quite correct.  It is called false-positive reports. Disadvantages of Static Code Analysis
  • 31.  Profiling is a form of dynamic program analysis that measures, for example, the usage of memory, the usage of particular instructions, or frequency and duration of function calls.  The most common use of profiling information is to aid program optimization.  Profiling is achieved by instrumenting either the program source code or its binary executable form using a tool called a profiler (or code profiler). Profiling