<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.eiffelroom.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>eiffelroom - CQS - Comments</title>
 <link>http://www.eiffelroom.org/tag/cqs</link>
 <description>Comments for &quot;CQS&quot;</description>
 <language>en</language>
<item>
 <title>Abstract Side Effect</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-433</link>
 <description>&lt;p&gt;It seems a little vague to speak of abstract side effect without specifying a model.  In this case, I think there is a model and a justification for each positions.  In OOSC, Meyer introduce the random number generator as a traversable object.  In this case, the corresponding model is composed of a sequence of numbers (about which the invariant may state that the numbers have certain probabilistic distribution) and an integer indicating what is the next number to be returned to the user.  In this case, generating a random number is a side effect and, according to CQS principle, should be implemented as a command.&lt;/p&gt;

&lt;p&gt;But another possible model may be only a set of possible numbers or a range of numbers.  In this case, the specification of a routine that generate a random numbers may be non deterministic without ever changing the abstract state of an object.&lt;/p&gt;

&lt;p&gt;An operation which returns a non-deterministic result is a common thing in B but one could argue that B does not have CQS and does not have a need for it since no operation invocation can be performed in expressions.  Back to Eiffel, it certainly is arguable whether non deterministic specification is the right thing for a query but it certainly is legal even according to CQS.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

&lt;p&gt;Simon&lt;/p&gt;

</description>
 <pubDate>Thu, 06 Mar 2008 07:28:33 -0800</pubDate>
 <dc:creator>maverick</dc:creator>
 <guid isPermaLink="false">comment 433 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>My summary</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-238</link>
 <description>&lt;p&gt;Together with my comment &amp;quot;What is the question?&amp;quot;, I think the whole discussion comes down to the question if you agree with the following statement or not:&lt;/p&gt;

&lt;p&gt;&amp;quot;A random number does not mean much by itself; it must be understood in relation to its predecessors and successors in the sequence&amp;quot; (Meyer, OOSC2, p. 755).&lt;/p&gt;

&lt;p&gt;If you agree with the statement, then you should apply CQS also for random numbers like it is described in OOSC2, using &lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;random: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+RANDOM&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;RANDOM&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
...&lt;br /&gt;
&lt;span style=&quot;color: #000060;&quot;&gt;random&lt;/span&gt;.&lt;span style=&quot;color: #000060;&quot;&gt;forth&lt;/span&gt;&lt;br /&gt;
l_item := random.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;If you disagree, then you should be able to write a feature &lt;code class=&quot;geshifilter eiffel&quot;&gt;next_random&lt;/code&gt;. And as soon as you have that, it doesn&#039;t matter how you implement it (therefore you can also implement it using &lt;e&gt;RANDOM&lt;e&gt; or change your implementation later).

I for my part disagree with Meyer&#039;s statement, that&#039;s why I&#039;m using &lt;code class=&quot;geshifilter eiffel&quot;&gt;next_random&lt;/code&gt;. If you agree with the statement, you shouldn&#039;t use the feature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quote from Colin:&lt;/strong&gt;&lt;br /&gt;
 &lt;em&gt;A principle that must be followed without exception is, in effect, a law&lt;/em&gt; &lt;br /&gt;
 I agree, but the quote you gave says &amp;quot;every object-oriented developer SHOULD apply this principle without exception&amp;quot;, not &amp;quot;every object-oriented developer MUST apply this principle without exception&amp;quot; :)&lt;/p&gt;

</description>
 <pubDate>Thu, 10 May 2007 15:05:44 -0700</pubDate>
 <dc:creator>doenniu</dc:creator>
 <guid isPermaLink="false">comment 238 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Selective quoting of OOSC2</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-237</link>
 <description>&lt;p&gt;I am somewhat bemused by the apparent appeal to OOSC2 (as if it were holy scripture) in order to support the case for making random numbers an exception to the CQS principal. This is highly selective quoting.&lt;/p&gt;

&lt;p&gt;For a start, on p. 758, Professor Meyer says: &amp;quot;every object-oriented developer should apply this principle without exception&amp;quot;.&lt;/p&gt;

