I'm a Floridian web engineer who planted his roots in Paris. Some of my favorite past-times are analyzing and optimizing development processes, building solid APIs, mentoring junior devs, and long walks on the beach.

Names n Stuff

A few days ago, where I work, there was an argument over whether the following function should exist:


def is_premium_or_has_receipt_for?(product)
  self.premium_member? || self.store.has_receipt?(product)
end

I had a hard time explaining myself as to why I thought the function should not exist. At first all I could think of was, "This seems like a bad idea." Then I ran into a similar piece of code today and it became clear to me.

The function should exist, but there is a problem with the name. It simply restates what the logic is. When writing functions one of the benefits is that it allows you to group a bunch of smaller ideas into a bigger one. In this scenario we are merely re-writing an if clause in a prettier fashion; But the lines of code together are conveying a higher level idea. What the function is actually saying is "return true if the user has access to the following product".

So the function should look something like:


can_use_product? product