Professional Code Reviews - Bogdan Gusiev

Ruby Meditation
Ruby MeditationRuby Meditation
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
1 of 47

Recommended

Rock Your Code with Code Contracts by
Rock Your Code with Code ContractsRock Your Code with Code Contracts
Rock Your Code with Code ContractsDavid McCarter
800 views40 slides
Back-2-Basics: .NET Coding Standards For The Real World (2011) by
Back-2-Basics: .NET Coding Standards For The Real World (2011)Back-2-Basics: .NET Coding Standards For The Real World (2011)
Back-2-Basics: .NET Coding Standards For The Real World (2011)David McCarter
681 views38 slides
Clean code & design patterns by
Clean code & design patternsClean code & design patterns
Clean code & design patternsPascal Larocque
4.1K views37 slides
Building unit tests correctly with visual studio 2013 by
Building unit tests correctly with visual studio 2013Building unit tests correctly with visual studio 2013
Building unit tests correctly with visual studio 2013Dror Helper
2.8K views46 slides
TDD And Refactoring by
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
7.4K views34 slides
TDD & BDD by
TDD & BDDTDD & BDD
TDD & BDDArvind Vyas
1.2K views29 slides

More Related Content

What's hot

XPDays Ukraine: Legacy by
XPDays Ukraine: LegacyXPDays Ukraine: Legacy
XPDays Ukraine: LegacyVictor_Cr
7.5K views27 slides
Working with Legacy Code by
Working with Legacy CodeWorking with Legacy Code
Working with Legacy CodeEyal Golan
5.8K views48 slides
Refactoring by
RefactoringRefactoring
RefactoringMikalai Alimenkou
5.5K views34 slides
Working Effectively with Legacy Code: Lessons in Practice by
Working Effectively with Legacy Code: Lessons in PracticeWorking Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in PracticeAmar Shah
644 views33 slides
Test-Driven Development (TDD) by
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)Brian Rasmussen
9.7K views55 slides
Design Patterns For 70% Of Programmers In The World by
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
24.8K views60 slides

What's hot(20)

XPDays Ukraine: Legacy by Victor_Cr
XPDays Ukraine: LegacyXPDays Ukraine: Legacy
XPDays Ukraine: Legacy
Victor_Cr7.5K views
Working with Legacy Code by Eyal Golan
Working with Legacy CodeWorking with Legacy Code
Working with Legacy Code
Eyal Golan5.8K views
Working Effectively with Legacy Code: Lessons in Practice by Amar Shah
Working Effectively with Legacy Code: Lessons in PracticeWorking Effectively with Legacy Code: Lessons in Practice
Working Effectively with Legacy Code: Lessons in Practice
Amar Shah644 views
Test-Driven Development (TDD) by Brian Rasmussen
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
Brian Rasmussen9.7K views
Design Patterns For 70% Of Programmers In The World by Saurabh Moody
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
Saurabh Moody24.8K views
Working With Legacy Code by Andrea Polci
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
Andrea Polci3.7K views
Refactoring Applications using SOLID Principles by Steven Smith
Refactoring Applications using SOLID PrinciplesRefactoring Applications using SOLID Principles
Refactoring Applications using SOLID Principles
Steven Smith10.5K views
Why Your Test Suite Sucks - PHPCon PL 2015 by CiaranMcNulty
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
CiaranMcNulty1.2K views
Back-2-Basics: Code Contracts by David McCarter
Back-2-Basics: Code ContractsBack-2-Basics: Code Contracts
Back-2-Basics: Code Contracts
David McCarter824 views
Creational Design Patterns by Taka Wang
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
Taka Wang362 views
Writing clean code in C# and .NET by Dror Helper
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NET
Dror Helper13.9K views
A journey to_be_a_software_craftsman by Jaehoon Oh
A journey to_be_a_software_craftsmanA journey to_be_a_software_craftsman
A journey to_be_a_software_craftsman
Jaehoon Oh1.6K views

Similar to Professional Code Reviews - Bogdan Gusiev

