SlideShare uma empresa Scribd logo
1 de 78
Baixar para ler offline
RAILS
The Next Five Years
THE LAST
FIVE YEARS
WHY DO WE
LIKE RAILS?
"CONVENTION OVER
CONFIGURATION"
TRIVIAL CHOICES.




        When we say "convention over
        configuration", we mostly mean
        eliminating trivial choices.
TRIVIAL CHOICES.
■ Naming
■ Asset compilation
■ To test or not to test
■ Routing HTTP to controllers
■ File structure and architecture
MORE COMMON
CONCERNS REQUIRE
FEWER DECISIONS.
Rails takes a very hard line on
conventions, which forces us to solve
problems very completely. There's little
room for us to punt problems onto Rails
users.
CSRF PROTECTION
100% MANUAL.
SEMIAUTOMATIC.
<form action="/cash_transfer">
{% csrf_token %}
AUTOMATIC.
<%= form_for @cash_transfer do |f| %>
  <%= f.text_field :from %>
  <%= f.text_field :to %>
  <%= f.text_field :amount %>
  <%= button "Transfer!" %>
<% end %> Enter Text here
Conventions            Tools           Hand-Rolled


Conventions allow you to avoid
thinking about the problem at all while
working on features.

Tools make the problem easier to solve,
but still make you think about it.


When we don't have a convention for
something, we end up forcing the
developer to learn about the problem
and choose a solution, which is most of
the cognitive overhead of solving it
yourself.
                    Cognitive Overhead
The common conventions of Rails
applications provide a foundation for
additional abstractions.
COURSE
             CORRECTIONS
No interest in cosmetic, no time for
refactoring.

Interested in figuring out why my
clients don't want me to use Rails.
MANY PEOPLE
  HAVE A PROBLEM.


Criteria for course corrections
MANY PARTS OF THE
SOLUTION ARE
TRIVIAL.REST:
      What HTTP structure should I use?
      What names should I give my methods?
      How should I generate URLs?
THERE IS BENEFIT IN A
SHARED SOLUTION.
       Asset pipeline:

       * Works out of the box
       * Reduces cost of entering a project
       * Concept of "Rails asset processor"
LEARNING ABOUT
THE PROBLEM IS
HARD. Encodings, Security, ETags
FAILURE TO SOLVE
IN RAILS CORE.
       What are the problems for failing to
       provide solutions in Rails core.

       Flip side of what I just said.
CRITICAL MASS.
       Having multiple competing solutions
       robs any one solution of the critical
       mass it needs to rapidly improve.

       No initial implementation is perfect,
       and Rails provides eyeballs and hands.
It's tempting to say "let this feature be
         a plugin, and we'll let our users flesh it
         out before we include it"
USAGE.   This often results in several competing
         solutions, each languishing with few
         users, all of which have major issues.

         The lack of usage can also hide
         conceptual problems with an approach
         (heroku deployment?)
INTEGRATION.
      When users pick a solution on their
      own, they are willing to put up with a
      lot of manual work. The process of
      integrating a feature into Rails to
      automate it often brings fundamental
      problems to light.
ECHO CHAMBER.
The people most likely to choose a plugin solution to a
problem also understand it the most. This means that
there is little impetus to provide completely transparent
solutions that work without complete (or any) knowledge
of the underlying problems. By making something a Rails
concern, it immediately busts the echo chamber of those
who already understand the problem.
TECHNICAL DEBT.
     As Aaron said yesterday, when solving
     these larger issues, we have a larger
     tolerance for technical debt.

     That said, we shouldn't throw caution
     to the wind and take on unlimited
     debt. At this point, we're still paying
     back our last emergency loan, so let's
     be more prudent now.
GOOD ARCHITECTURE
ENABLES FUTURE
FEATURES.
       Architecting well means that we can
                easily improve the feature in the
                future. Many of the good things in
                the Rails 3 architecture
                (notifications) have only come to
                fruition now.
FEATURES NOW + FEATURES LATER

             ÷
  COST NOW + MAINTENANCE
