Am 28.09.2016 um 15:58 schrieb Toshihiko Ichida <dogatana@gmail.com>:
It seems that I was out of the track.
Not at all! You broadened the scope of the discussion and showed that there’s a third type of method which at least I did not have in mind. And reminded me of the convention to suffix methods which change (the input?) with a !.
The (more precisely: Matz's) rule is that potentially dangerous
methods have a bang suffix. This often means, that they change state
of the instance (e.g. String#gsub!). Btw. this is also an example for
another type: this is primarily a command (i.e. has side effects) but
also indicates what it did via return value. I would not call it
"Query with side effects" because the side effect is really the
important thing (so it is rather a command) and often the return value
is just ignored.
Kind regards
robert
···
On Wed, Sep 28, 2016 at 4:11 PM, Michael Schwarze <michael@schwarze-web.de> wrote:
Am 28.09.2016 um 15:58 schrieb Toshihiko Ichida <dogatana@gmail.com>:
It seems that I was out of the track.
Not at all! You broadened the scope of the discussion and showed that there’s a third type of method which at least I did not have in mind. And reminded me of the convention to suffix methods which change (the input?) with a !.
> Which would mean that it would be an additional easy "tell" for anyone
reading your code. Plus it enables the extra functionality of chaining, as
others have pointed out.
I am not sure whether chaining is always such a good idea. This can
soon get messy.
I look at it this way: if I return self then whoever uses that method can chain if they want. If they decide to chain.all.the.methods.together.horribly, that's not a good idea. But it's not my fault! They could also use the feature responsibly...