New Ideas for Old Code - Greach by
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
1.1K views81 slides
6 Traits of a Successful Test Automation Architecture by
6 Traits of a Successful Test Automation Architecture6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation ArchitectureErdem YILDIRIM
835 views87 slides
Measuring Your Code by
Measuring Your CodeMeasuring Your Code
Measuring Your CodeNate Abele
10 views60 slides
Measuring Your Code 2.0 by
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0Nate Abele
1.4K views60 slides
A Future where we don’t write tests by
A Future where we don’t write testsA Future where we don’t write tests
A Future where we don’t write testsFelix Dobslaw
65 views46 slides
UI Testing by
UI TestingUI Testing
UI TestingJosh Black
203 views80 slides

Similar to Professional Code Reviews - Bogdan Gusiev(20)

New Ideas for Old Code - Greach by HamletDRC
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
HamletDRC1.1K views
6 Traits of a Successful Test Automation Architecture by Erdem YILDIRIM
6 Traits of a Successful Test Automation Architecture6 Traits of a Successful Test Automation Architecture
6 Traits of a Successful Test Automation Architecture
Erdem YILDIRIM835 views
Measuring Your Code by Nate Abele
Measuring Your CodeMeasuring Your Code
Measuring Your Code
Nate Abele10 views
Measuring Your Code 2.0 by Nate Abele
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0
Nate Abele1.4K views
A Future where we don’t write tests by Felix Dobslaw
A Future where we don’t write testsA Future where we don’t write tests
A Future where we don’t write tests
Felix Dobslaw65 views
2011-02-03 LA RubyConf Rails3 TDD Workshop by Wolfram Arnold
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold708 views
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018 by Mike Harris
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
Mike Harris32 views
Agile_goa_2013_clean_code_tdd by Srinivasa GV
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
Srinivasa GV1.3K views
Assuring the code quality of share point solutions and apps - Matthias Einig by SPC Adriatics
Assuring the code quality of share point solutions and apps - Matthias EinigAssuring the code quality of share point solutions and apps - Matthias Einig
Assuring the code quality of share point solutions and apps - Matthias Einig
SPC Adriatics728 views
Grails unit testing by pleeps
Grails unit testingGrails unit testing
Grails unit testing
pleeps4.1K views
Working Effectively With Legacy Perl Code by erikmsp
Working Effectively With Legacy Perl CodeWorking Effectively With Legacy Perl Code
Working Effectively With Legacy Perl Code
erikmsp1K views
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per... by GlobalLogic Ukraine
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
It's all about behaviour, also in php - phpspec by Giulio De Donato
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspec
Giulio De Donato5K views
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit by Ortus Solutions, Corp
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Testing ASP.NET - Progressive.NET by Ben Hall
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
Ben Hall5K views
Code Quality Practice and Tools by Bob Paulin
Code Quality Practice and ToolsCode Quality Practice and Tools
Code Quality Practice and Tools
Bob Paulin866 views

More from Ruby Meditation

Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30 by
Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30Ruby Meditation
207 views22 slides
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky... by
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Ruby Meditation
462 views141 slides
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29 by
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Ruby Meditation
210 views49 slides
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ... by
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Ruby Meditation
1.6K views59 slides
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 by
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 Ruby Meditation
366 views23 slides
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28 by
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28Ruby Meditation
459 views20 slides

More from Ruby Meditation(20)

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

Recently uploaded

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptxNeo4j
8 views26 slides
EV Charging App Case by
EV Charging App Case EV Charging App Case
EV Charging App Case iCoderz Solutions
5 views1 slide
MS PowerPoint.pptx by
MS PowerPoint.pptxMS PowerPoint.pptx
MS PowerPoint.pptxLitty Sylus
5 views14 slides
SAP FOR CONTRACT MANUFACTURING.pdf by
SAP FOR CONTRACT MANUFACTURING.pdfSAP FOR CONTRACT MANUFACTURING.pdf
SAP FOR CONTRACT MANUFACTURING.pdfVirendra Rai, PMP
13 views2 slides
tecnologia18.docx by
tecnologia18.docxtecnologia18.docx
tecnologia18.docxnosi6702
5 views5 slides
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptxanimuscrm
15 views19 slides

Recently uploaded(20)

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j8 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67025 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm15 views
JioEngage_Presentation.pptx by admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254556 views
Sprint 226 by ManageIQ
Sprint 226Sprint 226
Sprint 226
ManageIQ5 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok6 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
FOSSLight Community Day 2023-11-30 by Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan5 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy14 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik7 views
predicting-m3-devopsconMunich-2023.pptx by Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app7 views
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 views

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