Commands vs Queries

There are some fascinating discussions going on over on the mailing list for Avdi Grimm’s excellent e-book, Objects on Rails.

Recently, in a discussion about command-query separation and Dan Kubb posted this little piece of beauty:

One convention I use is that query methods are idempotent and return a value, while command methods change state, but they can only return self. This provides a nice fluent interface when working with the objects, and feels quite natural (to me at least).

Feels natural to me too.