SlideShare a Scribd company logo
Commit.where.not(liked_by: ‘DHH’).reject!




A story about open source, ideas, smells and tastes
               [github.com/claudiob]

 I’m a Senior Software Engineer at GOOD and I’m going to to tell you a story about what I learned from contributing to Rails.
TL;DR
Rails 3    Commit.where(“liked_by <> ‘DHH’”)



Rails 4     Commit.where.not(liked_by: ‘DHH’)

          So since this is a story, I’m going to spoil it and tell you how it ends.
          In Rails 3, ActiveRecord cannot specify negative conditions in a query, so you have to use SQL operators.
          In Rails 4, ‘where’ becomes a chainable method that can be followed by a new not operator to write a negation
Now that you know the end of the story, let’s rewind to its inception.

Most people don’t listen when you say something is annoying, even more if you are a stranger.
But programmers can be more heartful and kind than normal people.
We actually listen to complaints, even when they come from strangers. We empathize!
Commit.where(:liked_by ^ ‘DHH’)

Someone else had a similar feeling and created a gem to avoid SQL fragments.
What’s cool about gems is that you decide if you want to use them or not.
But suggesting this syntax in Rails core… gets rejected: it doesn’t smell or taste right.
DHH may sound harsh but he is telling the truth.
He is inviting us to try harder, to make a better coding world for everyone.

This is the main reason I love open source, because you can follow your instincts and feel human again!
Commit.where_not_like(sha: ‘2F%’)

So a new option came up: introducing where_not.
Well then, why not where_like, where_not_like, where_union etc?
But this would pollute ActiveRecord, a lot!
Commit.where.not(liked_by: ‘DHH’)

                                                                                Commit.where.like(author: ‘cla%’)

Finally, the best idea arrives: keept only one ‘where’ and make it chainable.
Rails 3                                                    where(“author <> ‘DHH’”)

@de75af7 where.not(author: ‘DHH’)

                                                            where.not(‘author = “DHH”’)

                                                            where.not(‘author = ?’, ‘DHH’)

 Rails 3                                                    where(“author like ‘DH%’”)

@de75af7 where.like(author: ‘DH%’)

 Rails 3                                                    where(“author not like ‘DH%’”)

@de75af7 where.not_like(author: ‘DH%’)
 Initially implemented by @amatsuda. Smells almost right…
Rails 3                                                                                               where(“id <> 42”).order(:id)

@de75af7 where.not(id: 42).order(:id)




 …but here’s a gotcha. Using mixins does not smell right.
 Mixins delegate the responsibility to another module instead of making sure the code does what we want.
 And you can write “smelly code” like the where.order(…).not(…) statement.
Rails 3                                                                                               where(“id <> 42”).order(:id)

@de75af7 where.not(id: 42).order(:id)

                                                                                                           where.order(:id).not(id: 42)




 …but here’s a gotcha. Using mixins does not smell right.
 Mixins delegate the responsibility to another module instead of making sure the code does what we want.
 And you can write “smelly code” like the where.order(…).not(…) statement.
So I made a pull request to use a builder class rather than a module.
Rails 3                                                                        where(“id <> 42”)

@de75af7 where.not(id: 42)

 Rails 3                                                                        where(“id > 42”)

                         ???                                                    where.gt(id: 42)

                         ???                                                    where.greater_than(id: 42)

 Rails 3                                                                        where(“id <= 42”)

                         ???                                                    where.lte(id: 42)

                         ???                                                    where.less_than_or_equal(id: 42)
  Moreover, if we start adding inequalities, than why not adding ALL of them?
Sounds right, but it’s not powerful enough, because they only apply to numeric types, while not has more uses.

Funny how a discussion started with “all SQL fragments are annoying” and took us to really understand their power one by one.
Rails 3                                                                                                                                                                         where(“author <> ‘DHH’”)

@de75af7 where.not(author: ‘DHH’)

                                                                                                                                                                                 where.not(‘author = “DHH”’)

                                                                                                                                                                                 where.not(‘author = ?’, ‘DHH’)

 Rails 3                                                                                                                                                                         where(“author like ‘DH%’”)

@de75af7 where.like(author: ‘DH%’)

 Rails 3                                                                                                                                                                         where(“author not like ‘DH%’”)

