<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Freya.no &#187; Java</title>
	<atom:link href="http://wp.freya.no/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.freya.no</link>
	<description>Knowledge is power</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:56:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>TDD (test-driven development) is Bullshit!</title>
		<link>http://wp.freya.no/2012/01/tdd-test-driven-development-is-bullshit/</link>
		<comments>http://wp.freya.no/2012/01/tdd-test-driven-development-is-bullshit/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 19:49:40 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[bullshit]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=1098</guid>
		<description><![CDATA[Well, maybe not in theory, but in practice &#8211; definitely. Test-drive development is a way to program where you write an automated unit test that fails first, then you write code and check that the test runs ok. Brilliant theory for an ideal world (doesn&#8217;t exist). In practice however it is very seldom that you [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Well, maybe not in <a href="http://en.wikipedia.org/wiki/Test-driven_development">theory</a>, but in practice &#8211; definitely.</p>
<p>Test-drive development is a way to program where you write an automated unit test that fails first, then you write code and check that the test runs ok. Brilliant theory for an ideal world (doesn&#8217;t exist). In practice however it is very seldom that you as a programmer have a full and clear understanding of what is it you are gonna do.</p>
<p>Of course I&#8217;m not talking about cases where you need to calculate the result of 2+2. Sure you can write a test case here.</p>
<p>And here comes a hard reality where you come to the real place, f.ex. a bank that needs a new program. And here you are with a task that states smth like this &#8220;Create a form that have these and these fields and calculates that and that&#8221;. You begin with a test case? You are right! That&#8217;s what happens if you do this: you kill several days  trying to understand how you build this test case, what fields you need to fill inn to calculate the result. If you&#8217;ll try to check a more specific result then you need several extra days to find a person who maybe knows how the value must be calculated.</p>
<p>Because it is very seldom in the real world that programmers work together with persons who both know and can explain to the programmer how the things should be done. Simply because those persons do not exist.</p>
<p>So you wrote the test and now you need to write a calculation algorithm&#8230; Hmm, how the hell do we do that? We start building it and magic happens! The algorithm that can calculate the value needs all totally different input values then those you&#8217;ve written in your test case&#8230; Ouch! It happened again?</p>
<p>At the end you&#8217;ve used double time to write the code and update the test case in parallel plus the time you&#8217;ve killed on the test at the beginning.</p>
<p>So why is it so popular to talk about it and constantly try to use it? Do not know. You need to write test cases when you program difficult logic. That is the fact. But doing it FIRST? It&#8217;s just a waste of time and killing of enthusiasm. You won&#8217;t be clever and you&#8217;ll not write better code if you kill time with the test first.</p>
<p>What really needs to be done before you start programming is to draw a solution.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1098" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2012%2F01%2Ftdd-test-driven-development-is-bullshit%2F&amp;title=TDD%20%28test-driven%20development%29%20is%20Bullshit%21" id="wpa2a_6"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2012/01/tdd-test-driven-development-is-bullshit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get a value of mx:DataGridColumn</title>
		<link>http://wp.freya.no/2011/02/how-to-get-a-value-of-mxdatagridcolumn/</link>
		<comments>http://wp.freya.no/2011/02/how-to-get-a-value-of-mxdatagridcolumn/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 20:23:42 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=987</guid>
		<description><![CDATA[No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:DataGrid xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Label;

            public function willShowResult(result:Label, myVar:String):Boolean {
                if (myVar== 'XXX') {
                    return false;
                }
                return true;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:columns&gt;
        &lt;mx:DataGridColumn
            dataField=&quot;myVar&quot;
            headerText=&quot;My var&quot;/&gt;
        &lt;mx:DataGridColumn
            dataField=&quot;result&quot;
            headerText=&quot;My result&quot;&gt;
            &lt;mx:itemRenderer&gt;
                &lt;mx:Component&gt;
                    &lt;mx:Label text=&quot;{outerDocument.willShowResult(this, data.myVar) ? data.result : ' ' }&quot;/&gt;
                &lt;/mx:Component&gt;
            &lt;/mx:itemRenderer&gt;
        &lt;/mx:DataGridColumn&gt;
    &lt;/mx:columns&gt;

&lt;/mx:DataGrid&gt;
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=987" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2011%2F02%2Fhow-to-get-a-value-of-mxdatagridcolumn%2F&amp;title=How%20to%20get%20a%20value%20of%20mx%3ADataGridColumn" id="wpa2a_14"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2011/02/how-to-get-a-value-of-mxdatagridcolumn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse autocomplete problem</title>
		<link>http://wp.freya.no/2011/02/eclipse-autocomplete-problem/</link>
		<comments>http://wp.freya.no/2011/02/eclipse-autocomplete-problem/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 14:17:44 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=983</guid>
		<description><![CDATA[If an autocomplete stopped working go Window -&#62; Preferences -&#62; Java -&#62; Editor -&#62; Content Assist -&#62; Advanced -&#62;  check for &#8220;Other Java Proposals&#8221; No related posts.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If an autocomplete stopped working go</p>
<p>Window -&gt; Preferences -&gt; Java -&gt; Editor -&gt; Content Assist -&gt; Advanced -&gt;  check for &#8220;Other Java Proposals&#8221;</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=983" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2011%2F02%2Feclipse-autocomplete-problem%2F&amp;title=Eclipse%20autocomplete%20problem" id="wpa2a_22"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2011/02/eclipse-autocomplete-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PMD XPath: Hibernate mapping example</title>
		<link>http://wp.freya.no/java/pmd-xpath-hibernate-mapping-example/</link>
		<comments>http://wp.freya.no/java/pmd-xpath-hibernate-mapping-example/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 20:13:08 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[pmd]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=879</guid>
		<description><![CDATA[Those who use hibernate for database access know that you need to provide an information that this object is a hibernate object. To do so you typically need to annotate your object with @Entity. It&#8217;s not a problem although if we speak about some large system. In large systems we have typically a number of [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Those who use hibernate for database access know that you need to provide an information that this object is a hibernate object. To do so you typically need to annotate your object with @Entity. It&#8217;s not a problem although if we speak about some large system. In large systems we have typically a number of instances of the same object that represent the same table in different contexts and packages. And here we need this: to give each object unique name.<br />
Example:</p>
<pre class="brush: java; title: ; notranslate">
@Entity(name=&quot;person.usa&quot;)
class Person {
   ...
}
</pre>
<p>This PMD rule shows how to check if a hibernate object have a name.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;![CDATA[
     //Annotation/NormalAnnotation[
     (
           Name/@Image='Entity'
           and
           not
           (
                 MemberValuePairs/MemberValuePair/@Image='name'
                 and
                 //PrimaryExpression/PrimaryPrefix[contains(Literal/@Image,'.')]
           )
     )
]]]&gt;
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=879" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fjava%2Fpmd-xpath-hibernate-mapping-example%2F&amp;title=PMD%20XPath%3A%20Hibernate%20mapping%20example" id="wpa2a_30"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/java/pmd-xpath-hibernate-mapping-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Return empty objects, not nulls</title>
		<link>http://wp.freya.no/2010/10/return-empty-objects-not-nulls/</link>
		<comments>http://wp.freya.no/2010/10/return-empty-objects-not-nulls/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 19:14:51 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=861</guid>
		<description><![CDATA[It&#8217;s uncommon to see methods like this> There is no reason to make a Person object where there are no persons found. But doing so requires extra code in the client to handle the null value. This becomes a problem if a client is, for example, a GUI: The result of such code in cases [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s uncommon to see methods like this></p>
<pre class="brush: java; title: ; notranslate">
public Person findPerson() {
   if(someService) [
     return someService.getPerson();
   }
   return null;
}
</pre>
<p>There is no reason to make a Person object where there are no persons found. But doing so requires extra code in the client to handle the null value. This becomes a problem if a client is, for example, a GUI:</p>
<pre class="brush: java; title: ; notranslate">
somePage.jsp
&lt;%
  ...
  Person person = myService.findPerson();
%&gt;
&lt;table&gt;
   &lt;tr&gt;
      &lt;td&gt;${person.name}&lt;/td&gt;
      &lt;td&gt;${person.address}&lt;/td&gt;
      &lt;td&gt;${person.numberOfPurchases}&lt;/td&gt;
   &lt;/tr&gt;
&lt;/table&gt;
</pre>
<p>The result of such code in cases where the person cannot be found is Server error. So,<strong> there is no reason ever to return <em>null </em>from an object-valued method instead of returning an empty object.</strong> Especially if you deal with arrays and collections.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=861" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2010%2F10%2Freturn-empty-objects-not-nulls%2F&amp;title=Return%20empty%20objects%2C%20not%20nulls" id="wpa2a_38"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2010/10/return-empty-objects-not-nulls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prefer two-element enum types to boolean parameters</title>
		<link>http://wp.freya.no/2010/10/prefer-two-element-enum-types-to-boolean-parameters/</link>
		<comments>http://wp.freya.no/2010/10/prefer-two-element-enum-types-to-boolean-parameters/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 10:14:03 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=852</guid>
		<description><![CDATA[How many times we write a program like this: And so we hear from our sjef that we can&#8217;t have same salary for male and female. So we do this: Yes, but what if we have more options later on? Or if we look just at the doSmth() function? What do these true/false mean? An [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>How many times we write a program like this:</p>
<pre class="brush: java; title: ; notranslate">
public void doSmth() {
    Salary s = calculateSalary(Person p);
    ...
}

private Salary calculateSalary(Person p) {
   return 100;
}
</pre>
<p>And so we hear from our sjef that we can&#8217;t have same salary for male and female. So we do this:</p>
<pre class="brush: java; title: ; notranslate">
public void doSmth() {
    Salary male = calculateSalary(Person p, true);
    Salary female = calculateSalary(Person p, false);
    ...
}

private Salary calculateSalary(Person p, boolean sex) {
   if(sex) return 100;
   else return 50;
}
</pre>
<p>Yes, but what if we have more options later on? Or if we look just at the doSmth() function? What do these true/false mean? </p>
<p>An enum type in such cases makes your code easier to read and to write, especially if you are using an IDE that supports autocomplition. Also, it makes it easy to add more options later. </p>
<p>So here&#8217;s how we should do it:</p>
<pre class="brush: java; title: ; notranslate">
public enum Sex {MALE, FEMALE}

public void doSmth() {
    Salary male = calculateSalary(Person p, Sex.MALE);
    Salary female = calculateSalary(Person p, Sex.FEMALE);
    ...
}

private Salary calculateSalary(Person p, Sex sex) {
   if(sex.equals(Sex.MALE) return 100;
   else return 50;
}
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=852" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F2010%2F10%2Fprefer-two-element-enum-types-to-boolean-parameters%2F&amp;title=Prefer%20two-element%20enum%20types%20to%20boolean%20parameters" id="wpa2a_46"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/2010/10/prefer-two-element-enum-types-to-boolean-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ugly code: The Law of Demeter</title>
		<link>http://wp.freya.no/ugly-code/ugly-code-the-law-of-demeter/</link>
		<comments>http://wp.freya.no/ugly-code/ugly-code-the-law-of-demeter/#comments</comments>
		<pubDate>Fri, 21 May 2010 21:20:12 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[ugly code]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=708</guid>
		<description><![CDATA[I&#8217;ve recently come to a heuristic called the Law of Demeter (LoD) or Principle of Least Knowledge that says a module should not know about the innards of the objects it manipulates. More precisely, the method of a particular class should call: other methods of the same class objects created by the method itself objects [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently come to a heuristic called the <a href="http://en.wikipedia.org/wiki/Law_of_Demeter">Law of Demeter</a> (LoD) or Principle of Least Knowledge that says a module should not know about the innards of the objects it manipulates. More precisely, the method of a particular class should call:</p>
<ul>
<li>other methods of the same class</li>
<li>objects created by the method itself</li>
<li>objects passed as arguments to the method</li>
<li>objects held in an instance variable of the same class</li>
</ul>
<p>And that&#8221;s all!</p>
<p>So the following code appears to violate the Law:</p>
<pre class="brush: java; title: ; notranslate">
String output = obj.getContext().getOptions().getDir().getPath();
</pre>
<p>It&#8217;s easy to forget something around such a structure. This one can solve the issue:</p>
<pre class="brush: java; title: ; notranslate">
String output = obj.getPathFromContext();
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=708" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fugly-code%2Fugly-code-the-law-of-demeter%2F&amp;title=Ugly%20code%3A%20The%20Law%20of%20Demeter" id="wpa2a_54"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/ugly-code/ugly-code-the-law-of-demeter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recipe for a high-quality &#8220;equals&#8221; method</title>
		<link>http://wp.freya.no/java/recipe-for-a-high-quality-equals-method/</link>
		<comments>http://wp.freya.no/java/recipe-for-a-high-quality-equals-method/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 21:49:25 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Memorable]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[equals]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=675</guid>
		<description><![CDATA[1. Use the == to check if the argument is a reference to this object. 2. Use the instanceof operator to check if the argument has the correct type. 3. Cast the argument to the correct type. 4. For each &#8220;significant&#8221; field in the class, check if that field of the argument matches the corresponding [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>1. Use the == to check if the argument is a reference to this object.</p>
<p>2. Use the <em>instanceof </em>operator to check if the argument has the correct type.</p>
<p>3. Cast the argument to the correct type.</p>
<p>4. For each &#8220;significant&#8221; field in the class, check if that field of the argument matches the corresponding field of this object.</p>
<p>5. Always override <em>hashCode </em>when you override <em>equals</em>.</p>
<p>6. Don&#8217;t substitute another type for Object in the equals declaration.</p>
<p>7. Write unit-test.</p>
<pre class="brush: java; title: ; notranslate">
   @Override
   public boolean equals(Object obj) {
      if(obj == this) {
         return true;
      }
      if(!(obj instanceof Person)) {
          return false;
      }
      Person p = (Person)obj;
      return p.name.equals(name)
             p.birthday.equals(birthday)
             p.personNumber == personNumber;
      }
</pre>
<p><em><br />
Ref.&#8221;Effective Java&#8221; by Joshua Bloch</em></p>
<p>Enother example with hashCode and toString:</p>
<pre class="brush: java; title: ; notranslate">
    @Override
    public boolean equals(Object obj) {
        if (obj == null || !obj.getClass().isInstance(this)) {
            return false;
        }
        Beregning b = (Beregning) obj;

        return new EqualsBuilder()
                .append(simulertPensjon, b.getSimulertPensjon())
                .append(linjer.size(), b.getLinjer().size()).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(simulertPensjon).append(linjer).hashCode();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
        .append(&quot;simulertPensjon&quot;, simulertPensjon)
        .append(&quot;antall linjer&quot;, linjer.size()).toString();
    }
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=675" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fjava%2Frecipe-for-a-high-quality-equals-method%2F&amp;title=Recipe%20for%20a%20high-quality%20%26%238220%3Bequals%26%238221%3B%20method" id="wpa2a_62"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/java/recipe-for-a-high-quality-equals-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean code</title>
		<link>http://wp.freya.no/ugly-code/clean-code/</link>
		<comments>http://wp.freya.no/ugly-code/clean-code/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:13:49 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Memorable]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=585</guid>
		<description><![CDATA[The book by Robert C. Martin &#8220;Clean Code&#8221; is a really very useful material for all programmers. You can disagree with him sometimes (as I do), but it still provides some useful notes that helped me to place my programmer experience and knowledge where they belong. Here I&#8217;ll provide some key notes that I did [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>The book by Robert C. Martin &#8220;Clean Code&#8221; is a really very useful material for all programmers. You can disagree with him sometimes (as I do), but it still provides some useful notes that helped me to place my programmer experience and knowledge where they belong. Here I&#8217;ll provide some key notes that I did while reading the book and that I&#8217;d like to memorize.</p>
<p>What you as a programmer <strong>SHOULD DO</strong>:</p>
<p>1. Give everything meaningful, searchable and pronounceable names.<br />
2. Use names that other programmers can understand. Remember that the code is for programmers, not customers.<br />
3. Functions should be small and smaller than that.<br />
4. Functions should do one thing. They should do it well. They should do it only.<br />
5. The ideal number of arguments for a function is zero. Max 3.<br />
6. Prefer exceptions to returning error codes. Create informative error messages.<br />
7. Prefer meaningful names to comments.<br />
8. Write JavaDoc only for public API&#8217;s.<br />
9. Format your code. While working in a team use a single formatting style.<br />
10. Test your code with clean tests. Remember that test code is just as important as production code.<br />
11. Test just one concept per test.<br />
12. Test should follow the FIRST rule:</p>
<ul> <strong>Fast </strong>-  tests should be fast.<br />
<strong>Independent </strong>- tests should not depend on each other<br />
<strong>Repeatable </strong>- tests should be repeatable in any environment<br />
<strong>Self-validating</strong> &#8211; the test should have a boolean output<br />
<strong>Timely </strong>- write unit tests before the production code.</ul>
<p>What you as a programmer should <strong>AVOID</strong>:<br />
1. Avoid encoding<br />
2. Avoid duplicate code. Watch out not only duplicate functions but also duplicate functionality.<br />
3. Avoid noisy, redundant, uninformative comments. Remember that one of the more common motivations for writing comments is bad code.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=585" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fugly-code%2Fclean-code%2F&amp;title=Clean%20code" id="wpa2a_70"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/ugly-code/clean-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java conversions and 7 Golden rules of widening, boxing &amp; varargs</title>
		<link>http://wp.freya.no/java/java-conversions-and-golden-rules-of-widening-boxing-varargs/</link>
		<comments>http://wp.freya.no/java/java-conversions-and-golden-rules-of-widening-boxing-varargs/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 19:31:43 +0000</pubDate>
		<dc:creator>Tatyana</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[certification]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[primitives]]></category>
		<category><![CDATA[scjp]]></category>

		<guid isPermaLink="false">http://wp.freya.no/?p=510</guid>
		<description><![CDATA[Here is a very useful java conversion table that I&#8217;ve created while preparing for the Sun Certified Java Programmer exam. And here is a complete overview of the Golden rules of widening, boxing &#38; varargs: 1. Primitive Widening &#62; Boxing &#62; Varargs. 2. Widening and Boxing (WB) not allowed. 3. Boxing and Widening (BW) allowed. [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Here is a very useful java conversion table that I&#8217;ve created while preparing for the Sun Certified Java Programmer exam.</p>
<div id="attachment_511" class="wp-caption alignnone" style="width: 900px"><a href="http://wp.freya.no/files/2010/02/conversions.jpg"><img class="size-full wp-image-511" title="Java conversions table" src="http://wp.freya.no/files/2010/02/conversions.jpg" alt="primitives conversion" width="890" height="242" /></a><p class="wp-caption-text">Java primitive conversions table</p></div>
<p>And here is a complete overview of the Golden rules of widening, boxing &amp; varargs:</p>
<p>1. Primitive Widening &gt; Boxing &gt; Varargs.<br />
2. Widening and Boxing (WB) not allowed.<br />
3. Boxing and Widening (BW) allowed.<br />
4. While overloading Widening + vararg and boxing + vararg are mutually exclusive of each other.<br />
5. Widening between wrapper classes not allowed<br />
6. Widening+varArgs &amp; Boxing+varargs are individually allowed (but not allowed in overloaded version of method)<br />
7. Boxing+Widening is preferred over Boxing+Varargs.</p>
<p>More explanation <a href="http://www.coderanch.com/t/417622/Programmer-Certification-SCJP/certification/Golden-Rules-widening-boxing-varargs#1918932">here</a>.</p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=510" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2Fjava%2Fjava-conversions-and-golden-rules-of-widening-boxing-varargs%2F&amp;title=Java%20conversions%20and%207%20Golden%20rules%20of%20widening%2C%20boxing%20%26amp%3B%20varargs" id="wpa2a_78"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/java/java-conversions-and-golden-rules-of-widening-boxing-varargs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

