SlideShare a Scribd company logo
CODE REVIEW PROCESSCODE REVIEW PROCESS
BOGDAN GUSIEVBOGDAN GUSIEV
CODE REVIEW TENDS TO BE NATURALCODE REVIEW TENDS TO BE NATURAL
CODE REVIEW YOURSELFCODE REVIEW YOURSELF
ASKING FOR HELPASKING FOR HELP
SPONDANUOUS CODE REVIEW PROBLEM:SPONDANUOUS CODE REVIEW PROBLEM:
TOO LATETOO LATE
EVERYTHING HAD CHANGED BYEVERYTHING HAD CHANGED BY
GITHUBGITHUB
DO I NEED A CODE REVIEW?DO I NEED A CODE REVIEW?
IMHO: NEW PROJECTSIMHO: NEW PROJECTS
DON'T NEED A FORMAL CODE REVIEW AT ALLDON'T NEED A FORMAL CODE REVIEW AT ALL
CODE REVIEW EVOLUTIONCODE REVIEW EVOLUTION
1. Spontanuous Code Reviews
2. "When I am not sure" code reviews
3. Formal Code Review Process
4. Required code review for certain changes
5. Required code reviews for everything
Fails Driven Process
CODE REVIEW PROPERTIESCODE REVIEW PROPERTIES
NECESSITYNECESSITY
Optional
Required
PROCESSPROCESS
Informal
Formal
PEOPLEPEOPLE
Dedicated
Distributed
POSITION IN A PROCESSPOSITION IN A PROCESS
1. Planning
2. Coding
3. Code Review
4. QA
5. Release
QA <-> Code Review
Formally QA a er Code Review
1. Make a fork (optional)
2. Create a Branch
3. Open a Pull Request
4. Wait for review
5. Discuss & Fix
6. Merge
CODE REVIEW ISCODE REVIEW IS
A PROCESS OFA PROCESS OF REVIEWING AND APPROVINGREVIEWING AND APPROVING CODE CHANGESCODE CHANGES
BEFOREBEFORE THEY GET ACCEPTED TO THE MAINSTREAMTHEY GET ACCEPTED TO THE MAINSTREAM
HOW TO REVIEW?HOW TO REVIEW?
FIX COMMON THINGS FIRST?FIX COMMON THINGS FIRST?
Typos
Whitespace
Code Style
Wrong Direction!
WHERE TO LOOK?WHERE TO LOOK?
Things that are most significant should be reviewed first
which are ones that are the most hard to change.
TOP TO BOTTOM CODE REVIEWTOP TO BOTTOM CODE REVIEW
1. Architecture
1. Problem Solution
2. Public APIs
3. Database Schema
4. Object Oriented Design
5. Public Method Signatures
2. Implementation
1. Classes & Methods
2. Views
3. Tests
4. Code Style, Typos, Whitespace
PROBLEM SOLUTIONPROBLEM SOLUTION
1. Problem makes sense
2. Problem Solved
3. High Level Security
4. High Level Performance
ONLY SHOW CUSTOM PROPERTIES WITH AT LEAST ONE VALUE IN SELECTONLY SHOW CUSTOM PROPERTIES WITH AT LEAST ONE VALUE IN SELECT
def selectable_product_categories
+ ProductCategory.with_at_least_one_product
- ProductCategory.all
end
ProductCategory.
where("not exists(select * from products where ...)").
count # => 0
HIGH LEVEL SECURITYHIGH LEVEL SECURITY
EX. FEATURE:EX. FEATURE:
LOGIN USER AUTOMATICALLY WHEN IT CLICKS ON THE LINK IN THE EMAILLOGIN USER AUTOMATICALLY WHEN IT CLICKS ON THE LINK IN THE EMAIL
THIS IS NOT VERY SECURETHIS IS NOT VERY SECURE
HIGH LEVEL PERFORMANCEHIGH LEVEL PERFORMANCE
CHECK IF THE CHANGECHECK IF THE CHANGE
Touches Performance sensitive code
Will be slow for particular data
No pagination when there are 1000+ records to display
PUBLIC APISPUBLIC APIS
USING HTTP API AS EXAMPLEUSING HTTP API AS EXAMPLE
1. Efficiency
2. Logical Endpoints
3. Request Parameters
4. Response Format
WHATEVER THAT IS DOCUMENTEDWHATEVER THAT IS DOCUMENTED
API INEFFICIENCY EXAMPLEAPI INEFFICIENCY EXAMPLE
EFFICIENT WAY?EFFICIENT WAY?
Purchase.has_one :referral
GET /purchases/:order_number
{
id: 1,
order_number: '1838382',
referral_id: 17
}
POST /referrals/:id/approve
POST /purchases/:order_number/referral/approve
RESPONSE FORMATRESPONSE FORMAT
# Easier
render json: @campaign.view_setups.to_json
# Extensible
render json: {view_setups: @campaign.view_setups.to_json}
BAD API EXAMPLEBAD API EXAMPLE
Talkable.publish('talkable_offer_close', null, true);
Talkable.publish('offer_close', null, true);
ANALYZE USAGE FIRSTANALYZE USAGE FIRST
BUT NOT IMPLEMENTATIONBUT NOT IMPLEMENTATION
setCustomProperty: function (person, properties) {
...
}
setCustomProperty('advocate', {key: value})
setCustomProperty('friend', {key: value})
setAdvocateCustomProperty: function(properties) {
private_stuff.setCustomProperty("advocate", properties);
},
setFriendCustomProperty: function(properties) {
private_stuff.setCustomProperty("friend", properties);
},
DATABASE SCHEMADATABASE SCHEMA
1. Relations between tables
2. Data Columns
3. Naming
EFFICIENT RELATIONSEFFICIENT RELATIONS
1. What are the variants?
2. Was the best one selected?
EFFICIENT SCHEMAEFFICIENT SCHEMA
add_column :images, :dimension, :string
class Image < AR::Base
def width
dimension.split("x").first
end
def height
dimension.split("x").last
end
end
add_column :images, :width, :integer
add_column :images, :height, :integer
DATA SHOULD BEDATA SHOULD BE EASY TO READEASY TO READ
EVEN IF IT MAKES ITEVEN IF IT MAKES IT HARDER TO WRITEHARDER TO WRITE
OBJECT ORIENTED DESIGNOBJECT ORIENTED DESIGN
1. Reflects Real World
2. Inheritance
3. Constructors
REVIEWING CONSTRUCTORSREVIEWING CONSTRUCTORS
CIRCULAR DEPENDENCYCIRCULAR DEPENDENCY
class Field
def initialize
@cells = Array.new(10) do
Array.new(10) { Cell.new(self) }
end
end
end
class Cell
def initialize(field)
@field = field
end
end
OBJECT CONSTRUCTORS ARE IMPORTANT:OBJECT CONSTRUCTORS ARE IMPORTANT:
Which things are required to use an object?
What are the object responsibilities?
Theoretical limit
Which methods can be implemented in the object?
Which things would need to be passed to methods as arguments?
Constructor defines object API
REVIEWING CONSTRUCTORSREVIEWING CONSTRUCTORS
UNDEFINED CONTEXTUNDEFINED CONTEXT
class ApplicationController
before_action do
WhateverRequestAnalyzer.new(request).analyze
end
end
CrawlerRequestAnalyzer.new(
request.user_agent, request.url, request.content_type
).analyze
PUBLIC METHOD SIGNATURESPUBLIC METHOD SIGNATURES
1. Placement
2. Arguments
3. Name
METHOD PLACEMENTMETHOD PLACEMENT
class User
def approve!(referral)
end
# OR
class Referral
def approve!(user)
end
METHOD ARGUMENTSMETHOD ARGUMENTS
this.extractUserData(this.data)
IMPLEMENTATIONIMPLEMENTATION
CLASSES & METHOD BODIESCLASSES & METHOD BODIES
Each method or class separately
Check one by one:
1. Approach & Algorithm
2. Performance
3. Security
4. Minimalism
5. Local Variable Names
PERFORMANCE & VULNERABILITIESPERFORMANCE & VULNERABILITIES
In the ideal world performance and vulnerabilities
should not change the code structure.
In practice it can but we should try hard
to fix performance problems only at the implementation level
GOOD PERFORMANCE PATCHGOOD PERFORMANCE PATCH
def core_options
- { header: name, description: description, group: group }
+ @core_options ||= { header: name, description: description, grou
end
- @campaign.locale_entries.each do
+ @campaign.locale_entries.preload(:variants).each do
GOOD VULNERABILITY PATCHGOOD VULNERABILITY PATCH
-{{ advocate_info.first_name }}
+{{ advocate_info.first_name | escape }}
SECURITYSECURITY
Approach Security (Step 1)
Is it secure to have this feature?
Is it secure to implement the feature this way?
Vulnerabilities
XSS
Allowed Parameters
Backend Authorisation check
Authorisation for UI elements
TESTSTESTS
1. Use Cases Coverage
2. Formal Code Coverage
3. Tests Implementation
TOP TO BOTTOM IDEATOP TO BOTTOM IDEA
IT IS BAD TO:IT IS BAD TO:
Discuss the method name before the method existence as a fact
Discuss Code Style before implementation itself
BOSS CONTROL APPROACHBOSS CONTROL APPROACH
Ensure top points from the list are always performed
Choose X things on top of the list to double-check and delegate the rest
completely
CODE REVIEW CULTURECODE REVIEW CULTURE
Be Polite
Admit good things
First things first
Reduce number of cycles
Save Author's time
Save Your time
TOP TO BOTTOM CODE REVIEWTOP TO BOTTOM CODE REVIEW
1. Architecture
1. Problem Solution
2. Public APIs
3. Database Schema
4. Object Oriented Design
5. Public Method Signatures
2. Implementation
1. Classes & Methods
2. Views
3. Test Coverage
4. Code Style, Typos, Whitespace

More Related Content

PPTX
Rock Your Code with Code Contracts
PPTX
Back-2-Basics: .NET Coding Standards For The Real World (2011)
PDF
Clean code & design patterns
PPTX
Building unit tests correctly with visual studio 2013
PPT
TDD And Refactoring
PPTX
TDD & BDD
PPTX
Rock Your Code With Code Contracts -2013
PPTX
Tdd & clean code
Rock Your Code with Code Contracts
Back-2-Basics: .NET Coding Standards For The Real World (2011)
Clean code & design patterns
Building unit tests correctly with visual studio 2013
TDD And Refactoring
TDD & BDD
Rock Your Code With Code Contracts -2013
Tdd & clean code

What's hot (20)

PPTX
XPDays Ukraine: Legacy
PPTX
Working with Legacy Code
PPTX
Refactoring
PDF
Working Effectively with Legacy Code: Lessons in Practice
PPTX
Test-Driven Development (TDD)
PPS
Design Patterns For 70% Of Programmers In The World
PPTX
BDD Primer
PPTX
Working Effectively with Legacy Code
PDF
Working With Legacy Code
PPTX
Refactoring Applications using SOLID Principles
PDF
Write readable tests
PPTX
Design Patterns: From STUPID to SOLID code
PDF
Why Your Test Suite Sucks - PHPCon PL 2015
PPTX
Back-2-Basics: Code Contracts
PDF
Creational Design Patterns
PPTX
Writing clean code in C# and .NET
PPTX
SAD10 - Refactoring
PDF
A journey to_be_a_software_craftsman
PPT
Spring AOP
PPTX
Clean tests good tests
XPDays Ukraine: Legacy
Working with Legacy Code
Refactoring
Working Effectively with Legacy Code: Lessons in Practice
Test-Driven Development (TDD)
Design Patterns For 70% Of Programmers In The World
BDD Primer
Working Effectively with Legacy Code
Working With Legacy Code
Refactoring Applications using SOLID Principles
Write readable tests
Design Patterns: From STUPID to SOLID code
Why Your Test Suite Sucks - PHPCon PL 2015
Back-2-Basics: Code Contracts
Creational Design Patterns
Writing clean code in C# and .NET
SAD10 - Refactoring
A journey to_be_a_software_craftsman
Spring AOP
Clean tests good tests
Ad

Similar to Professional Code Reviews - Bogdan Gusiev (20)

PPTX
Code reviews
PDF
Code reviews
PPTX
Capability Building for Cyber Defense: Software Walk through and Screening
PPTX
Code reviews
PDF
Voxxed days 2015-hakansaglam-codereview
PDF
Testing survival Guide
PDF
Funtional Ruby - Mikhail Bortnyk
PDF
Functional Ruby
PDF
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
PDF
How to improve the quality of your application
PDF
Refactoring
PPTX
Building a REST API for Longevity
PDF
JOSA TechTalks - RESTful API Concepts and Best Practices
KEY
Intro to Ruby - Twin Cities Code Camp 7
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
PDF
Code review in practice
PDF
On to code review lessons learned at microsoft
PDF
Code Inspection
PPT
The technology of the Human Protein Reference Database (draft, 2003)
ODP
RailswayCon 2010 - Command Your Domain
Code reviews
Code reviews
Capability Building for Cyber Defense: Software Walk through and Screening
Code reviews
Voxxed days 2015-hakansaglam-codereview
Testing survival Guide
Funtional Ruby - Mikhail Bortnyk
Functional Ruby
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
How to improve the quality of your application
Refactoring
Building a REST API for Longevity
JOSA TechTalks - RESTful API Concepts and Best Practices
Intro to Ruby - Twin Cities Code Camp 7
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
Code review in practice
On to code review lessons learned at microsoft
Code Inspection
The technology of the Human Protein Reference Database (draft, 2003)
RailswayCon 2010 - Command Your Domain
Ad

More from Ruby Meditation (20)

PDF
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
PDF
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
PDF
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
PDF
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
PDF
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
PDF
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
PDF
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
PDF
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
PDF
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
PDF
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
PDF
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
PDF
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
PDF
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
PDF
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
PDF
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
PDF
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
PDF
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
PDF
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
PDF
Rails App performance at the limit - Bogdan Gusiev
PDF
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Rails App performance at the limit - Bogdan Gusiev
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
top salesforce developer skills in 2025.pdf
PDF
AI in Product Development-omnex systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
L1 - Introduction to python Backend.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
medical staffing services at VALiNTRY
PDF
System and Network Administration Chapter 2
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
ai tools demonstartion for schools and inter college
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Design an Analysis of Algorithms I-SECS-1021-03
How to Choose the Right IT Partner for Your Business in Malaysia
2025 Textile ERP Trends: SAP, Odoo & Oracle
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
top salesforce developer skills in 2025.pdf
AI in Product Development-omnex systems
How to Migrate SBCGlobal Email to Yahoo Easily
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
CHAPTER 2 - PM Management and IT Context
L1 - Introduction to python Backend.pptx
Understanding Forklifts - TECH EHS Solution
medical staffing services at VALiNTRY
System and Network Administration Chapter 2
Softaken Excel to vCard Converter Software.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Nekopoi APK 2025 free lastest update
ai tools demonstartion for schools and inter college
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms I-SECS-1021-03

Professional Code Reviews - Bogdan Gusiev

  • 1. CODE REVIEW PROCESSCODE REVIEW PROCESS BOGDAN GUSIEVBOGDAN GUSIEV
  • 2. CODE REVIEW TENDS TO BE NATURALCODE REVIEW TENDS TO BE NATURAL
  • 3. CODE REVIEW YOURSELFCODE REVIEW YOURSELF
  • 5. SPONDANUOUS CODE REVIEW PROBLEM:SPONDANUOUS CODE REVIEW PROBLEM: TOO LATETOO LATE
  • 6. EVERYTHING HAD CHANGED BYEVERYTHING HAD CHANGED BY GITHUBGITHUB
  • 7. DO I NEED A CODE REVIEW?DO I NEED A CODE REVIEW? IMHO: NEW PROJECTSIMHO: NEW PROJECTS DON'T NEED A FORMAL CODE REVIEW AT ALLDON'T NEED A FORMAL CODE REVIEW AT ALL
  • 8. CODE REVIEW EVOLUTIONCODE REVIEW EVOLUTION 1. Spontanuous Code Reviews 2. "When I am not sure" code reviews 3. Formal Code Review Process 4. Required code review for certain changes 5. Required code reviews for everything Fails Driven Process
  • 9. CODE REVIEW PROPERTIESCODE REVIEW PROPERTIES NECESSITYNECESSITY Optional Required PROCESSPROCESS Informal Formal PEOPLEPEOPLE Dedicated Distributed
  • 10. POSITION IN A PROCESSPOSITION IN A PROCESS 1. Planning 2. Coding 3. Code Review 4. QA 5. Release QA <-> Code Review Formally QA a er Code Review
  • 11. 1. Make a fork (optional) 2. Create a Branch 3. Open a Pull Request 4. Wait for review 5. Discuss & Fix 6. Merge
  • 12. CODE REVIEW ISCODE REVIEW IS A PROCESS OFA PROCESS OF REVIEWING AND APPROVINGREVIEWING AND APPROVING CODE CHANGESCODE CHANGES BEFOREBEFORE THEY GET ACCEPTED TO THE MAINSTREAMTHEY GET ACCEPTED TO THE MAINSTREAM
  • 13. HOW TO REVIEW?HOW TO REVIEW?
  • 14. FIX COMMON THINGS FIRST?FIX COMMON THINGS FIRST? Typos Whitespace Code Style Wrong Direction!
  • 15. WHERE TO LOOK?WHERE TO LOOK? Things that are most significant should be reviewed first which are ones that are the most hard to change.
  • 16. TOP TO BOTTOM CODE REVIEWTOP TO BOTTOM CODE REVIEW 1. Architecture 1. Problem Solution 2. Public APIs 3. Database Schema 4. Object Oriented Design 5. Public Method Signatures 2. Implementation 1. Classes & Methods 2. Views 3. Tests 4. Code Style, Typos, Whitespace
  • 17. PROBLEM SOLUTIONPROBLEM SOLUTION 1. Problem makes sense 2. Problem Solved 3. High Level Security 4. High Level Performance
  • 18. ONLY SHOW CUSTOM PROPERTIES WITH AT LEAST ONE VALUE IN SELECTONLY SHOW CUSTOM PROPERTIES WITH AT LEAST ONE VALUE IN SELECT def selectable_product_categories + ProductCategory.with_at_least_one_product - ProductCategory.all end ProductCategory. where("not exists(select * from products where ...)"). count # => 0
  • 19. HIGH LEVEL SECURITYHIGH LEVEL SECURITY EX. FEATURE:EX. FEATURE: LOGIN USER AUTOMATICALLY WHEN IT CLICKS ON THE LINK IN THE EMAILLOGIN USER AUTOMATICALLY WHEN IT CLICKS ON THE LINK IN THE EMAIL THIS IS NOT VERY SECURETHIS IS NOT VERY SECURE
  • 20. HIGH LEVEL PERFORMANCEHIGH LEVEL PERFORMANCE CHECK IF THE CHANGECHECK IF THE CHANGE Touches Performance sensitive code Will be slow for particular data No pagination when there are 1000+ records to display
  • 21. PUBLIC APISPUBLIC APIS USING HTTP API AS EXAMPLEUSING HTTP API AS EXAMPLE 1. Efficiency 2. Logical Endpoints 3. Request Parameters 4. Response Format WHATEVER THAT IS DOCUMENTEDWHATEVER THAT IS DOCUMENTED
  • 22. API INEFFICIENCY EXAMPLEAPI INEFFICIENCY EXAMPLE EFFICIENT WAY?EFFICIENT WAY? Purchase.has_one :referral GET /purchases/:order_number { id: 1, order_number: '1838382', referral_id: 17 } POST /referrals/:id/approve POST /purchases/:order_number/referral/approve
  • 23. RESPONSE FORMATRESPONSE FORMAT # Easier render json: @campaign.view_setups.to_json # Extensible render json: {view_setups: @campaign.view_setups.to_json}
  • 24. BAD API EXAMPLEBAD API EXAMPLE Talkable.publish('talkable_offer_close', null, true); Talkable.publish('offer_close', null, true);
  • 25. ANALYZE USAGE FIRSTANALYZE USAGE FIRST BUT NOT IMPLEMENTATIONBUT NOT IMPLEMENTATION setCustomProperty: function (person, properties) { ... } setCustomProperty('advocate', {key: value}) setCustomProperty('friend', {key: value}) setAdvocateCustomProperty: function(properties) { private_stuff.setCustomProperty("advocate", properties); }, setFriendCustomProperty: function(properties) { private_stuff.setCustomProperty("friend", properties); },
  • 26. DATABASE SCHEMADATABASE SCHEMA 1. Relations between tables 2. Data Columns 3. Naming
  • 27. EFFICIENT RELATIONSEFFICIENT RELATIONS 1. What are the variants? 2. Was the best one selected?
  • 28. EFFICIENT SCHEMAEFFICIENT SCHEMA add_column :images, :dimension, :string class Image < AR::Base def width dimension.split("x").first end def height dimension.split("x").last end end add_column :images, :width, :integer add_column :images, :height, :integer
  • 29. DATA SHOULD BEDATA SHOULD BE EASY TO READEASY TO READ EVEN IF IT MAKES ITEVEN IF IT MAKES IT HARDER TO WRITEHARDER TO WRITE
  • 30. OBJECT ORIENTED DESIGNOBJECT ORIENTED DESIGN 1. Reflects Real World 2. Inheritance 3. Constructors
  • 31. REVIEWING CONSTRUCTORSREVIEWING CONSTRUCTORS CIRCULAR DEPENDENCYCIRCULAR DEPENDENCY class Field def initialize @cells = Array.new(10) do Array.new(10) { Cell.new(self) } end end end class Cell def initialize(field) @field = field end end
  • 32. OBJECT CONSTRUCTORS ARE IMPORTANT:OBJECT CONSTRUCTORS ARE IMPORTANT: Which things are required to use an object? What are the object responsibilities? Theoretical limit Which methods can be implemented in the object? Which things would need to be passed to methods as arguments? Constructor defines object API
  • 33. REVIEWING CONSTRUCTORSREVIEWING CONSTRUCTORS UNDEFINED CONTEXTUNDEFINED CONTEXT class ApplicationController before_action do WhateverRequestAnalyzer.new(request).analyze end end CrawlerRequestAnalyzer.new( request.user_agent, request.url, request.content_type ).analyze
  • 34. PUBLIC METHOD SIGNATURESPUBLIC METHOD SIGNATURES 1. Placement 2. Arguments 3. Name
  • 35. METHOD PLACEMENTMETHOD PLACEMENT class User def approve!(referral) end # OR class Referral def approve!(user) end
  • 38. CLASSES & METHOD BODIESCLASSES & METHOD BODIES Each method or class separately Check one by one: 1. Approach & Algorithm 2. Performance 3. Security 4. Minimalism 5. Local Variable Names
  • 39. PERFORMANCE & VULNERABILITIESPERFORMANCE & VULNERABILITIES In the ideal world performance and vulnerabilities should not change the code structure. In practice it can but we should try hard to fix performance problems only at the implementation level
  • 40. GOOD PERFORMANCE PATCHGOOD PERFORMANCE PATCH def core_options - { header: name, description: description, group: group } + @core_options ||= { header: name, description: description, grou end - @campaign.locale_entries.each do + @campaign.locale_entries.preload(:variants).each do
  • 41. GOOD VULNERABILITY PATCHGOOD VULNERABILITY PATCH -{{ advocate_info.first_name }} +{{ advocate_info.first_name | escape }}
  • 42. SECURITYSECURITY Approach Security (Step 1) Is it secure to have this feature? Is it secure to implement the feature this way? Vulnerabilities XSS Allowed Parameters Backend Authorisation check Authorisation for UI elements
  • 43. TESTSTESTS 1. Use Cases Coverage 2. Formal Code Coverage 3. Tests Implementation
  • 44. TOP TO BOTTOM IDEATOP TO BOTTOM IDEA IT IS BAD TO:IT IS BAD TO: Discuss the method name before the method existence as a fact Discuss Code Style before implementation itself
  • 45. BOSS CONTROL APPROACHBOSS CONTROL APPROACH Ensure top points from the list are always performed Choose X things on top of the list to double-check and delegate the rest completely
  • 46. CODE REVIEW CULTURECODE REVIEW CULTURE Be Polite Admit good things First things first Reduce number of cycles Save Author's time Save Your time
  • 47. TOP TO BOTTOM CODE REVIEWTOP TO BOTTOM CODE REVIEW 1. Architecture 1. Problem Solution 2. Public APIs 3. Database Schema 4. Object Oriented Design 5. Public Method Signatures 2. Implementation 1. Classes & Methods 2. Views 3. Test Coverage 4. Code Style, Typos, Whitespace