Keeping Rails on the Tracks

Similar documents
Contents in Detail. Foreword by Xavier Noria

Ruby in the Sky with Diamonds. August, 2014 Sao Paulo, Brazil

FINDING TOXIC CODE. Experiences and techniques for finding dangerous code in large multi-language codebases

The Long Road from Capistrano to Kubernetes

Lecture 14. Moving Forward 1 / 23

Angular 2 and Hexo. Static Meets Dynamic For the Best of Both Worlds! Copyright 2016 Code Career Academy

Rails Engines. Use Case. The Implementation

AirBespoke Inventory Tracking System

MRI Internals. Koichi Sasada.

Git. all meaningful operations can be expressed in terms of the rebase command. -Linus Torvalds, 2015

Continuous Integration. Johannes Seitz

Extract API: Build sophisticated data models with the Extract API

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

Developing Kubernetes Services

Web Hosting. Important features to consider

Implementing the Twelve-Factor App Methodology for Developing Cloud- Native Applications

BeBanjo Infrastructure and Security Overview

Overhauling Dev Arch with Ansible Tower and Docker

Developers and DBAs. Farmers and City Slickers have different mindsets

SYMFONY2 WEB FRAMEWORK

Surrogate Dependencies (in

Scaling DreamFactory

Stanko Tadić

ERICH PRIMEHAMMER REFACTORING

Cold, Hard Cache KV? On the implementation and maintenance of caches. who is

Gunnery Documentation

ChiliProject - Bug # 529: builder is not part of the bundle. Add it to Gemfile

Git Basi, workflow e concetti avanzati (pt2)

JavaScript: the Big Picture

Episode 298. Getting Started With Spree

Real Life Web Development. Joseph Paul Cohen

Rocking with Racket. Marc Burns Beatlight Inc

Getting Started With Containers

Introduction and first application. Luigi De Russis. Rails 101

learn programming the right way

a handful of Git workflows for the agilist steven harman twitter: stevenharman

Linux System Management with Puppet, Gitlab, and R10k. Scott Nolin, SSEC Technical Computing 22 June 2017

Japan on Rails. Name: Akira Matsuda GitHub: amatsuda

EPHEMERAL DEVOPS: ADVENTURES IN MANAGING SHORT-LIVED SYSTEMS

Expert Guidance on Migrating from Magento 1 to Magento 2

We re working full time this summer alongside 3 UCOSP (project course) students (2 from Waterloo: Mark Rada & Su Zhang, 1 from UofT: Angelo Maralit)

O Reilly RailsConf,

Microservices Smaller is Better? Eberhard Wolff Freelance consultant & trainer

monolith to micro-services? event sourcing can help Doug

DevOps Anti-Patterns. Have the Ops team deal with it. Time to fire the Ops team! Let s hire a DevOps unit! COPYRIGHT 2019 MANICODE SECURITY

Holistic Database Security

Deployment Is Not A Four Letter Word. Chris Hartjes PHP Quebec 2009 Conference

Web2py Instant Admin Documentation

Learning to love release notes

CloudCenter for Developers

ElasticIntel. Scalable Threat Intel Aggregation in AWS

Beyond 1001 Dedicated Data Service Instances

nacelle Documentation

Flexible Network Analytics in the Cloud. Jon Dugan & Peter Murphy ESnet Software Engineering Group October 18, 2017 TechEx 2017, San Francisco

Power Up/Level Up: Supercharging Your Security Program for Cloud and DevOps. Rich

Ruby on Rails. SITC Workshop Series American University of Nigeria FALL 2017

Distributed Systems. 29. Distributed Caching Paul Krzyzanowski. Rutgers University. Fall 2014

Application Deployment

Get in Touch Module 1 - Core PHP XHTML

Monica. Personal Relationship Management

Spam. Time: five years from now Place: England

Liquibase Version Control For Your Schema. Nathan Voxland April 3,

A TALE OF TWO APPS WHY DEVELOPMENT PRACTICES MATTER

Read & Download (PDF Kindle) Programming: C ++ Programming : Programming Language For Beginners: LEARN IN A DAY! (C++, Javascript, PHP, Python, Sql,

The Art and Science of Memory Allocation

Developing ASP.Net MVC 4 Web Application

Web Programming Step by Step

test with :) chen songyong

The Idiot s Guide to Quashing MicroServices. Hani Suleiman

App Engine: Datastore Introduction

An Incredibly Brief Introduction to Relational Databases: Appendix B - Learning Rails

Lecture 4. Ruby on Rails 1 / 52

Rancher Part 4: Using the Catalog Example with GlusterFS

COURSE 20486B: DEVELOPING ASP.NET MVC 4 WEB APPLICATIONS

Web Application Expectations

Back-end architecture

Rewrite or Refactor. When to declare technical bankruptcy. Laura Thomson OSCON - July 22,

Aspirin as a Service: Using the Cloud to Cure Security Headaches

Web App Vs Web Site. Some tricks of the trade. Laurent Technical Director, BlackBerry Web Platform

Final Report: Faculty Progress Report System Team Deadpool

CS Lab 1: httpd

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

Developing ASP.NET MVC 4 Web Applications

MySQL. The Right Database for GIS Sometimes

Unit Testing J2EE from JRuby. Evan Light

CS 520: VCS and Git. Intermediate Topics Ben Kushigian

Cloud Native Applications. 主讲人 :Capital One 首席工程师 Kevin Hoffman

Working with the Seagull Framework. By Demian Turner, Seagull Systems

Transcript for Episode 3: The Right Tool for the Job

SECURITY AUTOMATION BEST PRACTICES. A Guide on Making Your Security Team Successful with Automation SECURITY AUTOMATION BEST PRACTICES - 1

Crystal for Rubyists

Lecture 4. Ruby on Rails 1 / 49

Continuous Delivery of your infrastructure. Christophe

Enterprise Systems & Frameworks

Git: Distributed Version Control

Reengineering II. Transforming the System

Offline-first PWA con Firebase y Vue.js

ComSpOC: 3D Buildings:

Git: Distributed Version Control

Outline Key Management CS 239 Computer Security February 9, 2004

Transcription:

Keeping Rails on the Tracks Mikel Lindsaar @raasdnil lindsaar.net

Working in Rails & Ruby for 5+ Years http://lindsaar.net/ http://stillalive.com/ http://rubyx.com/

On the Rails? What do I mean by on the rails? Apps that work and are easy to maintain & bug free

Experience helped write, rewrite, support or review 40 production rails last 12 months released a non trivial gem - mail maintained a non trivial gem - tmail made many patches to Rails itself, in the top 20 committers

Working Code? This is the one end of the pragmatic scale Devs that are paid to make it work take the green light, red light approach too far. Is it running? Yes, therefore it is working - leads to messy code

Sexy Code? This is the other end of the pragmatic scale Devs that get upset if something doesn t look right or is not super neat Time wasters on large scale projects Sexy code is nice to have, but often a waste of money

Maintainable Code? This is probably the middle ground Code that works Code that is neat and tidy, but not sacrificing budget for that Code that can be maintained

A Product is Only a Product if it is Exchanged This is pretty critical to all Rails developers.

Budget Matters Beautiful code is ugly if no one buys it

Trade-Offs are Life Decide how much refactoring needed based on code use Touched once a year, or once a month. Refactor the latter

You are not selling code You are selling a solution Running app are what counts Internal or External client doesn t matter

Deployment is a First Class Citizen This has been said by many people - not the first Need to be able to deploy - make it a trivial and repeatable one liner

Server Setup Use Chef / Puppet / whatever Repeatable Configuration Much easier to run a chef recipe that you know will work at 3am than remember how to install postgres

Use Bundler Removes Deployment Pain Be explicit with versions Only lock to git repos you own Not specifying versions in the Gemfile leads to future pain At least limit using the ~> control Lock to your own github fork, and at least specify branch or sha1 Never lock to open versions Edge rails in bundler, seriously!?

Repeatable Deployment Get the staging server up Use common deployment methods capistrano, or ey deploy, or heroku git deploy

Make a db/seeds.rb file Make it easy for other Developers The other developer may be you! In 6 months you will have no idea what you need to get it working

Link in Security Don t store passwords in the app Use some other data store

Using app Gem

Document It Update that README file! Should be able to open the readme and deploy your app Include authorisation needed (ssh keys on server or whatever)

Fast Page == Happy Client

Page Load Times Count Combine Javascript and CSS CSS Sprites Asset Pipelining in Rails 3.1 Before combination: 40 asset requests After combination: 5 asset requests Trivial in Rails 3.1 Rails 3 and lower, Jammit and other tools

Caching Optimisation Know and love Rails view caching: Fragment Cache Action Cache Page Cache Before fragment cache: 2480ms After fragment caching: 120ms

Big Session == Slow Site Session objects are a slippery slope to pain Store values, not objects 10k session record 5,000 new sessions per month 500mb session table in DB

Pick Your Fights Don t make a persisted session cart for every visitor 500,000 rows in sessions table Removed sessions for non customers Appdex went from 10% => 98% row session database store... no fun. File system is just asking for trouble - not scalable If follow previous two advices then overhead is minimal and very scalable

Opinions Matter

Use Pluralization Breaks conventions - hard to code and remember Simple fix using inflectors

Use the idioms

Less code written == less bugs Remove Useless Code

Being Smart can be Stupid

Explicit Methods Don t use before, after and around filters for object instantiation Filters are for state modification Valid uses of filters: timezones, authorization, authentication et al. Reasons: filters inherit, easy to get lost. Use explicit helpers

Keep Tests Simple Computers are good at nesting Humans less so We need to see context, as close to content as possible

Use Helpers Instead before & after should only maintain the test environment Keep tests wet Don t use before and after for app related activities

Hard to read Especially 2 pages down, where you can t see the before block

Easy to Read Easy to read no matter where you are in the test, also less context switching

Simple is better than Complex What you leave out is almost more important than what you put in Meta Programming has its place, that place is probably not in your Rails App Long writing methods better than dynamic if you can get away with it Meta programming has it s place, that place is not

Good Code is Easy to Read Good code might be non trivial to implement But should be trivial to understand. The more bad code you have, the closer you are to a rewrite

Reinvention is Over Rated

Reinventing Controllers Becomes code smell because you need to relearn simple idioms

Reinventing Controllers

Use the right tool for the job

Cucumber is not Unit Testing Making cucumber specs that should be unit tests

You too can refactor 5 level nested ternary INSIDE A STRING - 343 characters, one line Good t-shirt print

You too can refactor

Read Ruby Docs Go and read the standard Ruby documentation online Array, String, Hash, Ennumerator

Databases have feelings too

You don t need database agnostic code Make use of your database features Out of 50 apps, one is migrating DB Use migrations Good for development and testing Bad for production, get into the SQL and make the DB sing

Instantiation is Slow Report run in ruby: 45 minutes Equivalent SQL query: 15 seconds Object instantiation is slow

Use the DB tools you have Migrate legacy data with Active Record: 150 hours PostgreSQL COPY with generated CSV: 74 mins

Don t Share the DB 12 rails apps against one BIG database 12 places for migration files Refactor to API calls and CAS for auth

Code has responsibilities

Beware the Train Wreck Trivial example, but valid, train wrecks also can blow up your database

Control flow is code smell DEMO (control_flow_demo.rb) 85 line 10 if else statement method You can ALWAYS refactor control flow into object messages Cleaner code, easier to read Again, be pragmatic, and pick your fights

How to stay on track? What do I mean by on the rails? Apps that work and are easy to maintain & bug free

Get an Inspection Many consultancies do this Ask for a sample rubyx Inspect Service rubyx.com/services/inspect

Maintainable Code This is probably the middle ground Code that works Code that is neat and tidy, but not sacrificing budget for that Code that can be maintained

Questions? Mikel Lindsaar @raasdnil rubyx.com rubyx.com/services/inspect speakerrate.com/talks/7575