<?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>Reacties op: Java best practices 5 &#8211; Code to Interface, Access by name and Instance Data</title>
	<atom:link href="http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/</link>
	<description>designing a new generation of software</description>
	<lastBuildDate>Mon, 02 Aug 2010 11:00:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
	<item>
		<title>Door: arjan</title>
		<link>http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/comment-page-1/#comment-302</link>
		<dc:creator>arjan</dc:creator>
		<pubDate>Mon, 08 Oct 2007 11:09:32 +0000</pubDate>
		<guid isPermaLink="false">http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/#comment-302</guid>
		<description>&lt;p&gt;Yes I agree with you. If in COLUMN_TITLE, &quot;TITLE&quot; is actually the name of the column it hardly effects readability. Like I said before, refering to the column by name once and then dynamically using the index is certainly miles better than using static index numbers in your code.&lt;br /&gt;&#160;&lt;/p&gt;&lt;p&gt; You do add at least one extra statement to your code for each column you access this way. Of course this doesn&#039;t add that much &#039;reading overhead&#039;, but then again, even for bulk reads the performance gain typically isn&#039;t that much either, if any. Just try it ;)
&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Yes I agree with you. If in COLUMN_TITLE, &quot;TITLE&quot; is actually the name of the column it hardly effects readability. Like I said before, refering to the column by name once and then dynamically using the index is certainly miles better than using static index numbers in your code.<br />&nbsp;</p>
<p> You do add at least one extra statement to your code for each column you access this way. Of course this doesn&#8217;t add that much &#8216;reading overhead&#8217;, but then again, even for bulk reads the performance gain typically isn&#8217;t that much either, if any. Just try it <img src='http://jdevelopment.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: aaawww</title>
		<link>http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/comment-page-1/#comment-301</link>
		<dc:creator>aaawww</dc:creator>
		<pubDate>Mon, 08 Oct 2007 10:27:24 +0000</pubDate>
		<guid isPermaLink="false">http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/#comment-301</guid>
		<description>well, what about:int COLUMN_TITLE = getIDForColumn(&quot;title&quot;);and then the iteration over the result set?this doesn&#039;t inpact performances, nor readabilitywell, assuming that the result set is used for a bulk read or update; else the the performance impact is negligible (as the overhead for doing it), so it&#039;s just a kind of habit&#160;</description>
		<content:encoded><![CDATA[<p>well, what about:int COLUMN_TITLE = getIDForColumn(&quot;title&quot;);and then the iteration over the result set?this doesn&#8217;t inpact performances, nor readabilitywell, assuming that the result set is used for a bulk read or update; else the the performance impact is negligible (as the overhead for doing it), so it&#8217;s just a kind of habit&nbsp;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: arjan</title>
		<link>http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/comment-page-1/#comment-300</link>
		<dc:creator>arjan</dc:creator>
		<pubDate>Mon, 08 Oct 2007 09:25:12 +0000</pubDate>
		<guid isPermaLink="false">http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/#comment-300</guid>
		<description>&gt; the access by index is indeed a lot faster.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&#160;&lt;br/&gt;&lt;/p&gt;  A lot depends on your context. Please also read what I have to say about such micro optimizations in http://jdevelopment.nl/java/java-best-practices-4-native-arrays-and-not-using-java-5. This case is actually the same kind of tradeoff as using native arrays vs arraylists. The former is theoretically faster, but most businesscode is not going to be influenced by that. The bottomline is; if you have actually used a profiler to &#039;prove&#039; that accesses by name are indeed a bottlenneck in your application, by all means, access by index. But please don&#039;t sacrifice readability in your code for an &#039;premature optimization&#039; which may have zero impact.&lt;p&gt;&#160;&lt;br/&gt;&lt;/p&gt; &lt;br /&gt;&lt;br /&gt;&gt;the best practice to be used for bulk data is to retrieve the result set metadata, ask for the index of the interesting columns by column name and then use the index to get data&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&#160;&lt;br/&gt;&lt;/p&gt; This is an intermediate solution. It&#039;s atleast a lot better than only using hardcoded index references in your code ;) On the other hand, this does add some slight complexity to your code and degrades the readability slightly. The performance gain is also very minimal. Most (nowadays all?) JDBC drivers use a fast HashMap for looking up the columnname. So, per getter you would safe one hash lookup. On modern computers and for typical business code this is absolutely nothing. Even if you were doing thousands of such lookups, the effect would be barebly noticable, if at all.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&#160;&lt;br/&gt;&lt;/p&gt; The tradeoff here is between a minimal performance gain and better readability of code. Would you like to have a 0.00001 second shorter execution time, but in case of a bug somewhere have your technicians spend 2 minutes more on reading the code, and have a 30 percent higher chance of misinterpreting the code when under presure? Of course everyone should make that decision for himself, although I think most businesses are better off to go for readability (and maintainability first and then optimize proven bottlenecks when they emerge.</description>
		<content:encoded><![CDATA[<p>&gt; the access by index is indeed a lot faster.</p>
<p>&nbsp;</p>
<p>  A lot depends on your context. Please also read what I have to say about such micro optimizations in <a href="http://jdevelopment.nl/java/java-best-practices-4-native-arrays-and-not-using-java-5" rel="nofollow">http://jdevelopment.nl/java/java-best-practices-4-native-arrays-and-not-using-java-5</a>. This case is actually the same kind of tradeoff as using native arrays vs arraylists. The former is theoretically faster, but most businesscode is not going to be influenced by that. The bottomline is; if you have actually used a profiler to &#8216;prove&#8217; that accesses by name are indeed a bottlenneck in your application, by all means, access by index. But please don&#8217;t sacrifice readability in your code for an &#8216;premature optimization&#8217; which may have zero impact.
<p>&nbsp;</p>
<p>&gt;the best practice to be used for bulk data is to retrieve the result set metadata, ask for the index of the interesting columns by column name and then use the index to get data</p>
<p>&nbsp;</p>
<p> This is an intermediate solution. It&#8217;s atleast a lot better than only using hardcoded index references in your code <img src='http://jdevelopment.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  On the other hand, this does add some slight complexity to your code and degrades the readability slightly. The performance gain is also very minimal. Most (nowadays all?) JDBC drivers use a fast HashMap for looking up the columnname. So, per getter you would safe one hash lookup. On modern computers and for typical business code this is absolutely nothing. Even if you were doing thousands of such lookups, the effect would be barebly noticable, if at all.</p>
<p>&nbsp;</p>
<p> The tradeoff here is between a minimal performance gain and better readability of code. Would you like to have a 0.00001 second shorter execution time, but in case of a bug somewhere have your technicians spend 2 minutes more on reading the code, and have a 30 percent higher chance of misinterpreting the code when under presure? Of course everyone should make that decision for himself, although I think most businesses are better off to go for readability (and maintainability first and then optimize proven bottlenecks when they emerge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: aaawww</title>
		<link>http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/comment-page-1/#comment-299</link>
		<dc:creator>aaawww</dc:creator>
		<pubDate>Mon, 08 Oct 2007 06:48:18 +0000</pubDate>
		<guid isPermaLink="false">http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/#comment-299</guid>
		<description>I don&#039;t agree on the result set best practice: the access by index is indeed a lot faster. the best practice to be used for bulk data is to retrieve the result set metadata, ask for the index of the interesting columns by column name and then use the index to get data</description>
		<content:encoded><![CDATA[<p>I don&#8217;t agree on the result set best practice: the access by index is indeed a lot faster. the best practice to be used for bulk data is to retrieve the result set metadata, ask for the index of the interesting columns by column name and then use the index to get data</p>
]]></content:encoded>
	</item>
	<item>
		<title>Door: LiveStone</title>
		<link>http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/comment-page-1/#comment-298</link>
		<dc:creator>LiveStone</dc:creator>
		<pubDate>Mon, 08 Oct 2007 06:02:26 +0000</pubDate>
		<guid isPermaLink="false">http://jdevelopment.nl/java/java-best-practices-5-code-to-interface-access-by-name-and-instance-data/#comment-298</guid>
		<description>Thanks, that was useful for me.</description>
		<content:encoded><![CDATA[<p>Thanks, that was useful for me.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