&lt;p&gt;Even more bemusing is that back on page 754-755, he explicitly gives the example of random numbers.&lt;/p&gt;

&lt;p&gt;A principle that must be followed without exception is, in effect, a law.&lt;/p&gt;

&lt;p&gt;Colin Adams&lt;/p&gt;

</description>
 <pubDate>Thu, 10 May 2007 07:28:50 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 237 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>What is the question?</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-233</link>
 <description>&lt;p&gt;The main principle of the CQS is: Asking a question should not change the answer. But: we&#039;re talking about a random number generator! If I ask for a random number, I WANT a different answer every time I ask.&lt;/p&gt;

&lt;p&gt;Let&#039;s look at the whole thing a little differently: Is it wrong to write a class that gives me a random number every time I ask for one? Certainly not. So my class looks as follows:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;deferred&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; MY_RANDOM&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;feature&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; new_random: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+DOUBLE&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;DOUBLE&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;is&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- returns a random number every time you ask for one&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;deferred&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Now I can have different implementations for &lt;code class=&quot;geshifilter eiffel&quot;&gt;MY_RANDOM&lt;/code&gt;. One might use the current time to give me a random, one might do something else. And: one might even use &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+RANDOM&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;RANDOM&lt;/span&gt;&lt;/a&gt;&lt;/code&gt; to implement &lt;code class=&quot;geshifilter eiffel&quot;&gt;new_random&lt;/code&gt;. Of course, by doing that, it violates CQS (like in the article). So what? The point is that nobody has access to the implementation. That&#039;s the same in the article: Nobody has access to &lt;code class=&quot;geshifilter eiffel&quot;&gt;random_sequence&lt;/code&gt;.&lt;br /&gt;
 So should I not be able to use &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+RANDOM&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;RANDOM&lt;/span&gt;&lt;/a&gt;&lt;/code&gt; to implement &lt;code class=&quot;geshifilter eiffel&quot;&gt;MY_RANDOM&lt;/code&gt;? I think it&#039;s wrong to tell me I shouldn&#039;t be able to use &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+RANDOM&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;RANDOM&lt;/span&gt;&lt;/a&gt;&lt;/code&gt;, just because it&#039;s violating CQS. And I see no difference between implementing &lt;code class=&quot;geshifilter eiffel&quot;&gt;MY_RANDOM&lt;/code&gt; using &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+RANDOM&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;RANDOM&lt;/span&gt;&lt;/a&gt;&lt;/code&gt; and the feature described in the article.&lt;/p&gt;

&lt;p&gt;Another reason I like the approach: With &lt;code class=&quot;geshifilter eiffel&quot;&gt;MY_RANDOM&lt;/code&gt;, you can easily call a feature which takes four random values:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;r: MY_RANDOM&lt;br /&gt;
...&lt;br /&gt;
&lt;span style=&quot;color: #000060;&quot;&gt;initialize&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;r.&lt;span style=&quot;color: #000060;&quot;&gt;new_random&lt;/span&gt;, r.&lt;span style=&quot;color: #000060;&quot;&gt;new_random&lt;/span&gt;, r.&lt;span style=&quot;color: #000060;&quot;&gt;new_random&lt;/span&gt;, r.&lt;span style=&quot;color: #000060;&quot;&gt;new_random&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;How would this feature be called using &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+RANDOM&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;RANDOM&lt;/span&gt;&lt;/a&gt;&lt;/code&gt; without violating CQS? One could store four randoms in four local variables, or store them in an array using a loop for example. Certainly, that&#039;s possible. But readability would suffer extremely from that IMO. And how is one going to change his code to use another random number generator, one that doesn&#039;t use a sequence to produce its random numbers? One would have to change code in lots of places, instead of just one. When I want a random number, I don&#039;t care if the random number is generated by a sequence or not, I just want a random number. That&#039;s exactly what the feature in the article or the class &lt;code class=&quot;geshifilter eiffel&quot;&gt;MY_RANDOM&lt;/code&gt; provides me.&lt;/p&gt;

