<?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: Why not to initialize your local variables at declaration</title>
	<atom:link href="http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/</link>
	<description>Software development done right!</description>
	<lastBuildDate>Wed, 08 Feb 2012 14:41:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Thor M</title>
		<link>http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/#comment-28529</link>
		<dc:creator>Thor M</dc:creator>
		<pubDate>Sat, 22 Dec 2007 22:24:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/#comment-28529</guid>
		<description>Consider the following code I often see:

&lt;pre lang=&quot;java&quot;&gt;
void ...(...)
{
   object o = null;
   object o = DoSomething(...);
   if (object != null)
   {
      ...
   }
}
&lt;/pre&gt;

It&#039;s a stupid double assignment. The DoSomething method assigns to variable because it always returns a value or throws an exception.
It&#039;s a case where the compiler could easily outwit the *programmer*.</description>
		<content:encoded><![CDATA[<p>Consider the following code I often see:</p>
<pre lang="java">
void ...(...)
{
   object o = null;
   object o = DoSomething(...);
   if (object != null)
   {
      ...
   }
}
</pre>
<p>It&#8217;s a stupid double assignment. The DoSomething method assigns to variable because it always returns a value or throws an exception.<br />
It&#8217;s a case where the compiler could easily outwit the *programmer*.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent Partington</title>
		<link>http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/#comment-461</link>
		<dc:creator>Vincent Partington</dc:creator>
		<pubDate>Fri, 13 Oct 2006 14:34:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/#comment-461</guid>
		<description>Exactly. Instead of &lt;em&gt;Try to initialize local variables where they\&#039;re declared&lt;/em&gt; it should have said &lt;em&gt;Try to declare local variables where they\&#039;re initialized&lt;/em&gt;. Then the compiler could prevent a lot of these initialization problems instead of users getting an NPE at runtime.

Regards, Vincent.</description>
		<content:encoded><![CDATA[<p>Exactly. Instead of <em>Try to initialize local variables where they\&#8217;re declared</em> it should have said <em>Try to declare local variables where they\&#8217;re initialized</em>. Then the compiler could prevent a lot of these initialization problems instead of users getting an NPE at runtime.</p>
<p>Regards, Vincent.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: erozendaal</title>
		<link>http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/#comment-460</link>
		<dc:creator>erozendaal</dc:creator>
		<pubDate>Fri, 13 Oct 2006 13:58:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/#comment-460</guid>
		<description>To me the sun standards recommend that the declaration of a local variable should be moved to where it is first assigned (initialized). This way the variable is _always_ initialized with a correct value.

Only if this is not possible (for example, due to some computation that cannot be extracted into a separate method) would you declare a local variable without initializing. Like you said, assigning &quot;null&quot; or some other random value is a bad thing in this case since the compiler is no longer able to help you avoid errors.</description>
		<content:encoded><![CDATA[<p>To me the sun standards recommend that the declaration of a local variable should be moved to where it is first assigned (initialized). This way the variable is _always_ initialized with a correct value.</p>
<p>Only if this is not possible (for example, due to some computation that cannot be extracted into a separate method) would you declare a local variable without initializing. Like you said, assigning &#8220;null&#8221; or some other random value is a bad thing in this case since the compiler is no longer able to help you avoid errors.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.xebia.com/2006/10/13/why-not-to-initialize-your-local-variables-at-declaration/feed/ ) in 0.53318 seconds, on Feb 9th, 2012 at 9:04 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 10:04 pm UTC -->