@de75af7 where.not_like(author: ‘DH%’)
  Which brings us back to evaluate this commit: in this light, where.like and where.not_like look very similar to inequalities: only apply to strings, do not reduce the code.
Rails 3                                                                                                                                                                         where(“author <> ‘DHH’”)

@de75af7 where.not(author: ‘DHH’)

                                                                                                                                                                                 where.not(‘author = “DHH”’)

                                                                                                                                                                                 where.not(‘author = ?’, ‘DHH’)

 Rails 3                                                                                                                                                                         where(“author like ‘DH%’”)

@de75af7 where.like(author: ‘DH%’)

 Rails 3                                                                                                                                                                         where(“author not like ‘DH%’”)

@de75af7 where.not_like(author: ‘DH%’)
  Which brings us back to evaluate this commit: in this light, where.like and where.not_like look very similar to inequalities: only apply to strings, do not reduce the code.
Therefore, not powerful enough to belong to the core!
TL;DR
Rails 3                                                                                                                                                                                                                                     Commit.where(“liked_by <> ‘DHH’”)



Rails 4                                                                                                                                                                                                                                     Commit.where.not(liked_by: ‘DHH’)


In the end, Rails 4 will have where chainable only with .not.

Contributing to Rails is fun, you learn a lot from the process, not only about source code, but about communities and the impact you can make following your instincts and listening to people who express feelings like “being annoyed”.
So, join the movement and contribute to open source!

More Related Content

PDF
Zed's room
PDF
Should you release open source Ruby projects?
PDF
Neverfails
PPT
Pro social anti social behaviour intro
PPTX
The Social Marketing of Sustainable Behaviour
PDF
PPTX
Social Media Behaviour - Nick Burcher - WMG conference Nov 2011
PPT
Ruby on Rails
Zed's room
Should you release open source Ruby projects?
Neverfails
Pro social anti social behaviour intro
The Social Marketing of Sustainable Behaviour
Social Media Behaviour - Nick Burcher - WMG conference Nov 2011
Ruby on Rails

Similar to The pleasure and learning process of contributing to Ruby on Rails (12)

