<?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 - Contracts for delegates - Comments</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates</link>
 <description>Comments for &quot;Contracts for delegates&quot;</description>
 <language>en</language>
<item>
 <title>Just coming back to add</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comment-370</link>
 <description>&lt;p&gt;Just coming back to add another couple of cents to this; I would say that using a variable isn&#039;t the best idea and using static access is better. It&#039;s clear where the feature invariants are taken from, it resolves using attributes/routine parameters using anchored types (This could make assertions differ depending on descending classes), and finally solves any issues when a class attribute/routine parameter is not available. You could argue to provide both ways, but Eiffel&#039;s principles prohibit multifaceted mechanisms unlike our friend Perl :)&lt;/p&gt;

</description>
 <pubDate>Fri, 26 Oct 2007 09:13:07 -0700</pubDate>
 <dc:creator>paulbates</dc:creator>
 <guid isPermaLink="false">comment 370 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Unattached variables not a problem</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comment-364</link>
 <description>&lt;p&gt;It doesn&#039;t matter if the variable is attached or not (for the contract - the body will require a suitable invariant, but that has nothing to do with the contract) - it is the static type of the variable that is used.&lt;/p&gt;

&lt;p&gt;I hadn&#039;t thought about borrowing contracts with a different signature. That is a minefield that I am not eager to explore.&lt;/p&gt;

&lt;p&gt;As for contracts being added or removed from the delegated feature, the whole point of making it a language enhancement is that the delegating class remains correct.&lt;/p&gt;

&lt;p&gt;As for the clients of the delegating class, they are no worse off than if the class itself is edited.&lt;/p&gt;

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

</description>
 <pubDate>Thu, 18 Oct 2007 22:46:28 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 364 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>I&#039;d like it!</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comment-363</link>
 <description>&lt;p&gt;I had a similar idea for a Eiffel-based language compiler I was working on for Lego MINDSTORMS NXT.&lt;/p&gt;

&lt;p&gt;In your example there&#039;s a couple of issues. First you are using a variable/argument to access the conditions. What if the variable is unattached? Are you using the dynamic type or the static type? You cannot use the dynamic type because the client cannot verify the contracts as well as the possibility of &#039;my_object&#039; resting in an detached form. Usage in a form of a static access call instead ensures the the routine &#039;my_feature&#039; is borrowing the contract from is assured and clear.&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;...&lt;br /&gt;
&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;require&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; my_precondition_tag: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#123;&lt;/span&gt;MY_OBJECT&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#125;&lt;/span&gt;.&lt;span style=&quot;color: #000060;&quot;&gt;feature_name&lt;/span&gt;&lt;br /&gt;
..&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;I like the reuse of &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt;&lt;/code&gt;. And I&#039;d never thought about trying to reuse contracts from a feature with a differing signature. However, there are problems in borrowing contracts from features of differing signatures:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;my_feature &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;a: STRING_32; b: &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; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;require&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; my_precondition_tag: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; feature_name&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; res: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; feature_name&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; is_initialized := &lt;span style=&quot;color: #800080;&quot;&gt;True&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; res := feature_name &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;a, &lt;span style=&quot;color: #FF0000;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#123;&lt;/span&gt;MY_TEST&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#125;&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;br /&gt;
&lt;br /&gt;
feature_name &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;a: &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;; b: &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;; c: MY_TEST&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;a href=&quot;http://www.google.com/search?q=site%3Ahttp%3A%2F%2Fdocs.eiffel.com%2Feiffelstudio%2Flibraries+BOOLEAN&amp;btnI=I%27m+Feeling+Lucky&quot;&gt;&lt;span style=&quot;color: #800000&quot;&gt;BOOLEAN&lt;/span&gt;&lt;/a&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; &amp;nbsp; a_is_positive: a &amp;gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; a_is_less_than_b: a &amp;lt; b&lt;br /&gt;
&amp;nbsp; &amp;nbsp; c_attached: c /= &lt;span style=&quot;color: #800080;&quot;&gt;Void&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; b_is_in_range: c.&lt;span style=&quot;color: #000060;&quot;&gt;is_valid_range&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;b&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; is_initialized: is_initialized&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;br /&gt;
&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;The first issue is that &#039;feature_name&#039; has an additional parameter &#039;c&#039;, which must be attached and is used to validate the argument &#039;b&#039;. How can we borrow the contracts for &#039;feature_name&#039; when there is no specification in &#039;my_feature&#039; for it?&lt;/p&gt;