&lt;p&gt;So, in my opinion, the article does not needed to be removed. Together with the comments, readers will have a good sense of what the problems with the approach might be, and in which cases they should not follow CQS blindly.&lt;/p&gt;

</description>
 <pubDate>Mon, 07 May 2007 11:09:34 -0700</pubDate>
 <dc:creator>doenniu</dc:creator>
 <guid isPermaLink="false">comment 233 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>I made small modifications</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-234</link>
 <description>&lt;p&gt;As an outcome of this discussion I slightly adapted the article: `random_integer&#039; is now called `new_random&#039; and `two_dice&#039; is renamed into `two_new_dice&#039;. All the other content remained unchanged since the first publication.&lt;/p&gt;

&lt;p&gt;After all I think there is a reason why it is called the CQS principle and not the CQS law. I know that some of you feel like this is not enough, but the comment sequence will stay online and the reader can make his own picture.&lt;/p&gt;

&lt;p&gt;Thanks for all the comments!&lt;/p&gt;

&lt;p&gt;-- mTn-_-|&lt;/p&gt;

</description>
 <pubDate>Mon, 07 May 2007 09:36:00 -0700</pubDate>
 <dc:creator>mtn</dc:creator>
 <guid isPermaLink="false">comment 234 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Not for beginners (or experts)</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-231</link>
 <description>&lt;p&gt;Neither performance nor interfacing with low level devices occurs here. In any case, we shouldn&#039;t be teaching beginners to ignore CQS. This article needs removing (then re-written from scratch, perhaps). Colin Adams&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 22:31:20 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 231 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Changing state of Current</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-230</link>
 <description>&lt;p&gt;Calling two_dice changes the  observable state of Current - proof - if you call it again, then you (usually) get a different value. Colin Adams&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 22:28:17 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 230 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Concrete and abstract</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-229</link>
 <description>&lt;p&gt;I don&#039;t see any abstract side effect, Colin. See OOSC2, page 752, under the heading &amp;quot;Functions that create objects&amp;quot;. The `two_dice&#039; function creates, initialises and returns a new TUPLE object. Returning a new object is not a side-effect, concrete or abstract: see &amp;quot;Definition: concrete side effect&amp;quot; on page 749 of OOSC2. The `two_dice&#039; function does not attach the new TUPLE to an &lt;em&gt;attribute&lt;/em&gt;, it simply &lt;em&gt;returns&lt;/em&gt; it.&lt;/p&gt;

&lt;p&gt;Or is this being too sneaky? The fact that &lt;code class=&quot;geshifilter eiffel&quot;&gt;two_dice.&lt;span style=&quot;color: #000060;&quot;&gt;is_equal&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;two_dice&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/code&gt; will return false (well, it will &lt;em&gt;usually&lt;/em&gt; return false) seems to violate &lt;strong&gt;referential transparency&lt;/strong&gt;. (See OOSC2 page 750.)&lt;/p&gt;

&lt;p&gt;Personally I have no qualms about `two_dice&#039;. Given the random nature of `two_dice&#039;, a perfectly reasonable postcondition for it might be:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;ensure&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no_referential_transparency_because_it_is_random: &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&amp;lt;&amp;lt;False, True&amp;gt;&amp;gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000060;&quot;&gt;has&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt;.&lt;span style=&quot;color: #000060;&quot;&gt;is_equal&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;two_dice&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 16:19:42 -0700</pubDate>
 <dc:creator>peter_gummer</dc:creator>
 <guid isPermaLink="false">comment 229 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>It&#039;s not really a problem</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-228</link>
 <description>&lt;p&gt;It&#039;s not really a problem that you did not notice since you knew that the state changed because the feature was named &#039;next_item&#039; which implies that it is not the current item in the sequence but the next. Although the CQS principle was violated, you could use the feature wihtout any problems. The same goes with &#039;random_integer&#039; which actually states that the call to this query is random, but maybe it would better be named &#039;next_random_integer&#039; to be even more obvious.&lt;/p&gt;

