SlideShare a Scribd company logo
BUILDING LARGE WEB
APPLICATIONS
That won’t be a pain to maintain
WHO AM I?
Xavier Redó Cano
CTO & Co-Founder
@xavier_redo
xavier.redo@marsbased.com
FIRST MONTHS BUILDINGTHE NEXT
BIGTHING ®
ONEYEAR LATER
–Henning Koch - Makandra CEO and author of Growing Rails
Applications
“Large applications are large.”
AN INCONVENIENT SECRET
WHAT DOYOUTHINKTHAT MAKES AN
APP MORE MAINTAINABLE?
3 STEPSTO GLORY
• Follow conventions	

• Write code for human
beings	

• Always test
–Arthur Forman
“Not everyone thinks the way you think, knows
the things you know, believes the things you believe,
nor acts the way you would act. Remember this and
you will go a long way in getting along with people.”
FOLLOW CONVENTIONS
THE EASY ONE: CODING STYLE
if current_user
redirect_to user_tasks_path(current_user, format: 'json')
end
!
if(current_user)
redirect_to(user_tasks_path(current_user, :format => ‘json'))
end
!
unless current_user.nil?
redirect_to( user_tasks_path( current_user, format: 'json' ) )
end
!
redirect_to(user_tasks_path(current_user, :format => 'json') if current_user
!
current_user && redirect_to(user_tasks_path(current_user, :format => 'json')
!
current_user and redirect_to(user_tasks_path(current_user, :format => 'json')
• It is very easy to start doing it.	

• You’ll be faster reading code that follows a certain
style.	

• Saves time avoiding trivial discussions.	

• When your team grows, you want to maintain
coherence amongst your codebase.
WHYYOU SHOULD BE ADOPTING A
CODING STYLE?
• Almost every Ruby on Rails company use and recommend a Style Guide:	

• Thoughtbot: https://github.com/thoughtbot/guides/tree/master/style	

• Plataformatec: http://guidelines.plataformatec.com.br/ruby.html	

• MarsBased: Coming soon!	

• If you can’t afford to build yours. Use the community ones!!	

• https://github.com/bbatsov/ruby-style-guide	

• https://github.com/bbatsov/rails-style-guide
WHY SHOULDYOU BE ADOPTING A
CODING STYLE?
FRAMEWORK CONVENTIONS
• ModelView Controller architecture	

• CRUD centric RESTFUL approach	

• ActiveRecord pattern	

• Convention over configuration	

• Unobtrusive Javascript	

• DRY (Don’t repeat yourself)	

• Concerns and modules to extend functionality	

• etc.
resources :projects
!
!
class ProjectsController <
ApplicationController
!
def index
end
!
def show
end
!
def new
end
!
def create
end
!
def edit
end
!
def update
end
!
def destroy
end
end
EXAMPLE: RAILS CRUD BASED RESTFUL
APPROACH
resources :projects
!
!
class ProjectsController <
ApplicationController
!
def index
end
!
def show
end
!
def new
end
!
def create
end
!
def edit
end
!
def update
end
!
def destroy
end
end
Publishing	

feature
EXAMPLE: RAILS CRUD BASED RESTFUL
APPROACH
resources :projects
!
!
class ProjectsController <
ApplicationController
!
def index
end
!
def show
end
!
def new
end
!
def create
end
!
def edit
end
!
def update
end
!
def destroy
end
end
resources :projects do
member do
patch :publish
patch :unpublish
end
end
!
!
class TasksController < ApplicationController
def index
end
!
def show
end
!
def new
end
!
def create
end
!
def edit
end
!
def update
end
!
def destroy
end
!
def publish
end
!
def unpublish
end
end
Publishing	

feature
EXAMPLE: RAILS CRUD BASED RESTFUL
APPROACH
resources :projects do
member do
patch :publish
patch :unpublish
end
end
resources :projects do
member do
patch :publish
patch :unpublish
post :duplicate
patch :add_collaborator
patch :remove_collaborator
end
!
collection do
get :search
end
end
Lots of features
EXAMPLE: RAILS CRUD BASED RESTFUL
APPROACH
A TRULY RAILS RESTFUL APPROACH
resources :projects
!
namespace :projects do
resources :publishings, only: [:create, :destroy]
resources :duplications, only: [:new, :create]
resources :collaborator_addings, only: [:create, :destroy]
resources :searches, only: [:create]
end
EXAMPLE: RAILS CRUD BASED RESTFUL
APPROACH
DEVELOPERS CONVENTIONS:	

DESIGN PATTERNS
Context Strategy
Concrete
Strategy 1
Concrete
Strategy 2
Concrete
Strategy 3
YOUR OWN CONVENTIONS
• Your team is going to naturally develop a
coding style and a set of conventions. 	

• Embrace them, document them and use
them in all your projects.	

• It’s part of your company’s culture.
YOUR OWN CONVENTIONS
Don’t change your
conventions every 2
months
–David Heinemeier Hansson (@dhh) - Ruby on Rails creator
“We are not computer scientists.We are software
writers.”
WRITE CODE FOR HUMAN BEINGS
Ruby programming language
WHY IS IT IMPORTANT?
BrainFuck programming language
USE INTENTION REVEALING
METHOD NAMES
aka: Let your code speak to you
INTENTION REVEALING METHOD NAMES
class SearchUsersService
def search_users(params)
# TODO: refactor
conditions = {}
conditions["hireable"] = params[:hireable] unless params[:hireable].nil?
conditions["availability"] = params[:availability] unless params[:availability].nil?
conditions["profile.tags_array"] = params[:tags].split(",") if params[:tags]
conditions["category_ids"] = params[:category_ids].split(",") if params[:category_ids]
!
if params[:location]
filter = {
:multi_match => {
:query => params[:location],
:fields => ["profile.country","profile.state","profile.city"]
}
}
end
!
if params[:q].present? || !conditions.empty?
query = User.search(params[:q], where: conditions, execute: false)
query.body[:query][:bool][:must] << filter if params[:location].present?
query.execute.results
else
User.active.ordered_for_directory(params[:order])
end
end
end
class SearchUsersService
!
def search_users(params)
conditions = extract_conditions_from(params)
filter = extract_filters_from(params)
!
if query_term_for?(params) || conditions.any?
query = build_users_search_query(params, conditions, filter)
query.execute.results
else
User.active.ordered_for_directory(params[:order])
end
end
!
end
INTENTION REVEALING METHOD NAMES
KISS: KEEP IT SIMPLE STUPID
HOW DOYOU ACHIEVE SIMPLICITY?
Create reusable components only when you detect
duplication.	

Apply a design pattern to a problem only when
simplifies your code and improves code readability.	

Prefer being explicit than being implicit.	

Maintain the abstraction low.
KISS: KEEP IT SIMPLE STUPID
It also applies to the 3rd party software you are using
HOWTO BE SUREYOU ARE WRITING
UNDERSTANDABLE CODE?
Pair programming	

Git workflow based on pull requests and
code revisions	

Reading, reading and reading open-source
applications and libraries
ALWAYSTEST
– Anonymous
“The principle objective of software testing is to give
confidence in the software.”
WHYTESTING?
Bring confidence and peace of mind.	

Discover hidden bugs in your application.	

Save lots of time avoiding manual tests.	

Allow you to refactor code.
# TODO: It needs refactoring. Replace conditionals with
# polymorphism and delegate responsibilities.
def author_information
if author.kind_of?(Teacher)
if author.male?
"Mr. #{author.full_name} - Dpt #{author.department}"
elsif author.female?
"Ms. #{author.full_name} - Dpt #{author.department}"
end
elsif author.kind_of?(Student)
"Student of #{author.degree}"
end
end
DON’T FORGETTO REFACTOR
A green test is not the final step
WHY DO CODERS STOP
TESTING?
Testing require a different set of skills.	

Some tests are hard to write (e.g.
integration).	

Tests also need maintenance.	

Customers don’t mind if you test or
not.
THANKYOU!
@xavier_redo
xavier.redo@marsbased.com
Don’t be shy and drop me a line
BONUSTRACK
Model
Controller
View
Decorators Presenters
Service Objects
Policy Objects
Facade

More Related Content

Viewers also liked

Mark 6 - Prophets Disrupt
Mark 6 - Prophets DisruptMark 6 - Prophets Disrupt
Mark 6 - Prophets Disrupt
Bill Faris
 
The Wisdom of Mercy
The Wisdom of MercyThe Wisdom of Mercy
The Wisdom of Mercy
Bill Faris
 
Act1_1&lt;&lt;mgal>>
Act1_1&lt;&lt;mgal>>Act1_1&lt;&lt;mgal>>
Act1_1&lt;&lt;mgal>>
Maya Álvarez Lozano
 
Social Media 5 Years Later: Strategy is Still the Key
Social Media 5 Years Later: Strategy is Still the KeySocial Media 5 Years Later: Strategy is Still the Key
Social Media 5 Years Later: Strategy is Still the Key
Trivera Interactive
 
PT Maestro Global Informatika - Company Profile & Service Offerings
PT Maestro Global Informatika - Company Profile & Service OfferingsPT Maestro Global Informatika - Company Profile & Service Offerings
PT Maestro Global Informatika - Company Profile & Service Offerings
Aradea Susetya
 
Presentation on the topic *School classroom of Chemistry*
Presentation on the topic *School classroom of Chemistry*Presentation on the topic *School classroom of Chemistry*
Presentation on the topic *School classroom of Chemistry*
Xagaroma
 
Semiotica 2
Semiotica 2Semiotica 2
7 laadukkaan verkkosivuston elementtiä
7 laadukkaan verkkosivuston elementtiä7 laadukkaan verkkosivuston elementtiä
7 laadukkaan verkkosivuston elementtiä
Digimoguli
 
Act1 e.f.o.m
Act1 e.f.o.mAct1 e.f.o.m
Act1 e.f.o.m
Erick Ordaz
 
Smed
SmedSmed
Social Media Measurement for Sales & Marketing
Social Media Measurement for Sales & MarketingSocial Media Measurement for Sales & Marketing
Social Media Measurement for Sales & Marketing
Brian Honigman
 
College and University Social Media Strategy
College and University Social Media StrategyCollege and University Social Media Strategy
College and University Social Media Strategy
Rebecca Roebuck
 
Planning Your Visit To Pearl Harbor
Planning Your Visit To Pearl HarborPlanning Your Visit To Pearl Harbor
Planning Your Visit To Pearl Harbor
Discover Hawaii Tours
 

Viewers also liked (13)

Mark 6 - Prophets Disrupt
Mark 6 - Prophets DisruptMark 6 - Prophets Disrupt
Mark 6 - Prophets Disrupt
 
The Wisdom of Mercy
The Wisdom of MercyThe Wisdom of Mercy
The Wisdom of Mercy
 
Act1_1&lt;&lt;mgal>>
Act1_1&lt;&lt;mgal>>Act1_1&lt;&lt;mgal>>
Act1_1&lt;&lt;mgal>>
 
Social Media 5 Years Later: Strategy is Still the Key
Social Media 5 Years Later: Strategy is Still the KeySocial Media 5 Years Later: Strategy is Still the Key
Social Media 5 Years Later: Strategy is Still the Key
 
PT Maestro Global Informatika - Company Profile & Service Offerings
PT Maestro Global Informatika - Company Profile & Service OfferingsPT Maestro Global Informatika - Company Profile & Service Offerings
PT Maestro Global Informatika - Company Profile & Service Offerings
 
Presentation on the topic *School classroom of Chemistry*
Presentation on the topic *School classroom of Chemistry*Presentation on the topic *School classroom of Chemistry*
Presentation on the topic *School classroom of Chemistry*
 
Semiotica 2
Semiotica 2Semiotica 2
Semiotica 2
 
7 laadukkaan verkkosivuston elementtiä
7 laadukkaan verkkosivuston elementtiä7 laadukkaan verkkosivuston elementtiä
7 laadukkaan verkkosivuston elementtiä
 
Act1 e.f.o.m
Act1 e.f.o.mAct1 e.f.o.m
Act1 e.f.o.m
 
Smed
SmedSmed
Smed
 
Social Media Measurement for Sales & Marketing
Social Media Measurement for Sales & MarketingSocial Media Measurement for Sales & Marketing
Social Media Measurement for Sales & Marketing
 
College and University Social Media Strategy
College and University Social Media StrategyCollege and University Social Media Strategy
College and University Social Media Strategy
 
Planning Your Visit To Pearl Harbor
Planning Your Visit To Pearl HarborPlanning Your Visit To Pearl Harbor
Planning Your Visit To Pearl Harbor
 

Similar to Building Large Web Applications That Are Easy to Maintain

SOLID Ruby, SOLID Rails
SOLID Ruby, SOLID RailsSOLID Ruby, SOLID Rails
SOLID Ruby, SOLID Rails
Jens-Christian Fischer
 
Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to Domain
Jeremy Cook
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
Chul Ju Hong
 
PLAT-14 Forms Config, Customization, and Extension
PLAT-14 Forms Config, Customization, and ExtensionPLAT-14 Forms Config, Customization, and Extension
PLAT-14 Forms Config, Customization, and Extension
Alfresco Software
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
Chul Ju Hong
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
Matthew Beale
 
Moving ActiveRecord objects to the boundaries of your domain
Moving ActiveRecord objects to the boundaries of your domainMoving ActiveRecord objects to the boundaries of your domain
Moving ActiveRecord objects to the boundaries of your domain
Patrick Dougall
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
Artem Tabalin
 
Grails patterns and practices
Grails patterns and practicesGrails patterns and practices
Grails patterns and practices
paulbowler
 
Refactoring
RefactoringRefactoring
Refactoring
Artem Tabalin
 
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
Ruby Meditation
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
Ben Scofield
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
Viget Labs
 
Writing Testable Code
Writing Testable CodeWriting Testable Code
Writing Testable Code
jameshalsall
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
rstankov
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Chris Laning
 
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
 Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg... Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
Brian Mann
 
Introduction to JavaScript design patterns
Introduction to JavaScript design patternsIntroduction to JavaScript design patterns
Introduction to JavaScript design patterns
Jeremy Duvall
 
Building Better Web Apps with Angular.js (SXSW 2014)
Building Better Web Apps with Angular.js (SXSW 2014)Building Better Web Apps with Angular.js (SXSW 2014)
Building Better Web Apps with Angular.js (SXSW 2014)
kbekessy
 

Similar to Building Large Web Applications That Are Easy to Maintain (20)

SOLID Ruby, SOLID Rails
SOLID Ruby, SOLID RailsSOLID Ruby, SOLID Rails
SOLID Ruby, SOLID Rails
 
Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to Domain
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
PLAT-14 Forms Config, Customization, and Extension
PLAT-14 Forms Config, Customization, and ExtensionPLAT-14 Forms Config, Customization, and Extension
PLAT-14 Forms Config, Customization, and Extension
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 
Moving ActiveRecord objects to the boundaries of your domain
Moving ActiveRecord objects to the boundaries of your domainMoving ActiveRecord objects to the boundaries of your domain
Moving ActiveRecord objects to the boundaries of your domain
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Grails patterns and practices
Grails patterns and practicesGrails patterns and practices
Grails patterns and practices
 
Refactoring
RefactoringRefactoring
Refactoring
 
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
Growing Rails Apps - Dmitry Zhlobo | Ruby Meditation #23
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Writing Testable Code
Writing Testable CodeWriting Testable Code
Writing Testable Code
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
 
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
 Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg... Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
 
Introduction to JavaScript design patterns
Introduction to JavaScript design patternsIntroduction to JavaScript design patterns
Introduction to JavaScript design patterns
 
Building Better Web Apps with Angular.js (SXSW 2014)
Building Better Web Apps with Angular.js (SXSW 2014)Building Better Web Apps with Angular.js (SXSW 2014)
Building Better Web Apps with Angular.js (SXSW 2014)
 

Recently uploaded

Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASICINTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
GOKULKANNANMMECLECTC
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
Beckhoff Programmable Logic Control Overview Presentation
Beckhoff Programmable Logic Control Overview PresentationBeckhoff Programmable Logic Control Overview Presentation
Beckhoff Programmable Logic Control Overview Presentation
VanTuDuong1
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
drshikhapandey2022
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
Impartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 StandardImpartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 Standard
MuhammadJazib15
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
DharmaBanothu
 
DELTA V MES EMERSON EDUARDO RODRIGUES ENGINEER
DELTA V MES EMERSON EDUARDO RODRIGUES ENGINEERDELTA V MES EMERSON EDUARDO RODRIGUES ENGINEER
DELTA V MES EMERSON EDUARDO RODRIGUES ENGINEER
EMERSON EDUARDO RODRIGUES
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
Dwarkadas J Sanghvi College of Engineering
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
Introduction to Artificial Intelligence.
Introduction to Artificial Intelligence.Introduction to Artificial Intelligence.
Introduction to Artificial Intelligence.
supriyaDicholkar1
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
PriyankaKilaniya
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
Unit -II Spectroscopy - EC I B.Tech.pdf
Unit -II Spectroscopy - EC  I B.Tech.pdfUnit -II Spectroscopy - EC  I B.Tech.pdf
Unit -II Spectroscopy - EC I B.Tech.pdf
TeluguBadi
 

Recently uploaded (20)

Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASICINTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
Beckhoff Programmable Logic Control Overview Presentation
Beckhoff Programmable Logic Control Overview PresentationBeckhoff Programmable Logic Control Overview Presentation
Beckhoff Programmable Logic Control Overview Presentation
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
Impartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 StandardImpartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 Standard
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
 
DELTA V MES EMERSON EDUARDO RODRIGUES ENGINEER
DELTA V MES EMERSON EDUARDO RODRIGUES ENGINEERDELTA V MES EMERSON EDUARDO RODRIGUES ENGINEER
DELTA V MES EMERSON EDUARDO RODRIGUES ENGINEER
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
Introduction to Artificial Intelligence.
Introduction to Artificial Intelligence.Introduction to Artificial Intelligence.
Introduction to Artificial Intelligence.
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
Unit -II Spectroscopy - EC I B.Tech.pdf
Unit -II Spectroscopy - EC  I B.Tech.pdfUnit -II Spectroscopy - EC  I B.Tech.pdf
Unit -II Spectroscopy - EC I B.Tech.pdf
 

Building Large Web Applications That Are Easy to Maintain

  • 1. BUILDING LARGE WEB APPLICATIONS That won’t be a pain to maintain
  • 2. WHO AM I? Xavier Redó Cano CTO & Co-Founder @xavier_redo xavier.redo@marsbased.com
  • 3. FIRST MONTHS BUILDINGTHE NEXT BIGTHING ®
  • 5. –Henning Koch - Makandra CEO and author of Growing Rails Applications “Large applications are large.” AN INCONVENIENT SECRET
  • 6. WHAT DOYOUTHINKTHAT MAKES AN APP MORE MAINTAINABLE?
  • 7. 3 STEPSTO GLORY • Follow conventions • Write code for human beings • Always test
  • 8. –Arthur Forman “Not everyone thinks the way you think, knows the things you know, believes the things you believe, nor acts the way you would act. Remember this and you will go a long way in getting along with people.” FOLLOW CONVENTIONS
  • 9. THE EASY ONE: CODING STYLE if current_user redirect_to user_tasks_path(current_user, format: 'json') end ! if(current_user) redirect_to(user_tasks_path(current_user, :format => ‘json')) end ! unless current_user.nil? redirect_to( user_tasks_path( current_user, format: 'json' ) ) end ! redirect_to(user_tasks_path(current_user, :format => 'json') if current_user ! current_user && redirect_to(user_tasks_path(current_user, :format => 'json') ! current_user and redirect_to(user_tasks_path(current_user, :format => 'json')
  • 10. • It is very easy to start doing it. • You’ll be faster reading code that follows a certain style. • Saves time avoiding trivial discussions. • When your team grows, you want to maintain coherence amongst your codebase. WHYYOU SHOULD BE ADOPTING A CODING STYLE?
  • 11. • Almost every Ruby on Rails company use and recommend a Style Guide: • Thoughtbot: https://github.com/thoughtbot/guides/tree/master/style • Plataformatec: http://guidelines.plataformatec.com.br/ruby.html • MarsBased: Coming soon! • If you can’t afford to build yours. Use the community ones!! • https://github.com/bbatsov/ruby-style-guide • https://github.com/bbatsov/rails-style-guide WHY SHOULDYOU BE ADOPTING A CODING STYLE?
  • 12. FRAMEWORK CONVENTIONS • ModelView Controller architecture • CRUD centric RESTFUL approach • ActiveRecord pattern • Convention over configuration • Unobtrusive Javascript • DRY (Don’t repeat yourself) • Concerns and modules to extend functionality • etc.
  • 13. resources :projects ! ! class ProjectsController < ApplicationController ! def index end ! def show end ! def new end ! def create end ! def edit end ! def update end ! def destroy end end EXAMPLE: RAILS CRUD BASED RESTFUL APPROACH
  • 14. resources :projects ! ! class ProjectsController < ApplicationController ! def index end ! def show end ! def new end ! def create end ! def edit end ! def update end ! def destroy end end Publishing feature EXAMPLE: RAILS CRUD BASED RESTFUL APPROACH
  • 15. resources :projects ! ! class ProjectsController < ApplicationController ! def index end ! def show end ! def new end ! def create end ! def edit end ! def update end ! def destroy end end resources :projects do member do patch :publish patch :unpublish end end ! ! class TasksController < ApplicationController def index end ! def show end ! def new end ! def create end ! def edit end ! def update end ! def destroy end ! def publish end ! def unpublish end end Publishing feature EXAMPLE: RAILS CRUD BASED RESTFUL APPROACH
  • 16. resources :projects do member do patch :publish patch :unpublish end end resources :projects do member do patch :publish patch :unpublish post :duplicate patch :add_collaborator patch :remove_collaborator end ! collection do get :search end end Lots of features EXAMPLE: RAILS CRUD BASED RESTFUL APPROACH
  • 17. A TRULY RAILS RESTFUL APPROACH resources :projects ! namespace :projects do resources :publishings, only: [:create, :destroy] resources :duplications, only: [:new, :create] resources :collaborator_addings, only: [:create, :destroy] resources :searches, only: [:create] end EXAMPLE: RAILS CRUD BASED RESTFUL APPROACH
  • 18. DEVELOPERS CONVENTIONS: DESIGN PATTERNS Context Strategy Concrete Strategy 1 Concrete Strategy 2 Concrete Strategy 3
  • 19. YOUR OWN CONVENTIONS • Your team is going to naturally develop a coding style and a set of conventions. • Embrace them, document them and use them in all your projects. • It’s part of your company’s culture.
  • 20. YOUR OWN CONVENTIONS Don’t change your conventions every 2 months
  • 21. –David Heinemeier Hansson (@dhh) - Ruby on Rails creator “We are not computer scientists.We are software writers.” WRITE CODE FOR HUMAN BEINGS
  • 22. Ruby programming language WHY IS IT IMPORTANT? BrainFuck programming language
  • 23. USE INTENTION REVEALING METHOD NAMES aka: Let your code speak to you
  • 24. INTENTION REVEALING METHOD NAMES class SearchUsersService def search_users(params) # TODO: refactor conditions = {} conditions["hireable"] = params[:hireable] unless params[:hireable].nil? conditions["availability"] = params[:availability] unless params[:availability].nil? conditions["profile.tags_array"] = params[:tags].split(",") if params[:tags] conditions["category_ids"] = params[:category_ids].split(",") if params[:category_ids] ! if params[:location] filter = { :multi_match => { :query => params[:location], :fields => ["profile.country","profile.state","profile.city"] } } end ! if params[:q].present? || !conditions.empty? query = User.search(params[:q], where: conditions, execute: false) query.body[:query][:bool][:must] << filter if params[:location].present? query.execute.results else User.active.ordered_for_directory(params[:order]) end end end
  • 25. class SearchUsersService ! def search_users(params) conditions = extract_conditions_from(params) filter = extract_filters_from(params) ! if query_term_for?(params) || conditions.any? query = build_users_search_query(params, conditions, filter) query.execute.results else User.active.ordered_for_directory(params[:order]) end end ! end INTENTION REVEALING METHOD NAMES
  • 26. KISS: KEEP IT SIMPLE STUPID
  • 27. HOW DOYOU ACHIEVE SIMPLICITY? Create reusable components only when you detect duplication. Apply a design pattern to a problem only when simplifies your code and improves code readability. Prefer being explicit than being implicit. Maintain the abstraction low.
  • 28. KISS: KEEP IT SIMPLE STUPID It also applies to the 3rd party software you are using
  • 29. HOWTO BE SUREYOU ARE WRITING UNDERSTANDABLE CODE? Pair programming Git workflow based on pull requests and code revisions Reading, reading and reading open-source applications and libraries
  • 30. ALWAYSTEST – Anonymous “The principle objective of software testing is to give confidence in the software.”
  • 31. WHYTESTING? Bring confidence and peace of mind. Discover hidden bugs in your application. Save lots of time avoiding manual tests. Allow you to refactor code.
  • 32. # TODO: It needs refactoring. Replace conditionals with # polymorphism and delegate responsibilities. def author_information if author.kind_of?(Teacher) if author.male? "Mr. #{author.full_name} - Dpt #{author.department}" elsif author.female? "Ms. #{author.full_name} - Dpt #{author.department}" end elsif author.kind_of?(Student) "Student of #{author.degree}" end end DON’T FORGETTO REFACTOR A green test is not the final step
  • 33. WHY DO CODERS STOP TESTING? Testing require a different set of skills. Some tests are hard to write (e.g. integration). Tests also need maintenance. Customers don’t mind if you test or not.