Code Style Consistency for Shopify’s Decade-Old Codebase

5 minute read Over the course of Shopify's 13-year codebase history, the core platform has never been rewritten. That meant a slew of outdated code styles, piling atop of one another and without a lot of consistency. By 2012, our CEO Tobi created a draft Ruby style guide to keep up with the growth. Unfortunately, it never became embedded in our programming culture and many people didn't even know it existed.

Gabi Stefanini
5 min readbeginner
--
View Original

Overview

The article discusses the challenges of maintaining code style consistency in Shopify's decade-old Ruby codebase and the solutions implemented to address these issues. It highlights the introduction of Policial, a tool built around RuboCop, and the development of a comprehensive Ruby style guide to improve code quality and developer experience.

What You'll Learn

1

How to implement a linter for Ruby code using Policial

2

Why maintaining code style consistency is crucial for large codebases

3

When to use commit status API for code quality checks

Prerequisites & Requirements

  • Understanding of Ruby programming and code style guidelines
  • Familiarity with GitHub and its webhooks(optional)

Key Questions Answered

What is Policial and how does it improve code style consistency?
Policial is a tool that wraps around RuboCop to check code style violations only on pull requests. It comments on lines with violations, helping developers identify and fix issues without overwhelming them with noise, thus improving code consistency in Shopify's codebase.
How did Shopify address the challenges of an outdated codebase?
Shopify addressed the challenges by introducing Policial to manage code style violations and developing a detailed Ruby style guide. They also utilized the commit status API to streamline feedback on pull requests, which helped improve developer engagement and code quality.
What were the results of the survey conducted after implementing Policial?
The survey results indicated that the majority of developers rated their experience with Policial positively. They found that improved code consistency made reading and maintaining code easier, which was particularly beneficial for new developers.
What strategies were used to fix existing code style violations?
To fix existing code style violations, Shopify planned a weekend to push thousands of line changes while preventing disruptions. They also connected to GitHub using a bot to differentiate their fixes from actual code changes, ensuring clarity in the Git history.

Key Statistics & Figures

Percentage of developers opting into Policial
50%
This statistic reflects the initial engagement level of developers with the new tool after its introduction.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Tool
Rubocop
Used for linting Ruby code to enforce style guidelines.
Platform
Github
Utilized for managing pull requests and integrating Policial through webhooks.

Key Actionable Insights

1
Engage developers early in the process of implementing code style tools like Policial.
Involving developers from the beginning helps address their concerns and improves adoption rates, as seen when teams expressed their initial dissatisfaction with Policial's noise.
2
Utilize commit status API to enhance pull request feedback without overwhelming developers.
This approach minimizes noise by providing a clear pass/fail status, which encourages developers to focus on critical issues rather than being distracted by excessive comments.
3
Plan strategically for fixing existing code style violations to avoid disruption.
By scheduling fixes during downtime, Shopify was able to implement necessary changes without affecting ongoing development, demonstrating the importance of timing in such initiatives.

Common Pitfalls

1
Overloading developers with too many comments on pull requests can lead to frustration and disengagement.
This was a significant issue with the initial implementation of Policial, which highlighted the need for a balance between providing feedback and maintaining developer morale.