&lt;p&gt;I&#039;m not against CQS, but I think it can be justified to ignore it if the code gets more readable or if there are other reasons like performance or interfacing with low level devices.&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 14:24:47 -0700</pubDate>
 <dc:creator>juliant</dc:creator>
 <guid isPermaLink="false">comment 228 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Ah yes, you are right</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-227</link>
 <description>&lt;p&gt;I didn&#039;t notice, which is odd. But that&#039;s exactly the problem - if you write classes that violate CQS, then the clients of those classes may not see that they are changing state. It is very often easier to violate CQS - that does not make it right to do so.&lt;/p&gt;

&lt;p&gt;So my example needs changing to use RANDOM and to do the multiplication. Colin Adams&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 10:32:56 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 227 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>RANGED_RANDOM</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-226</link>
 <description>&lt;p&gt;It&#039;s interesting that you use a helper class RANGED_RANDOM with a feature &#039;next_item_in_range&#039; which clearly violates the CQS. That&#039;s exactly what Martin meant when he said that sometimes it is easier to write/use a helper function which does not bother about CQS...&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 09:18:46 -0700</pubDate>
 <dc:creator>juliant</dc:creator>
 <guid isPermaLink="false">comment 226 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Concrete and abstract</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-225</link>
 <description>&lt;p&gt;Sorry, I forgot the OOSC2 terminiology. In OOSC2 terms, the side effect is both concrete and abstract. Note that in OOSC2 terminiology, all abstract side effects are also concrete, by definition.&lt;/p&gt;

&lt;p&gt;This one is abstract too. That it is, you can observe the difference by calling any of the functions a second time - you will not see the same result, except by lucky coincidence. Colin Adams&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 07:26:20 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 225 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Command-Query Separation principle</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-224</link>
 <description>&lt;p&gt;Colin, you wrote, &amp;quot;the side effect is concrete, not abstract, so it DOES violate CQS.&amp;quot; The definition of the Command-Query Separation principle on page 751 of OOSC2 states, &amp;quot;Functions should not produce abstract side effects.&amp;quot; If we agree that the side effect in `two_dice&#039; is concrete, not abstract, then it doesn&#039;t violate OOSC2&#039;s definition of CQS.&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 06:34:15 -0700</pubDate>
 <dc:creator>peter_gummer</dc:creator>
 <guid isPermaLink="false">comment 224 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Shaking the dice</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-222</link>
 <description>&lt;p&gt;Peter, you are right to say that the cure is worse than the problem. That is always the case with an inline agent, without exception (at least, I&#039;ve never seen one yet).&lt;/p&gt;

&lt;p&gt;As you say, the side effect is concrete, not abstract, so it DOES violate CQS.&lt;/p&gt;

&lt;p&gt;It also does not model the real-world situation accurately.&lt;/p&gt;

&lt;p&gt;In the real world, to get a score from two six-sided dice, we place the two dice in a cup, and shake them. That&#039;s a lot of side effects to get a number, so it does not seem appropriate to try to model this with a mathmatical function.&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;random_number_generator: RANGED_RANDOM&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- Random number generator&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
cup: DS_CELL &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- Cup for shaking two dice&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
shake_two_dice &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;a_cup: DS_CELL &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt;; a_generator: RANGED_RANDOM&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;is&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- Roll two dice making the result available in `cup&#039;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;require&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; a_cup_not_void: a_cup /= &lt;span style=&quot;color: #800080;&quot;&gt;Void&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; a_cup_empty: a_cup.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt; = &lt;span style=&quot;color: #800080;&quot;&gt;Void&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; random_number_generator_not_void: a_generator /= &lt;span style=&quot;color: #800080;&quot;&gt;Void&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;local&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;l_first, l_second: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; l_first := random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;next_item_in_range&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; l_second := random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;next_item_in_range&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; a_cup.&lt;span style=&quot;color: #000060;&quot;&gt;put&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;l_first + l_second&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;ensure&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; dice_roll_result_in_cup: a_cup.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt; /= &lt;span style=&quot;color: #800080;&quot;&gt;Void&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;print_dice_roll &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;is&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- Roll two six-sided dice and print result.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;create&lt;/span&gt; cup.&lt;span style=&quot;color: #000060;&quot;&gt;make&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #800080;&quot;&gt;Void&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;create&lt;/span&gt; random_number_generator.&lt;span style=&quot;color: #000060;&quot;&gt;make_default&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;shake_two_dice &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;cup, random_number_generator&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;print &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;cup.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt;.&lt;span style=&quot;color: #000060;&quot;&gt;out&lt;/span&gt; + &lt;span style=&quot;color: #0080A0;&quot;&gt;&amp;quot;&lt;span style=&quot;color: #005070; font-weight: bold;&quot;&gt;%N&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;/div&gt; Colin Adams&lt;/p&gt;