&lt;p&gt;Also, in the above example &#039;feature_name&#039; requires &#039;is_initialized&#039; to be &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;span style=&quot;color: #800080;&quot;&gt;True&lt;/span&gt;&lt;/code&gt; but &#039;my_feature&#039; does not. How do you selectively exclude contracts?&lt;/p&gt;

&lt;p&gt;You might use a tuple to select the contracts you want to borrow:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;my_feature &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;a: STRING_32; b: &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; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;require&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; my_precondition_tag: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; feature_name &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a_is_positive &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;b&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; a_is_less_than_b &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;b, &lt;span style=&quot;color: #FF0000;&quot;&gt;10&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: #FF0000;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;end&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; res: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; feature_name&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; is_initialized := &lt;span style=&quot;color: #800080;&quot;&gt;True&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; res := feature_name &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;a, &lt;span style=&quot;color: #FF0000;&quot;&gt;10&lt;/span&gt;, &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;create&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#123;&lt;/span&gt;MY_TEST&lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#125;&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;&lt;/p&gt;

&lt;p&gt;But with this we are already becoming more verbose, less readable and are not saving a whole lot on typing.&lt;/p&gt;

&lt;p&gt;There&#039;s also the problem that borrowing contracts from &#039;feature_name&#039; might break clients of &#039;my_feature&#039;, if contracts are added or removed from &#039;feature_name&#039;. Unless you keep a vigilant eye on it the contracts of &#039;feature_name&#039;, &#039;my_feature&#039; may be broken unnecessarily or allow invalid state to pass through. This a maintenance nightmare!&lt;/p&gt;

&lt;p&gt;I really like the idea but it requires a lot of thought.&lt;/p&gt;

</description>
 <pubDate>Thu, 18 Oct 2007 10:16:19 -0700</pubDate>
 <dc:creator>paulbates</dc:creator>
 <guid isPermaLink="false">comment 363 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Query renaming must be dealt with also</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comment-362</link>
 <description>&lt;p&gt;Yes, it&#039;s an interesting point. Assuming the delegate is class A, and the delegating class is class B, and both classes A and B inherit from class C, and class A uses a query from class C in one of the preconditions, and class B renames this query, then the expansion of the like precondition will involve using B&#039;s name for the query.&lt;/p&gt;

&lt;p&gt;That isn&#039;t actually a problem. For Manu&#039;s suggestion of a tool solution, it means the tool has to be ever-so-slightly more sophisticated.&lt;/p&gt;

&lt;p&gt;For my language enhancement suggestion, it&#039;s a no-op (that is, it&#039;s just part of the semantics). Colin Adams&lt;/p&gt;

</description>
 <pubDate>Thu, 18 Oct 2007 00:11:23 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 362 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Not maintenance proof</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comment-361</link>
 <description>&lt;p&gt;Yes, that is helpful, but it doesn&#039;t help if the author of the delegate class realizes (s)he made a mistake, and strenghtens the precondition or weakens the postcondition. Of course, this is a more general problem, and my proposal only helps for a small subset of such cases.&lt;/p&gt;

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

</description>
 <pubDate>Thu, 18 Oct 2007 00:06:02 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">comment 361 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Good idea</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comment-359</link>
 <description>&lt;p&gt;We certainly need something like that, but I wonder whether it should be a language change or a tool change. I&#039;m favoring the tool because when you have the call `a.f&#039; and you want to extract the assertions, then in your model you need to make sure that `a&#039; is also available to the client which is not always the case. With a tool, then the tool can basically expand your `like a.f&#039; notation in usable assertions.&lt;/p&gt;

</description>
 <pubDate>Wed, 17 Oct 2007 13:42:44 -0700</pubDate>
 <dc:creator>manus_eiffel</dc:creator>
 <guid isPermaLink="false">comment 359 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>may be problematic</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comment-358</link>
 <description>&lt;p&gt;what about contracts involving queries and not just the feature arguments? just ignore them?&lt;/p&gt;

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

