#516 — August 27, 2020

Read on the Web

📝 At the end of this week's issue we have a great interview with prolific Rubyist and author of '99 Bottles of OOP', Sandi Metz. Be sure to scroll down and check it out.

🎉 It has also come to my attention that Ruby Weekly is ten years old this week! Thanks for all of your support over the years, including many of you who I know have been subscribed since the very start 😄

Ruby Weekly

The Story of Upgrading GitHub to Ruby 2.7 — GitHub has made a habit of writing about their upgrades, which is great for the rest of us. The move to 2.7 brought some performance gains, as you might expect.

Eileen M. Uchitelle

The Shopify Ruby Style Guide — Shopify, the ecommerce platform, is one of Ruby’s true success stories and they still use it heavily. This is their attempt at defining what Ruby style means to them and may be useful for improving the quality of your code too.

Shopify

Troubleshoot Ruby App Errors and Latency with Datadog APM — Debug and optimize your code by tracing requests across web servers, databases, and services in your environment. Then correlate between distributed request traces, metrics, and logs to troubleshoot issues without switching tools or contexts. Try Datadog APM free.

Datadog sponsor

How Shopify Reduced Storefront Response Times with a Rewrite — Speaking of Shopify, here’s an example where they pulled their storefront out of the monolith and how they tested it in production alongside the legacy app. A great example of how to properly roll out a new version.

Shopify Engineering

The Great Rubykon Benchmark 2020: CRuby vs JRuby vs TruffleRuby — The last benchmark in this series was 3.5 years ago. Rubykon is a Go (the game, not the language) AI written in Ruby, so the results here aren’t representative of web apps, etc., but they’re still interesting.

Tobias Pfeiffer

▶  The NoRuKo Virtual Ruby Conference Videos — Last week we featured NoRuKo, a virtual Ruby conference taking place last Friday. If you missed it, the full streams (not short!) are now on YouTube. If you just want to watch Matz’s Ruby 3 and Beyond keynote, you can do so at 25 minutes in. The video of the community track is also available.

Ruby NL

💻 Jobs

Ruby on Rails Engineer at Five Good Friends (Remote in Australia) — Our mission is to help people live vibrantly in their own homes, connected to their friends and communities, doing what they love.

Five Good Friends

Sr. Engineer @ Dutchie, Remote — Dutchie is the world's largest and fastest growing cannabis marketplace. Backed by Howard Schultz, Thrive, Gron & Casa Verde Capital.

DUTCHIE

Find a Job Through Vettery — Create a profile on Vettery to connect with hiring managers at startups and Fortune 500 companies. It's free for job-seekers.

Vettery

ℹ️ Interested in running a job listing in Ruby Weekly? There's more info here.

📘 Articles & Tutorials

Peter's Adventures in Ruby: Garbage Collection in Ruby — A walk through the C source of the garbage collector that also explains the mark and sweep algorithm it uses. As Peter himself says: “I’ve been working on improving the GC in Ruby for several months now. The GC is pretty complex but also very interesting.”

Peter Zhu

Mortal and Immortal Symbols in Ruby — Did you know that Ruby 2.2 introduced immortal symbols? You could be using some, which has memory and security implications.

Mehdi Farsi

How to Use Bootstrap and jQuery in Rails 6 with Webpacker — jQuery remains one of the most heavily used JavaScript libraries out there, no matter what Twitter says 😄🤷‍♂️

Ruby Yagi

Understanding Selection Sort with Ruby — An intuitive, if often inefficient, way to sort things that can crop up in technical interviews, although you’d rarely implement it by yourself.

Julie Kent

Ruby Trickery from 2018 — Somehow I missed this competition at the time, but this look at some submissions to an arcane (or ‘transcendental’, if you will) programming contest at Ruby Kaigi in 2018 really throw up some headscratchers, including a Ruby program that uses (only) every reserved keyword!

Idiosyncratic Ruby

DHH: 'Rewrite Your Software' — An interview for RubyRussia 2020, DHH discusses when to rewrite, evolve, or your application, touching upon a few other topics along the way.

Hacker Noon

The Basics of Ruby 2.7's 'Beginless Range'

Ashwath Biradar

Best-Practices on How to Speed Up Your Postgres Queries. Free eBook

pganalyze sponsor

Understanding Ruby Blocks — Aimed at beginners. It’s easy to use blocks in various places in Ruby without really thinking about them, but it’s worth knowing how they’re constructed.

Jason Swett

Turning a Rails-based REST API to GraphQL using Hasura Actions — Note that Hasura is a commercial service.

Hasura

🛠 Code and Tools

ActiveRecord::Events: Manage Timestamps in Active Record Models — Adds convenience methods on top of a datetime field so you can manage custom timestamps in a similar way to how Active Record handles the created_at and updated_at fields.

Bartosz Pieńkowski

