---
title: intention
teaser:
tags: web,rails
author: Jared Carroll
published_on: 2007-07-16
---

Now conditional logic asks questions, which sucks, but its always still in code
([try to get rid of it
though](https://thoughtbot.com/blog/coding-without-ifs)).  In Ruby, we have the
ability to use the `?` in method names e.g. `#empty?`, `#has_key?`, etc.  I'm to
the point now where I want to see a `?` method in every conditional.

I don't want to see some condition like:

    if group_membership.group_membership_type == 'Admin'
    end

I want this:

    if group_membership.admin?
    end

I'm not arguing for the sake of DRYness either, even though it is DRYer because
you'll probably duplicate this code...

    group_membership.group_membership_type == 'Admin'

...in a couple places.  But even if the condition is only in 1 place, I still
say refactor it into a query method.

My argument is for clarity and understandability.  Why keep a cryptic
conditional, when you can put that conditional behind a nice intention revealing
message.  Especially since Ruby allows the '?' character in method names, now
you can get even closer to normal language.  Ruby aside, this refactoring is
applicable in any language.

[Fowler](http://www.martinfowler.com/) has a refactoring in his catalog related
to this: [Introduce Explaining
Variable](http://refactoring.com/catalog/extractVariable.html)
which is basically a rehash of some ideas found in
[here](http://www.amazon.com/Smalltalk-Best-Practice-Patterns-Kent/dp/013476904X/ref=sr_1_1/179-8855906-4593233)
