Ruby OO – Tea-Driven Development https://blog.mattwynne.net Matt Wynne taking it one tea at a time Wed, 21 Aug 2019 12:54:39 +0000 en-US hourly 1 https://wordpress.org/?v=6.2 165828820 Commands vs Queries https://blog.mattwynne.net/2012/02/22/commands-vs-queries/ https://blog.mattwynne.net/2012/02/22/commands-vs-queries/#comments Wed, 22 Feb 2012 10:43:17 +0000 http://blog.mattwynne.net/?p=331 Continue reading "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.

]]>
https://blog.mattwynne.net/2012/02/22/commands-vs-queries/feed/ 2 331