<?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: Your code smells!!!</title>
	<atom:link href="http://theshyam.com/2008/08/your-code-smells/feed/" rel="self" type="application/rss+xml" />
	<link>http://theshyam.com/2008/08/your-code-smells/</link>
	<description>Thoughts and factoids from the Real Shyam. You know, unlike those fake ones!!</description>
	<lastBuildDate>Wed, 21 Apr 2010 17:05: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: shyamseshadri</title>
		<link>http://theshyam.com/2008/08/your-code-smells/comment-page-1/#comment-13</link>
		<dc:creator>shyamseshadri</dc:creator>
		<pubDate>Fri, 22 Aug 2008 20:20:09 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=35#comment-13</guid>
		<description>Oh, I don&#039;t say, no comments in source code. Again, Class level and method level comments are essential in any code base. All Point 1 says is if you need comments to explain the internal workings of any method, you are probably doing something wrong. Again, this is not a hard fast rule, but rather a guidance and something to watch out for if this seems to be happening more often than not.</description>
		<content:encoded><![CDATA[<p>Oh, I don&#8217;t say, no comments in source code. Again, Class level and method level comments are essential in any code base. All Point 1 says is if you need comments to explain the internal workings of any method, you are probably doing something wrong. Again, this is not a hard fast rule, but rather a guidance and something to watch out for if this seems to be happening more often than not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael L</title>
		<link>http://theshyam.com/2008/08/your-code-smells/comment-page-1/#comment-12</link>
		<dc:creator>Michael L</dc:creator>
		<pubDate>Thu, 21 Aug 2008 21:55:07 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=35#comment-12</guid>
		<description>Well I usually do not comment code that is strait forward and easy to user stand. Now that I think about it, point one is saying if you code is so complicated that you need a lot of comments to explain what is going on, then this is bad sign since if you can do the same thing with more simple version that is better and improves maintainability of software. But saying &quot;no comments in source code&quot; is not a good idea ether because sometimes you have to go the complicated route. Also if I am looking a piece of code, sometimes the names of classes and functions make sense to the developers that write them, but when you show them to someone else might make no sense at all.  In fact I do many code reviews, and sometimes the names make no sense to me, since they have acronyms in the names.  So comments in that case would help a lot to a person who does not know those acronyms.</description>
		<content:encoded><![CDATA[<p>Well I usually do not comment code that is strait forward and easy to user stand. Now that I think about it, point one is saying if you code is so complicated that you need a lot of comments to explain what is going on, then this is bad sign since if you can do the same thing with more simple version that is better and improves maintainability of software. But saying &#8220;no comments in source code&#8221; is not a good idea ether because sometimes you have to go the complicated route. Also if I am looking a piece of code, sometimes the names of classes and functions make sense to the developers that write them, but when you show them to someone else might make no sense at all.  In fact I do many code reviews, and sometimes the names make no sense to me, since they have acronyms in the names.  So comments in that case would help a lot to a person who does not know those acronyms.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shyamseshadri</title>
		<link>http://theshyam.com/2008/08/your-code-smells/comment-page-1/#comment-10</link>
		<dc:creator>shyamseshadri</dc:creator>
		<pubDate>Thu, 21 Aug 2008 21:34:34 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=35#comment-10</guid>
		<description>I don&#039;t say, do away with comments. I agree, especially class level and method level comments are essential in outlining what the code is doing. What I am saying though, is if you need to comment what a particular block of code is doing, your code is not self explanatory and could probably do with good naming. Also, pulling it out into a separate method of its own with good documentation on the method level is probably aeons better than writing some comments inside the code there itself. For one, it allows you to reuse it, and two, it allows you to test that snippet in separate.

&lt;strong&gt;For example, this is what I meant by too many comments is a code smell :&lt;/strong&gt;

&lt;code&gt;double getProjectSkipAverage(String projectName) {
  List data = new ArrayList();
  // If local cache is initialized and it contains the project info
  if (localcache != null &amp;&amp; localcache.contains(projectName) {
    data = localcache.get(projectName).getData();
  }
  // If not enough results, get it from the database
  if (data.length() &lt; 5) {
    Datastore datastore = DatastoreFactory.getInstance();
    data = datastore.query(&quot;Name=&quot; + projectName).getResults();
  }
  // If still no results, return 0
  if (data.length() == 0) {
    return 0;
  }

  // Otherwise, do a skipping sum, skipping each alternate value
  int sum = 0;
  for(int i = 0; i &lt; data.length; i+= 2) {
    sum += data.get(i);
  }

  // return the average
  return sum / data.length();
}&lt;/code&gt;

&lt;strong&gt;Whereas you could do this instead :&lt;/strong&gt;

&lt;code&gt;

// Documentation here
double getSkipAverage(List data) {
  if (data.length() == 0) {
    return 0;
  }

  int sum = 0;
  for(int i = 0; i &lt; data.length; i+= 2) {
    sum += data.get(i);
  }

  return sum / data.length();
}

List getDataFromCache(Cache localcache,
    String projectName) {
   if (localcache != null &amp;&amp; localcache.contains(projectName) {
    return localcache.get(projectName).getData();
  }
  return new List();
}

List getDataFromDatastore(String projectName) {
    Datastore datastore = DatastoreFactory.getInstance();
    return datastore.query(&quot;Name=&quot; + projectName).getResults();
}

double getSkipAverage(String projectName) {
   List data = getDataFromCache(localcache,
       projectName);

   if (data.length &lt; 5) {
      data = getDataFromDatastore(projectName);
   }

   return getSkipAverage(data);
}
&lt;/code&gt;

Now each of these methods can and should have documentation at the method level, and each of them are nice small easy to test methods in and by itself. This is what I prefer, any day.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t say, do away with comments. I agree, especially class level and method level comments are essential in outlining what the code is doing. What I am saying though, is if you need to comment what a particular block of code is doing, your code is not self explanatory and could probably do with good naming. Also, pulling it out into a separate method of its own with good documentation on the method level is probably aeons better than writing some comments inside the code there itself. For one, it allows you to reuse it, and two, it allows you to test that snippet in separate.</p>
<p><strong>For example, this is what I meant by too many comments is a code smell :</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:425px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">double getProjectSkipAverage(String projectName) {<br />
&nbsp; List data = new ArrayList();<br />
&nbsp; // If local cache is initialized and it contains the project info<br />
&nbsp; if (localcache != null &amp;amp;&amp;amp; localcache.contains(projectName) {<br />
&nbsp; &nbsp; data = localcache.get(projectName).getData();<br />
&nbsp; }<br />
&nbsp; // If not enough results, get it from the database<br />
&nbsp; if (data.length() &amp;lt; 5) {<br />
&nbsp; &nbsp; Datastore datastore = DatastoreFactory.getInstance();<br />
&nbsp; &nbsp; data = datastore.query(&quot;Name=&quot; + projectName).getResults();<br />
&nbsp; }<br />
&nbsp; // If still no results, return 0<br />
&nbsp; if (data.length() == 0) {<br />
&nbsp; &nbsp; return 0;<br />
&nbsp; }<br />
<br />
&nbsp; // Otherwise, do a skipping sum, skipping each alternate value<br />
&nbsp; int sum = 0;<br />
&nbsp; for(int i = 0; i &amp;lt; data.length; i+= 2) {<br />
&nbsp; &nbsp; sum += data.get(i);<br />
&nbsp; }<br />
<br />
&nbsp; // return the average<br />
&nbsp; return sum / data.length();<br />
}</div></td></tr></tbody></table></div>
<p><strong>Whereas you could do this instead :</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:425px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">// Documentation here<br />
double getSkipAverage(List data) {<br />
&nbsp; if (data.length() == 0) {<br />
&nbsp; &nbsp; return 0;<br />
&nbsp; }<br />
<br />
&nbsp; int sum = 0;<br />
&nbsp; for(int i = 0; i &amp;lt; data.length; i+= 2) {<br />
&nbsp; &nbsp; sum += data.get(i);<br />
&nbsp; }<br />
<br />
&nbsp; return sum / data.length();<br />
}<br />
<br />
List getDataFromCache(Cache localcache,<br />
&nbsp; &nbsp; String projectName) {<br />
&nbsp; &nbsp;if (localcache != null &amp;amp;&amp;amp; localcache.contains(projectName) {<br />
&nbsp; &nbsp; return localcache.get(projectName).getData();<br />
&nbsp; }<br />
&nbsp; return new List();<br />
}<br />
<br />
List getDataFromDatastore(String projectName) {<br />
&nbsp; &nbsp; Datastore datastore = DatastoreFactory.getInstance();<br />
&nbsp; &nbsp; return datastore.query(&quot;Name=&quot; + projectName).getResults();<br />
}<br />
<br />
double getSkipAverage(String projectName) {<br />
&nbsp; &nbsp;List data = getDataFromCache(localcache,<br />
&nbsp; &nbsp; &nbsp; &nbsp;projectName);<br />
<br />
&nbsp; &nbsp;if (data.length &amp;lt; 5) {<br />
&nbsp; &nbsp; &nbsp; data = getDataFromDatastore(projectName);<br />
&nbsp; &nbsp;}<br />
<br />
&nbsp; &nbsp;return getSkipAverage(data);<br />
}</div></td></tr></tbody></table></div>
<p>Now each of these methods can and should have documentation at the method level, and each of them are nice small easy to test methods in and by itself. This is what I prefer, any day.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael L</title>
		<link>http://theshyam.com/2008/08/your-code-smells/comment-page-1/#comment-11</link>
		<dc:creator>Michael L</dc:creator>
		<pubDate>Thu, 21 Aug 2008 19:30:30 +0000</pubDate>
		<guid isPermaLink="false">http://assertionfailed.wordpress.com/?p=35#comment-11</guid>
		<description>I dissagree with your first &quot;code smell.&quot;  In my experience most developers dont have enough comments in code, (I am guilty of this myself at times). I think good commenting and good class names go hand in hand. It is also usefull because many times you have to turn over source code to other developers and if you have comments that out line the design or logic of a block of code, this helps other people down the line and yourself if you have to look at code you wrote years ago but forgot what it does.</description>
		<content:encoded><![CDATA[<p>I dissagree with your first &#8220;code smell.&#8221;  In my experience most developers dont have enough comments in code, (I am guilty of this myself at times). I think good commenting and good class names go hand in hand. It is also usefull because many times you have to turn over source code to other developers and if you have comments that out line the design or logic of a block of code, this helps other people down the line and yourself if you have to look at code you wrote years ago but forgot what it does.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