</description>
 <pubDate>Wed, 17 Oct 2007 13:10:27 -0700</pubDate>
 <dc:creator>mtn</dc:creator>
 <guid isPermaLink="false">comment 358 at http://www.eiffelroom.org</guid>
</item>
<item>
 <title>Contracts for delegates</title>
 <link>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates</link>
 <description>&lt;p&gt;Routines that simply forward the request to another object (a delegate) typically have the same signature and contract (possibly strengthened) as the delegate&#039;s routine. In which case it is slightly tedious to write out the duplicate assertions (especially if the delegating routine is using different names for the arguments), and a potential maintenance problem too.&lt;/p&gt;

&lt;p&gt;It appears that there is a simple, problem-free, extension to the assertion syntax to improve this situation - reusing the &lt;code class=&quot;geshifilter eiffel&quot;&gt;&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt;&lt;/code&gt; keyword within assertions.&lt;/p&gt;

&lt;p&gt;The suggested syntax looks like this:&lt;/p&gt;

&lt;p&gt;&lt;div class=&quot;geshifilter eiffel&quot; style=&quot;font-family: monospace;&quot;&gt;my_feature &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;...&lt;span style=&quot;color: #000060;&quot;&gt;signature&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: #008000; font-style: italic;&quot;&gt;-- Delegating feature&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; my_precondition_tag: &lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;like&lt;/span&gt; my_object.&lt;span style=&quot;color: #000060;&quot;&gt;feature_name&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; additional_preconditions: ...&lt;br /&gt;
&lt;span style=&quot;color: #0600FF; font-weight: bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;... &lt;span style=&quot;color: #000060;&quot;&gt;other&lt;/span&gt; code ...&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: #000060;&quot;&gt;my_object&lt;/span&gt;.&lt;span style=&quot;color: #000060;&quot;&gt;feature_name&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;&amp;#40;&lt;/span&gt;...&lt;span style=&quot;color: #000060;&quot;&gt;arguments&lt;/span&gt;-to-`my_feature&lt;span style=&quot;color: #0080A0;&quot;&gt;&#039;...)&lt;br /&gt;
&amp;nbsp;... other_code ...&lt;br /&gt;
ensure&lt;br /&gt;
&amp;nbsp;my_postcondition_tag: like my_object.feature_name&lt;br /&gt;
end&lt;/span&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;It is an error if &lt;code class=&quot;geshifilter eiffel&quot;&gt;`feature_name&lt;span style=&quot;color: #0080A0;&quot;&gt;&#039;&lt;/span&gt;&lt;/code&gt; does not have the same (identical?, conforming?) signature as &lt;code class=&quot;geshifilter eiffel&quot;&gt;`my_object.&lt;span style=&quot;color: #000060;&quot;&gt;feature_name&lt;/span&gt;&lt;span style=&quot;color: #0080A0;&quot;&gt;&#039;&lt;/span&gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The preconditions for &lt;code class=&quot;geshifilter eiffel&quot;&gt;`my_feature&lt;span style=&quot;color: #0080A0;&quot;&gt;&#039;&lt;/span&gt;&lt;/code&gt; are now the same as those of &lt;code class=&quot;geshifilter eiffel&quot;&gt;`my_object.&lt;span style=&quot;color: #000060;&quot;&gt;feature_name&lt;/span&gt;&lt;span style=&quot;color: #0080A0;&quot;&gt;&#039;&lt;/span&gt;&lt;/code&gt; (with appropriate substitution of argument names) plus the additional preconditions declared in &lt;code class=&quot;geshifilter eiffel&quot;&gt;`my_feature&lt;span style=&quot;color: #0080A0;&quot;&gt;&#039;&lt;/span&gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Similarly for the postconditions.&lt;/p&gt;

</description>
 <comments>http://www.eiffelroom.org/blog/colin_adams/contracts_for_delegates#comments</comments>
 <pubDate>Wed, 17 Oct 2007 01:11:33 -0700</pubDate>
 <dc:creator>colin-adams</dc:creator>
 <guid isPermaLink="false">230 at http://www.eiffelroom.org</guid>
</item>
</channel>
</rss>