FEATURES NOW + FEATURES LATER

               ÷
  COST NOW + MAINTENANCE
          Building a feature right lets us extend
          it easily in the future with lower
          maintenance costs. This allows us to
          make necessary investments more
          easily in the future.
BETS

When we correct course, we are
placing a bet about the future of our
industry.
BETTING ON REST.
WINS OF REST.
■ Early support for rich HTTP semantics
  ■ Powerful router (request constraints, ...)
  ■ Content negotiation (Accept, $.getJSON)
  ■ Baked-in MIME types
  ■ HTTP caching ("Conditional GET")
  ■ JSON parameters
  ■ Security (e.g. IP spoofing)
RAILS HAS A GREAT
HTTP FOUNDATION.
BUT...
DATA
TRANSPORT
SQL DATABASE
BEFORE RAILS.
■ Primary key: chosen per table
■ Table name: chosen per table
■ Timestamps: chosen per timestamp
■ Polymorphic tables: ad hoc setup
■ Foreign keys: chosen per relationship
■ Camel/Underscore: chosen per field
Because of all of these discrepancies,
you end up needing to build a map of
your database for your application.
"DATABASES ARE
TOO DIFFERENT"
      In the early days of Rails, we heard a
      lot of arguments that databases were
      simply too different for AR to be more
      than just a toy. We hear similar
      arguments today with APIs.
JSON APIS.
JSON APIS.
■ Should responses include a root?
■ How to embed associations?
■ Include the identifier? In what form?
  ■ id or href?
■ Include additional/associated resources?
■ How to update in bulk?
■ Primary key defined on server or client?
■ Moving a belongs_to record?
              Just like there were questions in SQL,
              there are questions in JSON APIs.
STANDARDIZED
CLIENT CODE.

      Without standardization, we cannot
      easily build standardized code on the
      client.
We're also back to making the same
trivial decisions over and over again,
if we even realize that we are
making decisions.
And because we're not taking on the
problem, we're pushing the concerns
onto every client.
Since Rails doesn't provide these conventions,
 people are asking "Is Rails the right tool for the job"

 Even though other tools don't provide conventions,
 Rails is all about CoC, so the lack of conventions
 makes *Rails* feel like the wrong tool for the job,
 even though much of Rails is still useful.


IS RAILS WORTH IT?


 Rails starts feeling more like a very polished
 library and less like a framework.
ACTIVEMODEL
SERIALIZERS.
What to Serialize         How to Serialize

• Which   attributes     • Include a root?
• Which   associations   • Associations?
                         • Extra data?
                         • Avoid duplication!
WHAT TO SERIALIZE.
class PostSerializer < ApplicationSerializer
  attributes :title, :body
  belongs_to :author
  has_many :comments
end
CUSTOMIZE.
class PostSerializer < ApplicationSerializer
  attributes :title, :body
  belongs_to :author
  has_many :comments
 
  def comments
    comments = post.comments
    return comments if scope.admin?
 
    comments.where(hidden: false)
  end
end
HOW TO SERIALIZE.
class ApplicationController
  embed :ids, include: true
end
AVOID DUPLICATION.
{
  posts: [
    { "id":   1, "title": "First", "person_id": 1 },
    { "id":   2, "title": "Next", "person_id": 1 },
    { "id":   3, "title": "More!", "person_id": 1 }
  ],
  people: [
    { "id":   1, "name": "Yehuda Katz" }
  ]
}
ANY CONVENTION IS
BETTER THAN NO
CONVENTION.
DEMO.
The advantage of serializers is that
   it avoids mixing the common
   (representation) with the unique
   (attributes, associations)


AVOID MIXING
COMMON AND
UNCOMMON.
   This is in contrast with builders,
   which put the common and unique
   things in one place, so we have no
   place for conventions.
CONFIGURABLE.

       Especially for authorization, there is
       a need to be able to poke under the
       declarative hood. It's not all
       documented, but it works.