u-attributes: Create 'Immutable' Objects with No Setters, Just Getters — And if you change an attribute of the object, you’ll have a new object instance.

Rodrigo Serradura

Racecar: A Simple Framework for Kafka Consumers

Zendesk

Rainbow: A Gem for Colorizing Printed Text on ANSI Terminals — e.g. puts Rainbow("this is red").red .. though the API goes further than that with support for backgrounds, underlining, etc. There’s also a refinements based version with a nicer API, e.g. puts "Hi!".green

Marcin Kulik

Faster CI/CD for All Your Software Projects - Try Buildkite ✅ — See how Shopify scaled from 300 to 1800 engineers while keeping their build times under 5 minutes.

Buildkite sponsor

HTTP Headers Verifier: A Way to Verify HTTP Headers — An assertion framework for HTTP headers coming from live endpoints, such as for verifying security policy headers are present.

Avner Cohen

Sandi Metz is a prolific Rubyist and author that has penned two of the most well-received books on object-oriented programming in recent memory. She also speaks, consults, and teaches, giving us almost 99 ways to benefit from her wisdom.

What were the biggest changes incorporated into the 2nd edition of 99 Bottles of OOP?

The 1st Edition used the 99 Bottles problem as a jumping off point to explore a bunch of Object-Oriented (OO) ideas. It generally solved design problems by identifying code smells and following refactoring recipes. It emphasized a concise programming style where the only code you're allowed to write is that which the recipes require. (Note: this is actually a lot more fun than you might imagine.)

Many programmers don't have firsthand experience with how detailed and helpful refactoring recipes are. While the 1st Edition discussed lots of fundamental OO ideas, it's overall emphasis was on satisfying new requirements by determining which parts of the code needed to vary, isolating those parts using refactoring recipes, and then creating new variants to fulfil the requirements.

The 2nd Edition moves up a level of abstraction and addresses programmer volition. It grapples with the "This code works, but I don't think it's good enough" problem. It gives concrete advice about how to decide if making a voluntary change to improve code is justified. The overall theme of the 2nd Edition is loosening coupling to allow for unexpected future change. It thoroughly addresses dependency injection, separating object creation and object use, and following the Law of Demeter, all in service of loose coupling between objects.

What do you think about the more functional bits, like pattern matching, being added to Ruby?

Pattern matching is cool, and good OO is very functional.

If you think of pattern matching as a nicer kind of conditional, then one (cough) might wonder if making conditionals easier to write in Ruby will entice folks to use them in situations where they're better served by creating new objects instead.

This might happen, but we'll recover if it does. Everything I know I figured out by abusing some technique, and then learning from my mistakes. I suspect this will be true for Pattern matching. There are problems for which it's a great solution, and I have confidence that with practice we'll figure out how best to use it.

Are you excited about anything coming in Ruby 3?

Or perhaps everything? The speed and concurrency improvements are amazing. Also, as someone who would love a little magical type safety but finds type declaration syntax distracting, I'm looking forward to built-in support for static analysis tools. The thought that I'll be able to pretty much write Ruby as I always have, but at the same time effortlessly convey the API of a duck type, makes me giddy.

If you could only teach a single principle of OOD, what would it be?

Can I have two? Hmm, now that I think about it, they're really the same thing — One, loose coupling, and two, object ignorance.

By object ignorance I mean an OO programming style where you strive to make objects know as little about one another as possible. In more formal terms this means reducing the number of dependencies in each object. Objects with fewer dependencies know less about their surroundings and so require a smaller context. An object that's context independent can be reused in novel ways.

You can tell how much context an object requires by looking at the setup needed to test it. Piles of setup indicate lots of required context. The object can only be used if the world is just so. Little or no setup indicates that the object is independent of context. These objects are amenable to being used in unexpected situations.

An object that's context independent is loosely coupled to the other parts of your application. The price of loose coupling is that you can't look at the source for any individual object and understand the context in which it's used. The benefit of loose coupling is that changes to the arrangement of groups of objects doesn't break everything in the app.

In my experience, apps always change, frequently in unexpected ways. This means the most cost effective way to write code is to strive for loose coupling everywhere, so you can make a change anywhere.

What's next? Is there a 3rd edition of POODR coming?

I (along with Katrina Owen and TJ Stankus) are still fully occupied with 99 Bottles of OOP. It's already available in Ruby or JavaScript, and we're very close to finishing the PHP edition. Next in the queue is Python.

Once these are complete, we're thinking of taking on a statically typed language (Java, Swift, TypeScript, etc). It's hard to predict how that will turn out, but it'll definitely be interesting to try.

In the next few weeks I'm also recording my Practical Object-Oriented Design course as a series of videos. In late 2019 I committed to drastically reducing my airline flights before 2021 (because planet), and Covid arrived just in time to ensure I fulfilled that promise.

Folks who'd like to keep up with these projects can sign-up for Sandi's Chainline Newsletter or follow her on Twitter.