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.
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
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!
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!
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.
…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.
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.
= ?’, ‘DHH’) Rails 3 where(“author like ‘DH%’”) where.like(author: ‘DH%’) @de75af7 Rails 3 where(“author not like ‘DH%’”) where.not_like(author: ‘DH%’) @de75af7 Rails 3 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.
= ?’, ‘DHH’) Rails 3 where(“author like ‘DH%’”) where.like(author: ‘DH%’) @de75af7 Rails 3 where(“author not like ‘DH%’”) where.not_like(author: ‘DH%’) @de75af7 Rails 3 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.
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!