AUTHORIZATION.
class PostSerializer < ApplicationSerializer
  attributes :title, :body
  has_many :comments
  has_many :troll_ratings

  # override just default association inclusion
  def include_associations!
    comments = post.comments
 
    unless scope.can(:see_hidden, post)
      comments = comments.where(visible: true)
    end
 
    # override default value, but not embedding rules, etc.
    include! :comments, value: comments
 
    # conditionally include an association
    include! :troll_ratings if scope.can(:troll_rate, post)
  end
end
WAS IN RAILS.
REVERTED. WHY?
EMBER-RAILS.

       ember-rails was trying to build a
       transparent data transport and it
       was hard for arbitrary Rails
       applications.
GENERATE A MODEL,
GET A SERIALIZER
AND EMBER-DATA
MODEL.
REST ADAPTER.
REST ADAPTER.
App.store = DS.Store.create({
  revision: 4,
  adapter: "DS.RESTAdapter"
});
MODELS.
App.Post = DS.Model.extend({
  title: DS.attr('string'),
  body: DS.attr('string'),
 
  comments: DS.hasMany(App.Comment) 
});
 
App.Comment = DS.Model.extend({
  body: DS.attr('string'),

  post: DS.belongsTo(App.Post) 
});
TRANSPARENT.
var people = App.Person.all();
/* GET /people */
 
// later...

var first = people.objectAt(0);
first.set('firstName', "Brohuda");
 
App.store.commit();
/* POST /person/1 { ... } */
Transport                 Serialization




AMo::Serializers solve serialization, but I
think we need a general solution for all
three.
                   Client Side
BULK.
 Serializers doesn't solve this, but there is a
 need to define conventions around bulk
 updates.

 ember-data defines conventions that, if
 implemented in Rails, "just work"
OTHER DATA
FEATURES.
   Identity map; data binding to the
   view; associations (including create
   parent=>child=>persist)
CONVENTIONS FOR
APPLICATION
STRUCTURE.
  Beyond "put your JS here"
TRIVIAL CHOICES ARE
THE ENEMY.
NODE?
“
    Back in 1995, we knew something that I don't think
    our competitors understood, and few understand
    even now: when you're writing software that only
    has to run on your own servers, you can use any
    language you want. When you're writing desktop
    software, there's a strong bias toward writing
    applications in the same language as the operating
    system. But with Web-based software, you can use
    whatever language you want.




PAUL GRAHAM
“
    This new freedom is a double-edged sword,
    however. Now that you can use any language, you
    have to think about which one to use. Companies
    that try to pretend nothing has changed risk finding
    that their competitors do not.




PAUL GRAHAM
TRANSPORT.

  Standards and                      Same Language
   Conventions                         Everywhere

• HTML                            • JMS
• ActiveRecord                    • DRb
         Thinking "I need to talk with JS,
         therefore I need to write JS on the
         ser ver" is pretty lazy thinking. We can
         get seamlessness without insisting on
         the same language everywhere.
TRANSPORT.

  Standards and                      Same Language


                         >
   Conventions                         Everywhere

• HTML                            • JMS
• ActiveRecord                    • DRb
         Thinking "I need to talk with JS,
         therefore I need to write JS on the
         ser ver" is pretty lazy thinking. We can
         get seamlessness without insisting on
         the same language everywhere.
RECAP
RECAP.
■ Good conventions save developers from
  having to agonize over common problems.
■ Rails' bet on REST gave it a leg up in many
  areas that are relevant to rich client apps.
■ There is still room for improvement: we can
  make APIs as transparent as ActiveRecord.
■ ActiveModel::Serializers is one approach we
  are looking at to get us there.
■ We can also make browser frameworks better
  through the same conventions.
THANKS!

@WYCATS

Mais conteúdo relacionado

Mais procurados

Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsReturn on Intelligence
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machenAndré Goliath
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016Matt Raible
 
