<?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: How much &#8216;less code&#8217; is better?</title>
	<atom:link href="http://nutrun.com/weblog/how-much-less-code-is-better/feed/" rel="self" type="application/rss+xml" />
	<link>http://nutrun.com/weblog/how-much-less-code-is-better/</link>
	<description>nutrun</description>
	<pubDate>Tue, 06 Jan 2009 09:06:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris</title>
		<link>http://nutrun.com/weblog/how-much-less-code-is-better/comment-page-1/#comment-263</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sat, 17 Feb 2007 23:57:51 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=81#comment-263</guid>
		<description>The code is certainly neater, however there is an argument that the interface of User is now unclear - we only know it responds to an administrator? method because there is a role in the data with the name "administrator", and if that role name was to change or the role removed, then the interface to your class would also magically change - with possible undesirable effects on it's clients.

If the concept of these particular roles is required in the domain model, and is actively used by code (such as the client of User which is invoking administrator?), then I feel they should be represented directly in the code, possibly as an enumeration (and then these convenience methods could be defined by iterating over the enumeration).  Of course this then begs the question of why Roles, now of fixed values from an enumeration, would be in the database at all.

If, on the other hand, they are in the database because they are configurable, then it is probably better to not have these convenience methods at all - but rather to provide a single is? or inRole? method that takes a Role object (not a role name).  The client that does care about particular Roles, like administrator, can then obtain the Role object it wants, and then invoke the is? method with that role.  This allows the failure to find a particular role in the data to be indicated at precisely the point where the code is dependant on that role existing.</description>
		<content:encoded><![CDATA[<p>The code is certainly neater, however there is an argument that the interface of User is now unclear - we only know it responds to an administrator? method because there is a role in the data with the name &#8220;administrator&#8221;, and if that role name was to change or the role removed, then the interface to your class would also magically change - with possible undesirable effects on it&#8217;s clients.</p>
<p>If the concept of these particular roles is required in the domain model, and is actively used by code (such as the client of User which is invoking administrator?), then I feel they should be represented directly in the code, possibly as an enumeration (and then these convenience methods could be defined by iterating over the enumeration).  Of course this then begs the question of why Roles, now of fixed values from an enumeration, would be in the database at all.</p>
<p>If, on the other hand, they are in the database because they are configurable, then it is probably better to not have these convenience methods at all - but rather to provide a single is? or inRole? method that takes a Role object (not a role name).  The client that does care about particular Roles, like administrator, can then obtain the Role object it wants, and then invoke the is? method with that role.  This allows the failure to find a particular role in the data to be indicated at precisely the point where the code is dependant on that role existing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony</title>
		<link>http://nutrun.com/weblog/how-much-less-code-is-better/comment-page-1/#comment-262</link>
		<dc:creator>Tony</dc:creator>
		<pubDate>Thu, 15 Feb 2007 18:45:26 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=81#comment-262</guid>
		<description>This is an argument for the use of comments. I know that they went out of fashion some time ago, but absolutism sucks.</description>
		<content:encoded><![CDATA[<p>This is an argument for the use of comments. I know that they went out of fashion some time ago, but absolutism sucks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aníbal Rojas</title>
		<link>http://nutrun.com/weblog/how-much-less-code-is-better/comment-page-1/#comment-261</link>
		<dc:creator>Aníbal Rojas</dc:creator>
		<pubDate>Wed, 14 Feb 2007 21:06:45 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=81#comment-261</guid>
		<description>I understand your point, programmers are not islands and the source code is part of social network.</description>
		<content:encoded><![CDATA[<p>I understand your point, programmers are not islands and the source code is part of social network.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Travis</title>
		<link>http://nutrun.com/weblog/how-much-less-code-is-better/comment-page-1/#comment-260</link>
		<dc:creator>Travis</dc:creator>
		<pubDate>Wed, 14 Feb 2007 20:34:31 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=81#comment-260</guid>
		<description>It's true, 'any competent developer could figure it out' -- The problem is the length of time it takes the developer to figure it out.

I have recently been looking through a lot of code, all which can be 'figured out'.  I keep on thinking that it would be so nice if for each class there was some sort of human readable description that told me in general terms what the class does.  Ah-HA!  Documentation!!

If you were to provide a one or two sentence description of what the &lt;i&gt;clever&lt;/i&gt; code does in human readable terms, then you have gained both cleverness and readability.</description>
		<content:encoded><![CDATA[<p>It&#8217;s true, &#8216;any competent developer could figure it out&#8217; &#8212; The problem is the length of time it takes the developer to figure it out.</p>
<p>I have recently been looking through a lot of code, all which can be &#8216;figured out&#8217;.  I keep on thinking that it would be so nice if for each class there was some sort of human readable description that told me in general terms what the class does.  Ah-HA!  Documentation!!</p>
<p>If you were to provide a one or two sentence description of what the <i>clever</i> code does in human readable terms, then you have gained both cleverness and readability.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Barry</title>
		<link>http://nutrun.com/weblog/how-much-less-code-is-better/comment-page-1/#comment-259</link>
		<dc:creator>Paul Barry</dc:creator>
		<pubDate>Tue, 13 Feb 2007 22:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=81#comment-259</guid>
		<description>I don't think that code is too much magic.  The methods are still defined in the User class.  Any competent developer should be able to figure that out from looking at that code.  It's not like when programming in ruby you have an IDE for you where you could click on "user.customer?" and have it take you to the code where that is defined.

One thing I would be worried about with the above code is name collisions.  For example, what if you add a role called foo and then a method called "foo?".  you might run into some strange errors that are difficult to debug.  Maybe make the auto_generated methods like user.role_customer? to avoid that?

The area where I get really worried about having to much magic in the code is when you have some random code off in some other file that adds methods to a class.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think that code is too much magic.  The methods are still defined in the User class.  Any competent developer should be able to figure that out from looking at that code.  It&#8217;s not like when programming in ruby you have an IDE for you where you could click on &#8220;user.customer?&#8221; and have it take you to the code where that is defined.</p>
<p>One thing I would be worried about with the above code is name collisions.  For example, what if you add a role called foo and then a method called &#8220;foo?&#8221;.  you might run into some strange errors that are difficult to debug.  Maybe make the auto_generated methods like user.role_customer? to avoid that?</p>
<p>The area where I get really worried about having to much magic in the code is when you have some random code off in some other file that adds methods to a class.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