PPTX
Redis Indices (#RedisTLV)
PPT
Rest in Rails
PPTX
Elegant CSS Design In Drupal: LESS vs Sass
PDF
Low-Maintenance Perl
PPTX
Transformational Tricks for RDF.pptx
PPT
Prototype Utility Methods(1)
PDF
Ruby On Rails Introduction
PPTX
Ruby from zero to hero
PDF
Introduction to Perl
PDF
SEO for Developers
DOC
php&mysql with Ethical Hacking
PDF
Hijacking Ruby Syntax in Ruby (RubyConf 2018)
Redis Indices (#RedisTLV)
Rest in Rails
Elegant CSS Design In Drupal: LESS vs Sass
Low-Maintenance Perl
Transformational Tricks for RDF.pptx
Prototype Utility Methods(1)
Ruby On Rails Introduction
Ruby from zero to hero
Introduction to Perl
SEO for Developers
php&mysql with Ethical Hacking
Hijacking Ruby Syntax in Ruby (RubyConf 2018)
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Spectroscopy.pptx food analysis technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Spectroscopy.pptx food analysis technology
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
MIND Revenue Release Quarter 2 2025 Press Release
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
20250228 LYD VKU AI Blended-Learning.pptx
Approach and Philosophy of On baking technology
Understanding_Digital_Forensics_Presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
Ad

The pleasure and learning process of contributing to Ruby on Rails

  • 1. Commit.where.not(liked_by: ‘DHH’).reject! A story about open source, ideas, smells and tastes [github.com/claudiob] I’m a Senior Software Engineer at GOOD and I’m going to to tell you a story about what I learned from contributing to Rails.
  • 2. TL;DR Rails 3 Commit.where(“liked_by <> ‘DHH’”) Rails 4 Commit.where.not(liked_by: ‘DHH’) So since this is a story, I’m going to spoil it and tell you how it ends. In Rails 3, ActiveRecord cannot specify negative conditions in a query, so you have to use SQL operators. In Rails 4, ‘where’ becomes a chainable method that can be followed by a new not operator to write a negation
  • 3. Now that you know the end of the story, let’s rewind to its inception. Most people don’t listen when you say something is annoying, even more if you are a stranger. But programmers can be more heartful and kind than normal people. We actually listen to complaints, even when they come from strangers. We empathize!
  • 4. Commit.where(:liked_by ^ ‘DHH’) Someone else had a similar feeling and created a gem to avoid SQL fragments. What’s cool about gems is that you decide if you want to use them or not.
  • 5. But suggesting this syntax in Rails core… gets rejected: it doesn’t smell or taste right. DHH may sound harsh but he is telling the truth. He is inviting us to try harder, to make a better coding world for everyone. This is the main reason I love open source, because you can follow your instincts and feel human again!
  • 6. Commit.where_not_like(sha: ‘2F%’) So a new option came up: introducing where_not. Well then, why not where_like, where_not_like, where_union etc? But this would pollute ActiveRecord, a lot!
  • 7. Commit.where.not(liked_by: ‘DHH’) Commit.where.like(author: ‘cla%’) Finally, the best idea arrives: keept only one ‘where’ and make it chainable.
  • 8. Rails 3 where(“author <> ‘DHH’”) @de75af7 where.not(author: ‘DHH’) where.not(‘author = “DHH”’) where.not(‘author = ?’, ‘DHH’) Rails 3 where(“author like ‘DH%’”) @de75af7 where.like(author: ‘DH%’) Rails 3 where(“author not like ‘DH%’”) @de75af7 where.not_like(author: ‘DH%’) Initially implemented by @amatsuda. Smells almost right…
  • 9. Rails 3 where(“id <> 42”).order(:id) @de75af7 where.not(id: 42).order(:id) …but here’s a gotcha. Using mixins does not smell right. Mixins delegate the responsibility to another module instead of making sure the code does what we want. And you can write “smelly code” like the where.order(…).not(…) statement.
  • 10. Rails 3 where(“id <> 42”).order(:id) @de75af7 where.not(id: 42).order(:id) where.order(:id).not(id: 42) …but here’s a gotcha. Using mixins does not smell right. Mixins delegate the responsibility to another module instead of making sure the code does what we want. And you can write “smelly code” like the where.order(…).not(…) statement.
  • 11. So I made a pull request to use a builder class rather than a module.
  • 12. Rails 3 where(“id <> 42”) @de75af7 where.not(id: 42) Rails 3 where(“id > 42”) ??? where.gt(id: 42) ??? where.greater_than(id: 42) Rails 3 where(“id <= 42”) ??? where.lte(id: 42) ??? where.less_than_or_equal(id: 42) Moreover, if we start adding inequalities, than why not adding ALL of them?
  • 13. Sounds right, but it’s not powerful enough, because they only apply to numeric types, while not has more uses. Funny how a discussion started with “all SQL fragments are annoying” and took us to really understand their power one by one.
  • 14. Rails 3 where(“author <> ‘DHH’”) @de75af7 where.not(author: ‘DHH’) where.not(‘author = “DHH”’) where.not(‘author = ?’, ‘DHH’) Rails 3 where(“author like ‘DH%’”) @de75af7 where.like(author: ‘DH%’) Rails 3 where(“author not like ‘DH%’”) @de75af7 where.not_like(author: ‘DH%’) Which brings us back to evaluate this commit: in this light, where.like and where.not_like look very similar to inequalities: only apply to strings, do not reduce the code.
  • 15. Rails 3 where(“author <> ‘DHH’”) @de75af7 where.not(author: ‘DHH’) where.not(‘author = “DHH”’) where.not(‘author = ?’, ‘DHH’) Rails 3 where(“author like ‘DH%’”) @de75af7 where.like(author: ‘DH%’) Rails 3 where(“author not like ‘DH%’”) @de75af7 where.not_like(author: ‘DH%’) Which brings us back to evaluate this commit: in this light, where.like and where.not_like look very similar to inequalities: only apply to strings, do not reduce the code.
  • 16. Therefore, not powerful enough to belong to the core!
  • 17. TL;DR Rails 3 Commit.where(“liked_by <> ‘DHH’”) Rails 4 Commit.where.not(liked_by: ‘DHH’) In the end, Rails 4 will have where chainable only with .not. Contributing to Rails is fun, you learn a lot from the process, not only about source code, but about communities and the impact you can make following your instincts and listening to people who express feelings like “being annoyed”. So, join the movement and contribute to open source!