NullCon 2012 - Ra.2: blackbox DOM-based XSS scanner
NullCon 2012 - Ra.2: blackbox DOM-based XSS scannerNullCon 2012 - Ra.2: blackbox DOM-based XSS scanner
NullCon 2012 - Ra.2: blackbox DOM-based XSS scannerNishant Das Patnaik
 
You wanna crypto in AEM
You wanna crypto in AEMYou wanna crypto in AEM
You wanna crypto in AEMDamien Antipa
 
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSencha
 
Cutting the Fat
Cutting the FatCutting the Fat
Cutting the FatCodemotion
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Naresh Chintalcheru
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tipsShakti Shrestha
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angularBasarat Syed
 
Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Matt Raible
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016Matt Raible
 
Advanced CSRF and Stateless Anti-CSRF
Advanced CSRF and Stateless Anti-CSRFAdvanced CSRF and Stateless Anti-CSRF
Advanced CSRF and Stateless Anti-CSRFjohnwilander
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015Matt Raible
 
Wicket Introduction
Wicket IntroductionWicket Introduction
Wicket IntroductionEyal Golan
 
Our application got popular and now it breaks
Our application got popular and now it breaksOur application got popular and now it breaks
Our application got popular and now it breaksColdFusionConference
 

Mais procurados (20)

Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.js
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machen
 
Getting started with angular js
Getting started with angular jsGetting started with angular js
Getting started with angular js
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx France 2016
 
Secrets management in the cloud
Secrets management in the cloudSecrets management in the cloud
Secrets management in the cloud
 
NullCon 2012 - Ra.2: blackbox DOM-based XSS scanner
NullCon 2012 - Ra.2: blackbox DOM-based XSS scannerNullCon 2012 - Ra.2: blackbox DOM-based XSS scanner
NullCon 2012 - Ra.2: blackbox DOM-based XSS scanner
 
You wanna crypto in AEM
You wanna crypto in AEMYou wanna crypto in AEM
You wanna crypto in AEM
 
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
 
Cutting the Fat
Cutting the FatCutting the Fat
Cutting the Fat
 
Kickstart sencha extjs
Kickstart sencha extjsKickstart sencha extjs
Kickstart sencha extjs
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
 
Java script performance tips
Java script performance tipsJava script performance tips
Java script performance tips
 
SxSW 2015
SxSW 2015SxSW 2015
SxSW 2015
 
Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angular
 
Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021Web App Security for Java Developers - UberConf 2021
Web App Security for Java Developers - UberConf 2021
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Devoxx UK 2016
 
Advanced CSRF and Stateless Anti-CSRF
Advanced CSRF and Stateless Anti-CSRFAdvanced CSRF and Stateless Anti-CSRF
Advanced CSRF and Stateless Anti-CSRF
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
 
Wicket Introduction
Wicket IntroductionWicket Introduction
Wicket Introduction
 
Our application got popular and now it breaks
Our application got popular and now it breaksOur application got popular and now it breaks
Our application got popular and now it breaks
 

Semelhante a The Next Five Years of Rails

Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010arif44
 
Backbone/Marionette introduction
Backbone/Marionette introductionBackbone/Marionette introduction
Backbone/Marionette introductionmatt-briggs
 
Beyond rails new
Beyond rails newBeyond rails new
Beyond rails newPaul Oguda
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails PresentationPaul Pajo
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusJarrod Overson
 
2010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week12010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week1Wolfram Arnold
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!mold
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Pythongturnquist
 
Using Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyUsing Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyDavid Keener
 
Decoupled cms sunshinephp 2014
Decoupled cms sunshinephp 2014Decoupled cms sunshinephp 2014
Decoupled cms sunshinephp 2014Lukas Smith
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arpGary Pedretti
 
黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)Fong Liou
 
The 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaThe 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaDavid Chandler
 
Document Databases & RavenDB
Document Databases & RavenDBDocument Databases & RavenDB
Document Databases & RavenDBBrian Ritchie
 
Lessons from running AppSync in prod
Lessons from running AppSync in prodLessons from running AppSync in prod
Lessons from running AppSync in prodYan Cui
 