</description>
 <pubDate>Thu, 03 May 2007 00:17:24 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 222 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Command-Query Separation principle</title>
 <link>http://www.eiffelroom.org/article/random_numbers#comment-221</link>
 <description>&lt;p&gt;We all agree that the `random_integer&#039; function violates CQS. To my mind, it does so unnecessarily. As an old-time C programmer, its use in the lesson feels ok to me; but reason and experience tell me it&#039;s a bad thing to do, so I would not do it. We can rewrite the `two_dice&#039; function to adhere to CQS, eliminating the side-effect confusion, while keeping it reasonably concise:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;two_dice: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+TUPLE&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;TUPLE&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;, &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- A new tuple containing two unrelated random numbers between 1 and 6.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;forth&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt; := random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt; \\ &lt;span style=&quot;color: #FF0000;&quot;&gt;6&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;forth&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt; := random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt; \\ &lt;span style=&quot;color: #FF0000;&quot;&gt;6&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;There&#039;s a bit of code duplication here, unfortunately. We can get rid of the duplication with a really funky in-line agent:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;two_dice: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+TUPLE&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;TUPLE&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;, &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- A new tuple containing two unrelated random numbers between 1 and 6.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt; |..| &lt;span style=&quot;color: #FF0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000060;&quot;&gt;do_all&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;agent&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;dice: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; two_dice; index: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;forth&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dice &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;index&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt; := random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt; \\ &lt;span style=&quot;color: #FF0000;&quot;&gt;6&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt;, ?&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Hmmm, the cure might be worse than the code duplication it was intended to fix! But note that the agent is a command, so unlike the lesson&#039;s `random_integer&#039; function it doesn&#039;t violate CQS. We could extract the inline agent to a separate routine:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;two_dice: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+TUPLE&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;TUPLE&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;, &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- A new tuple containing two unrelated random numbers between 1 and 6.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; add_die &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; add_die &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #800080;&quot;&gt;Result&lt;/span&gt;, &lt;span style=&quot;color: #FF0000;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; add_die &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;dice: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; two_dice; index: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+INTEGER&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;INTEGER&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #008000; font-style: italic;&quot;&gt;-- Add a random number between 1 and 6 to `dice&#039; at `index&#039;.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;forth&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dice &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;index&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt; := random_sequence.&lt;span style=&quot;color: #000060;&quot;&gt;item&lt;/span&gt; \\ &lt;span style=&quot;color: #FF0000;&quot;&gt;6&lt;/span&gt; + &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;This is nicer.&lt;/p&gt;

&lt;p&gt;But the `two_dice&#039; function still has a side-effect on `random_sequence&#039;. Is this a violation of CQS? It depends on whether `random_sequence&#039; is part of the &lt;em&gt;abstract state&lt;/em&gt; of this class. The lesson places it in the implementation, so I think `two_dice&#039; is ok: it&#039;s a concrete side-effect, not an abstract one, so it doesn&#039;t violate CQS.&lt;/p&gt;

</description>
 <pubDate>Wed, 02 May 2007 17:50:43 -0700</pubDate>
 <dc:creator>peter_gummer</dc:creator>
 <guid isPermaLink="false">comment 221 at http://www.eiffelroom.org</guid>
</item>
</channel>
</rss>
