<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Scala Goodness: Structural Typing</title>
	<atom:link href="http://codemonkeyism.com/scala-goodness-structural-typing/feed/" rel="self" type="application/rss+xml" />
	<link>http://codemonkeyism.com/scala-goodness-structural-typing/</link>
	<description></description>
	<lastBuildDate>Fri, 30 Jul 2010 06:49:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Scala traits &#171; Jgoday&#39;s Blog</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-271502</link>
		<dc:creator>Scala traits &#171; Jgoday&#39;s Blog</dc:creator>
		<pubDate>Tue, 16 Feb 2010 22:10:52 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-271502</guid>
		<description>[...] references: http://markthomas.info/blog/?p=92 http://codemonkeyism.com/scala-goodness-structural-typing/  42.487982 [...]</description>
		<content:encoded><![CDATA[<p>[...] references: <a href="http://markthomas.info/blog/?p=92" rel="nofollow">http://markthomas.info/blog/?p=92</a> <a href="http://codemonkeyism.com/scala-goodness-structural-typing/" rel="nofollow">http://codemonkeyism.com/scala-goodness-structural-typing/</a>  42.487982 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269307</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 04 Feb 2010 07:50:07 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269307</guid>
		<description>@Cedric: You might be right, I still have the gut feeling thecoupling is less, but as I&#039;ve said on Debashis blog:

&quot;The evolution problem of Java interfaces still applies. If you ever only need one method on which Payroll depends, then your Java interface also only needs on method. If the interface needs more methods, most probalby because of the Payroll, then evidently you depend on more than one and all the workers need to change also.&quot;

Some more thoughts:

&quot;Structural typing also introduces couplings of its own: suppose both A and B have close() and you rename the one in A: you now have to rename close() in B as well.&quot;

With interfaces and structural typing you cannot change method names in the dependent class, or it won&#039;t compile (or you would need as you&#039;ve said, change all names). So this it not &quot;coupling of it&#039;s own&quot; I think.

Three packages A,B,C
A contains the interface
B contains the class
C uses the interface

B -&gt; A
C -&gt; A,B

A contains the class
B uses structural typing

B -&gt; A

&quot;It also introduces indeterminism in automatic renamings for similar reasons.&quot;

This surely is a problem, I often blogged about dynamic languages (e.g. Ruby). You need a runtime sniffer to detect such dependencies for safer refactoring.

Structural typing borders on &quot;respond_to?&quot; in Ruby (but with the benefit of compile time checking) and - if you do not think about what you do - will lead to brittle classes.</description>
		<content:encoded><![CDATA[<p>@Cedric: You might be right, I still have the gut feeling thecoupling is less, but as I&#8217;ve said on Debashis blog:</p>
<p>&#8220;The evolution problem of Java interfaces still applies. If you ever only need one method on which Payroll depends, then your Java interface also only needs on method. If the interface needs more methods, most probalby because of the Payroll, then evidently you depend on more than one and all the workers need to change also.&#8221;</p>
<p>Some more thoughts:</p>
<p>&#8220;Structural typing also introduces couplings of its own: suppose both A and B have close() and you rename the one in A: you now have to rename close() in B as well.&#8221;</p>
<p>With interfaces and structural typing you cannot change method names in the dependent class, or it won&#8217;t compile (or you would need as you&#8217;ve said, change all names). So this it not &#8220;coupling of it&#8217;s own&#8221; I think.</p>
<p>Three packages A,B,C<br />
A contains the interface<br />
B contains the class<br />
C uses the interface</p>
<p>B -> A<br />
C -> A,B</p>
<p>A contains the class<br />
B uses structural typing</p>
<p>B -> A</p>
<p>&#8220;It also introduces indeterminism in automatic renamings for similar reasons.&#8221;</p>
<p>This surely is a problem, I often blogged about dynamic languages (e.g. Ruby). You need a runtime sniffer to detect such dependencies for safer refactoring.</p>
<p>Structural typing borders on &#8220;respond_to?&#8221; in Ruby (but with the benefit of compile time checking) and &#8211; if you do not think about what you do &#8211; will lead to brittle classes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cedric</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269277</link>
		<dc:creator>Cedric</dc:creator>
		<pubDate>Thu, 04 Feb 2010 01:24:51 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269277</guid>
		<description>Mmmh... can you elaborate?

Structural typing couples you to a method name while the others couple you to a class, not sure it&#039;s such a huge gain.

Structural typing also introduces couplings of its own: suppose both A and B have close() and you rename the one in A: you now have to rename close() in B as well.

It also introduces indeterminism in automatic renamings for similar reasons.</description>
		<content:encoded><![CDATA[<p>Mmmh&#8230; can you elaborate?</p>
<p>Structural typing couples you to a method name while the others couple you to a class, not sure it&#8217;s such a huge gain.</p>
<p>Structural typing also introduces couplings of its own: suppose both A and B have close() and you rename the one in A: you now have to rename close() in B as well.</p>
<p>It also introduces indeterminism in automatic renamings for similar reasons.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269253</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 03 Feb 2010 21:14:45 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269253</guid>
		<description>@Cedric: They are not beaten by coupling, all of the others (interfaces, abstract classes, traits) have tighter coupling (only worse is class inheritance).

The API book was really an eye opener for me, I still love interfaces, but I&#039;m aware of their dangers.

But thanks for commenting, I value your opinion very highly.</description>
		<content:encoded><![CDATA[<p>@Cedric: They are not beaten by coupling, all of the others (interfaces, abstract classes, traits) have tighter coupling (only worse is class inheritance).</p>
<p>The API book was really an eye opener for me, I still love interfaces, but I&#8217;m aware of their dangers.</p>
<p>But thanks for commenting, I value your opinion very highly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cedric</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269244</link>
		<dc:creator>Cedric</dc:creator>
		<pubDate>Wed, 03 Feb 2010 19:34:04 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269244</guid>
		<description>Stephan,

Basically, I think the only reasonable options here are interfaces, abstract classes and traits.

Structural types have are beaten by each of these three options on different criteria and I don&#039;t really think they have their place in code that is longer than ten lines.</description>
		<content:encoded><![CDATA[<p>Stephan,</p>
<p>Basically, I think the only reasonable options here are interfaces, abstract classes and traits.</p>
<p>Structural types have are beaten by each of these three options on different criteria and I don&#8217;t really think they have their place in code that is longer than ten lines.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269231</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 03 Feb 2010 17:17:49 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269231</guid>
		<description>That said, you might run in the same problems with structural typing as with method declarations in XML or Strings (like AOP does for example, or Spring).</description>
		<content:encoded><![CDATA[<p>That said, you might run in the same problems with structural typing as with method declarations in XML or Strings (like AOP does for example, or Spring).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269230</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 03 Feb 2010 17:16:35 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269230</guid>
		<description>@Cedric: I know your post[1]  ;-) Basically everyone does. 

I still disagree with you

- DRY: Use a type alias
- Semantic problems also exist with interfaces

As a developer one needs to decide when to use interfaces, abstract classes, traits, structural typing.

After reading the excellent &quot;Practical API Design: Confessions of a Java Framework Architect&quot; I realized 90% of Java developers don&#039;t know what they do when they design an API and decide between interfaces and abstract classes.

[1] The second comment was from me</description>
		<content:encoded><![CDATA[<p>@Cedric: I know your post[1]  ;-) Basically everyone does. </p>
<p>I still disagree with you</p>
<p>- DRY: Use a type alias<br />
- Semantic problems also exist with interfaces</p>
<p>As a developer one needs to decide when to use interfaces, abstract classes, traits, structural typing.</p>
<p>After reading the excellent &#8220;Practical API Design: Confessions of a Java Framework Architect&#8221; I realized 90% of Java developers don&#8217;t know what they do when they design an API and decide between interfaces and abstract classes.</p>
<p>[1] The second comment was from me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cedric</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269229</link>
		<dc:creator>Cedric</dc:creator>
		<pubDate>Wed, 03 Feb 2010 17:04:04 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269229</guid>
		<description>Structural typing is bad, mmmkay?

Here is why:

http://beust.com/weblog/2008/02/11/structural-typing-vs-duck-typing/</description>
		<content:encoded><![CDATA[<p>Structural typing is bad, mmmkay?</p>
<p>Here is why:</p>
<p><a href="http://beust.com/weblog/2008/02/11/structural-typing-vs-duck-typing/" rel="nofollow">http://beust.com/weblog/2008/02/11/structural-typing-vs-duck-typing/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269220</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 03 Feb 2010 15:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269220</guid>
		<description>@Zach: Thanks for the code, fixed it in your comment</description>
		<content:encoded><![CDATA[<p>@Zach: Thanks for the code, fixed it in your comment</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach Cox</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269219</link>
		<dc:creator>Zach Cox</dc:creator>
		<pubDate>Wed, 03 Feb 2010 15:35:34 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269219</guid>
		<description>Wow that using method got all messed up in my last comment, see this instead:

http://gist.github.com/293666</description>
		<content:encoded><![CDATA[<p>Wow that using method got all messed up in my last comment, see this instead:</p>
<p><a href="http://gist.github.com/293666" rel="nofollow">http://gist.github.com/293666</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach Cox</title>
		<link>http://codemonkeyism.com/scala-goodness-structural-typing/comment-page-1/#comment-269216</link>
		<dc:creator>Zach Cox</dc:creator>
		<pubDate>Wed, 03 Feb 2010 15:05:16 +0000</pubDate>
		<guid isPermaLink="false">http://codemonkeyism.com/?p=1575#comment-269216</guid>
		<description>I particularly like the use of structural typing in the &quot;using&quot; control structure from Beginning Scala chapter 4:

&lt;pre class=&quot;code&quot;&gt;
def using[A &lt;: {def close(): Unit}, B]
  (param: A)(f: A =&gt; B): B = 
  
  try {
    f(param)
  } finally {
    param.close()
  }
&lt;/pre&gt;

Now you can safely use any object with a close() method and be assured it will be closed when you&#039;re done.  A lot of Java classes implement the java.io.Closeable interface, but many do not (JDBC&#039;s Connection, Statement and ResultSet are a few).

val conn: Connection = ...
using (conn) { conn =&gt; //do stuff with conn and it&#039;ll get closed }

using (new BufferedReader(new FileReader(&quot;file&quot;)) { reader =&gt; //do stuff with reader and it&#039;ll get closed }

using (new PrintWriter(new FileWriter(&quot;file&quot;)) { writer =&gt; //do stuff with writer and it&#039;ll get closed }

Structural types used to not be thread-safe: https://lampsvn.epfl.ch/trac/scala/ticket/1006, but apparently this has been fixed.  Not sure if it&#039;s fixed in 2.7 or just 2.8?

(Stephan: Fixed displayed code)</description>
		<content:encoded><![CDATA[<p>I particularly like the use of structural typing in the &#8220;using&#8221; control structure from Beginning Scala chapter 4:</p>
<pre class="code">
def using[A < : {def close(): Unit}, B]
  (param: A)(f: A => B): B = 

  try {
    f(param)
  } finally {
    param.close()
  }
</pre>
<p>Now you can safely use any object with a close() method and be assured it will be closed when you&#8217;re done.  A lot of Java classes implement the java.io.Closeable interface, but many do not (JDBC&#8217;s Connection, Statement and ResultSet are a few).</p>
<p>val conn: Connection = &#8230;<br />
using (conn) { conn =&gt; //do stuff with conn and it&#8217;ll get closed }</p>
<p>using (new BufferedReader(new FileReader(&#8220;file&#8221;)) { reader =&gt; //do stuff with reader and it&#8217;ll get closed }</p>
<p>using (new PrintWriter(new FileWriter(&#8220;file&#8221;)) { writer =&gt; //do stuff with writer and it&#8217;ll get closed }</p>
<p>Structural types used to not be thread-safe: <a href="https://lampsvn.epfl.ch/trac/scala/ticket/1006" rel="nofollow">https://lampsvn.epfl.ch/trac/scala/ticket/1006</a>, but apparently this has been fixed.  Not sure if it&#8217;s fixed in 2.7 or just 2.8?</p>
<p>(Stephan: Fixed displayed code)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 15/21 queries in 0.010 seconds using disk

Served from: codemonkeyism.com @ 2010-07-30 12:31:45 -->