2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...
2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...
2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...Peter Rosenberg
 
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias
 

Semelhante a The Next Five Years of Rails (20)

Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010
 
Backbone/Marionette introduction
Backbone/Marionette introductionBackbone/Marionette introduction
Backbone/Marionette introduction
 
Beyond rails new
Beyond rails newBeyond rails new
Beyond rails new
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails Presentation
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Micro services
Micro servicesMicro services
Micro services
 
2010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week12010-07-19_rails_tdd_week1
2010-07-19_rails_tdd_week1
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
Using Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case StudyUsing Rails to Create an Enterprise App: A Real-Life Case Study
Using Rails to Create an Enterprise App: A Real-Life Case Study
 
Decoupled cms sunshinephp 2014
Decoupled cms sunshinephp 2014Decoupled cms sunshinephp 2014
Decoupled cms sunshinephp 2014
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)黑豹 ch4 ddd pattern practice (2)
黑豹 ch4 ddd pattern practice (2)
 
The 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaThe 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for Java
 
Document Databases & RavenDB
Document Databases & RavenDBDocument Databases & RavenDB
Document Databases & RavenDB
 
Lessons from running AppSync in prod
Lessons from running AppSync in prodLessons from running AppSync in prod
Lessons from running AppSync in prod
 
Wordpress development 101
Wordpress development 101Wordpress development 101
Wordpress development 101
 
2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...
2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...
2009 10-08 soa-og_itil_does service in it service rhyme with service as in so...
 
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
 

Último

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

The Next Five Years of Rails

  • 3. WHY DO WE LIKE RAILS?
  • 5. TRIVIAL CHOICES. When we say "convention over configuration", we mostly mean eliminating trivial choices.
  • 6. TRIVIAL CHOICES. ■ Naming ■ Asset compilation ■ To test or not to test ■ Routing HTTP to controllers ■ File structure and architecture
  • 8. Rails takes a very hard line on conventions, which forces us to solve problems very completely. There's little room for us to punt problems onto Rails users.
  • 12. AUTOMATIC. <%= form_for @cash_transfer do |f| %> <%= f.text_field :from %> <%= f.text_field :to %> <%= f.text_field :amount %> <%= button "Transfer!" %> <% end %> Enter Text here
  • 13. Conventions Tools Hand-Rolled Conventions allow you to avoid thinking about the problem at all while working on features. Tools make the problem easier to solve, but still make you think about it. When we don't have a convention for something, we end up forcing the developer to learn about the problem and choose a solution, which is most of the cognitive overhead of solving it yourself. Cognitive Overhead
  • 14. The common conventions of Rails applications provide a foundation for additional abstractions.
  • 15. COURSE CORRECTIONS No interest in cosmetic, no time for refactoring. Interested in figuring out why my clients don't want me to use Rails.
  • 16. MANY PEOPLE HAVE A PROBLEM. Criteria for course corrections
  • 17. MANY PARTS OF THE SOLUTION ARE TRIVIAL.REST: What HTTP structure should I use? What names should I give my methods? How should I generate URLs?
  • 18. THERE IS BENEFIT IN A SHARED SOLUTION. Asset pipeline: * Works out of the box * Reduces cost of entering a project * Concept of "Rails asset processor"
  • 19. LEARNING ABOUT THE PROBLEM IS HARD. Encodings, Security, ETags
  • 20. FAILURE TO SOLVE IN RAILS CORE. What are the problems for failing to provide solutions in Rails core. Flip side of what I just said.
  • 21. CRITICAL MASS. Having multiple competing solutions robs any one solution of the critical mass it needs to rapidly improve. No initial implementation is perfect, and Rails provides eyeballs and hands.
  • 22. It's tempting to say "let this feature be a plugin, and we'll let our users flesh it out before we include it" USAGE. This often results in several competing solutions, each languishing with few users, all of which have major issues. The lack of usage can also hide conceptual problems with an approach (heroku deployment?)
  • 23. INTEGRATION. When users pick a solution on their own, they are willing to put up with a lot of manual work. The process of integrating a feature into Rails to automate it often brings fundamental problems to light.
  • 24. ECHO CHAMBER. The people most likely to choose a plugin solution to a problem also understand it the most. This means that there is little impetus to provide completely transparent solutions that work without complete (or any) knowledge of the underlying problems. By making something a Rails concern, it immediately busts the echo chamber of those who already understand the problem.
  • 25. TECHNICAL DEBT. As Aaron said yesterday, when solving these larger issues, we have a larger tolerance for technical debt. That said, we shouldn't throw caution to the wind and take on unlimited debt. At this point, we're still paying back our last emergency loan, so let's be more prudent now.
  • 26. GOOD ARCHITECTURE ENABLES FUTURE FEATURES. Architecting well means that we can easily improve the feature in the future. Many of the good things in the Rails 3 architecture (notifications) have only come to fruition now.
  • 27. FEATURES NOW + FEATURES LATER ÷ COST NOW + MAINTENANCE
  • 28. FEATURES NOW + FEATURES LATER ÷ COST NOW + MAINTENANCE Building a feature right lets us extend it easily in the future with lower maintenance costs. This allows us to make necessary investments more easily in the future.
  • 29. BETS When we correct course, we are placing a bet about the future of our industry.
  • 31. WINS OF REST. ■ Early support for rich HTTP semantics ■ Powerful router (request constraints, ...) ■ Content negotiation (Accept, $.getJSON) ■ Baked-in MIME types ■ HTTP caching ("Conditional GET") ■ JSON parameters ■ Security (e.g. IP spoofing)
  • 32. RAILS HAS A GREAT HTTP FOUNDATION.
  • 36. BEFORE RAILS. ■ Primary key: chosen per table ■ Table name: chosen per table ■ Timestamps: chosen per timestamp ■ Polymorphic tables: ad hoc setup ■ Foreign keys: chosen per relationship ■ Camel/Underscore: chosen per field
  • 37. Because of all of these discrepancies, you end up needing to build a map of your database for your application.
  • 38. "DATABASES ARE TOO DIFFERENT" In the early days of Rails, we heard a lot of arguments that databases were simply too different for AR to be more than just a toy. We hear similar arguments today with APIs.
  • 40. JSON APIS. ■ Should responses include a root? ■ How to embed associations? ■ Include the identifier? In what form? ■ id or href? ■ Include additional/associated resources? ■ How to update in bulk? ■ Primary key defined on server or client? ■ Moving a belongs_to record? Just like there were questions in SQL, there are questions in JSON APIs.
  • 41. STANDARDIZED CLIENT CODE. Without standardization, we cannot easily build standardized code on the client.
  • 42. We're also back to making the same trivial decisions over and over again, if we even realize that we are making decisions.
  • 43. And because we're not taking on the problem, we're pushing the concerns onto every client.
  • 44. Since Rails doesn't provide these conventions, people are asking "Is Rails the right tool for the job" Even though other tools don't provide conventions, Rails is all about CoC, so the lack of conventions makes *Rails* feel like the wrong tool for the job, even though much of Rails is still useful. IS RAILS WORTH IT? Rails starts feeling more like a very polished library and less like a framework.
  • 46. What to Serialize How to Serialize • Which attributes • Include a root? • Which associations • Associations? • Extra data? • Avoid duplication!
  • 47. WHAT TO SERIALIZE. class PostSerializer < ApplicationSerializer   attributes :title, :body   belongs_to :author   has_many :comments end
  • 48. CUSTOMIZE. class PostSerializer < ApplicationSerializer   attributes :title, :body   belongs_to :author   has_many :comments     def comments     comments = post.comments     return comments if scope.admin?       comments.where(hidden: false)   end end
  • 49. HOW TO SERIALIZE. class ApplicationController   embed :ids, include: true end
  • 50. AVOID DUPLICATION. {   posts: [     { "id": 1, "title": "First", "person_id": 1 },     { "id": 2, "title": "Next", "person_id": 1 },     { "id": 3, "title": "More!", "person_id": 1 }   ],   people: [     { "id": 1, "name": "Yehuda Katz" }   ] }
  • 51. ANY CONVENTION IS BETTER THAN NO CONVENTION.
  • 52. DEMO.
  • 53.
  • 54.
  • 55. The advantage of serializers is that it avoids mixing the common (representation) with the unique (attributes, associations) AVOID MIXING COMMON AND UNCOMMON. This is in contrast with builders, which put the common and unique things in one place, so we have no place for conventions.
  • 56. CONFIGURABLE. Especially for authorization, there is a need to be able to poke under the declarative hood. It's not all documented, but it works.
  • 57. AUTHORIZATION. class PostSerializer < ApplicationSerializer   attributes :title, :body   has_many :comments   has_many :troll_ratings # override just default association inclusion   def include_associations!     comments = post.comments       unless scope.can(:see_hidden, post)       comments = comments.where(visible: true)     end       # override default value, but not embedding rules, etc.     include! :comments, value: comments       # conditionally include an association     include! :troll_ratings if scope.can(:troll_rate, post)   end end
  • 60. EMBER-RAILS. ember-rails was trying to build a transparent data transport and it was hard for arbitrary Rails applications.
  • 61. GENERATE A MODEL, GET A SERIALIZER AND EMBER-DATA MODEL.
  • 63. REST ADAPTER. App.store = DS.Store.create({ revision: 4,   adapter: "DS.RESTAdapter" });
  • 64. MODELS. App.Post = DS.Model.extend({   title: DS.attr('string'),   body: DS.attr('string'),     comments: DS.hasMany(App.Comment)  });   App.Comment = DS.Model.extend({   body: DS.attr('string'),   post: DS.belongsTo(App.Post)  });
  • 65. TRANSPARENT. var people = App.Person.all(); /* GET /people */   // later... var first = people.objectAt(0); first.set('firstName', "Brohuda");   App.store.commit(); /* POST /person/1 { ... } */
  • 66. Transport Serialization AMo::Serializers solve serialization, but I think we need a general solution for all three. Client Side
  • 67. BULK. Serializers doesn't solve this, but there is a need to define conventions around bulk updates. ember-data defines conventions that, if implemented in Rails, "just work"
  • 68. OTHER DATA FEATURES. Identity map; data binding to the view; associations (including create parent=>child=>persist)
  • 69. CONVENTIONS FOR APPLICATION STRUCTURE. Beyond "put your JS here"
  • 71. NODE?
  • 72. Back in 1995, we knew something that I don't think our competitors understood, and few understand even now: when you're writing software that only has to run on your own servers, you can use any language you want. When you're writing desktop software, there's a strong bias toward writing applications in the same language as the operating system. But with Web-based software, you can use whatever language you want. PAUL GRAHAM
  • 73. This new freedom is a double-edged sword, however. Now that you can use any language, you have to think about which one to use. Companies that try to pretend nothing has changed risk finding that their competitors do not. PAUL GRAHAM
  • 74. TRANSPORT. Standards and Same Language Conventions Everywhere • HTML • JMS • ActiveRecord • DRb Thinking "I need to talk with JS, therefore I need to write JS on the ser ver" is pretty lazy thinking. We can get seamlessness without insisting on the same language everywhere.
  • 75. TRANSPORT. Standards and Same Language > Conventions Everywhere • HTML • JMS • ActiveRecord • DRb Thinking "I need to talk with JS, therefore I need to write JS on the ser ver" is pretty lazy thinking. We can get seamlessness without insisting on the same language everywhere.
  • 76. RECAP
  • 77. RECAP. ■ Good conventions save developers from having to agonize over common problems. ■ Rails' bet on REST gave it a leg up in many areas that are relevant to rich client apps. ■ There is still room for improvement: we can make APIs as transparent as ActiveRecord. ■ ActiveModel::Serializers is one approach we are looking at to get us there. ■ We can also make browser frameworks better through the same conventions.