<?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: Bad, Better, Best</title>
	<atom:link href="http://stuffthathappens.com/blog/2008/05/20/bad-better-best/feed/" rel="self" type="application/rss+xml" />
	<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/</link>
	<description>Technology and Geek Stuff by Eric Burke</description>
	<lastBuildDate>Thu, 04 Nov 2010 22:37:00 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Zoelson</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-18074</link>
		<dc:creator>Zoelson</dc:creator>
		<pubDate>Tue, 22 Jul 2008 21:33:22 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-18074</guid>
		<description>Some things I consider about this question:
- null != 0 (zero). Zero can be a valid value in a lot of cases. The same for null != &quot;&quot;;
- If you are building a framework, throws an IllegalArgumentException;
- If you are building a program, use assertions or keep throwing an IllegalArgumentException. You must solve most issues on dev time;

Of course it would be great if you can catch null values on compile time, but It depends on the context of the execution.</description>
		<content:encoded><![CDATA[<p>Some things I consider about this question:<br />
- null != 0 (zero). Zero can be a valid value in a lot of cases. The same for null != &#8220;&#8221;;<br />
- If you are building a framework, throws an IllegalArgumentException;<br />
- If you are building a program, use assertions or keep throwing an IllegalArgumentException. You must solve most issues on dev time;</p>
<p>Of course it would be great if you can catch null values on compile time, but It depends on the context of the execution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lumpynose</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11721</link>
		<dc:creator>lumpynose</dc:creator>
		<pubDate>Wed, 21 May 2008 04:44:17 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11721</guid>
		<description>Are the other examples of the typesafe id class?  I could only find this one in the zonski framework:

http://zonskiframework.blogspot.com/</description>
		<content:encoded><![CDATA[<p>Are the other examples of the typesafe id class?  I could only find this one in the zonski framework:</p>
<p><a href="http://zonskiframework.blogspot.com/" rel="nofollow">http://zonskiframework.blogspot.com/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Slesinsky</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11705</link>
		<dc:creator>Brian Slesinsky</dc:creator>
		<pubDate>Wed, 21 May 2008 01:59:15 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11705</guid>
		<description>For string id&#039;s, a Customer.Id class also helps with security; you can make sure your id&#039;s are parsed in one place.</description>
		<content:encoded><![CDATA[<p>For string id&#8217;s, a Customer.Id class also helps with security; you can make sure your id&#8217;s are parsed in one place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Lee</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11693</link>
		<dc:creator>Bob Lee</dc:creator>
		<pubDate>Tue, 20 May 2008 22:52:49 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11693</guid>
		<description>+1 to using a Customer.Id class. If you partition your data, you can easily store a partition &quot;hint&quot; as part of the ID. Also, when your company takes off, you can easily switch that int to a long without changing your code in N places.</description>
		<content:encoded><![CDATA[<p>+1 to using a Customer.Id class. If you partition your data, you can easily store a partition &#8220;hint&#8221; as part of the ID. Also, when your company takes off, you can easily switch that int to a long without changing your code in N places.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Breidecker</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11684</link>
		<dc:creator>Rob Breidecker</dc:creator>
		<pubDate>Tue, 20 May 2008 20:49:28 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11684</guid>
		<description>This is best... ;-)

public Customer getCustomer(String customerId) { ... }</description>
		<content:encoded><![CDATA[<p>This is best&#8230; <img src='http://stuffthathappens.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>public Customer getCustomer(String customerId) { &#8230; }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Burke</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11683</link>
		<dc:creator>Eric Burke</dc:creator>
		<pubDate>Tue, 20 May 2008 20:47:30 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11683</guid>
		<description>Confused post? LOL. I intentionally kept it brief to spark a conversation. You say: &quot;There is currently no good way standard way to enforce this at compile-time&quot;

To which I respond, use a primitive if you don&#039;t allow null. Thus you get compile-time enforcement, which is basically what I was trying to demonstrate.

I did not bring up the custom types issue, that was Jesse&#039;s comment. So it seems pretty unfair to label my post &quot;confused&quot;.

Though not stated explicitly, my underlying concept is to design APIs to be narrow and focused. When possible -- within the constraints of the language -- strive to design contracts that let the compiler catch errors as soon as possible. If your method requires a simple number and null is not allowed, use a primitive.</description>
		<content:encoded><![CDATA[<p>Confused post? LOL. I intentionally kept it brief to spark a conversation. You say: &#8220;There is currently no good way standard way to enforce this at compile-time&#8221;</p>
<p>To which I respond, use a primitive if you don&#8217;t allow null. Thus you get compile-time enforcement, which is basically what I was trying to demonstrate.</p>
<p>I did not bring up the custom types issue, that was Jesse&#8217;s comment. So it seems pretty unfair to label my post &#8220;confused&#8221;.</p>
<p>Though not stated explicitly, my underlying concept is to design APIs to be narrow and focused. When possible &#8212; within the constraints of the language &#8212; strive to design contracts that let the compiler catch errors as soon as possible. If your method requires a simple number and null is not allowed, use a primitive.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eugene Kaganovich</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11682</link>
		<dc:creator>Eugene Kaganovich</dc:creator>
		<pubDate>Tue, 20 May 2008 20:31:48 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11682</guid>
		<description>This seems like a very confused post. All kinds of issues are intermingled:
1) wrappers vs primitives
This is really an optimization for the common case to avoid autoboxing. If you expect most of your code to have Integer objects at runtime (doesn&#039;t seem likely), use Integer; otherwise use int
2) null parameters/return values contract in a method
There is currently no good way standard way to enforce this at compile-time; IDEA provides support for @Nullable and @NotNull. The accepted arguments should be documented, and a NullPointerException should be thrown by the method if null is not valid. Hopefully JSR 305 will standardize the contract annotations.
3) Defining custom types (Customer) vs using builtin classes (Integer):
Not addressed at all, and a matter of taste. A lot of people will tell you to create a class for any semantic type in the system; I usually decide case by case.</description>
		<content:encoded><![CDATA[<p>This seems like a very confused post. All kinds of issues are intermingled:<br />
1) wrappers vs primitives<br />
This is really an optimization for the common case to avoid autoboxing. If you expect most of your code to have Integer objects at runtime (doesn&#8217;t seem likely), use Integer; otherwise use int<br />
2) null parameters/return values contract in a method<br />
There is currently no good way standard way to enforce this at compile-time; IDEA provides support for @Nullable and @NotNull. The accepted arguments should be documented, and a NullPointerException should be thrown by the method if null is not valid. Hopefully JSR 305 will standardize the contract annotations.<br />
3) Defining custom types (Customer) vs using builtin classes (Integer):<br />
Not addressed at all, and a matter of taste. A lot of people will tell you to create a class for any semantic type in the system; I usually decide case by case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11677</link>
		<dc:creator>Jesse</dc:creator>
		<pubDate>Tue, 20 May 2008 18:47:05 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11677</guid>
		<description>I&#039;ve started to use typesafe ID classes:

class Customer {
  static class Id {
    private final int internalForm;
    public Id(int internalForm) { ... }
    public int internalForm() { ... }
    @Override boolean equals(Object other) { ... }
    @Override boolean hashCode(Object other) { ... }
    @Override String toString() { return &quot;(Customer.Id:&quot; + internalForm + &quot;)&quot;; }
  }
}

Although the Id class is slightly annoying to write, I think it&#039;s worthwhile:
- Self-documenting APIs. With methods like this, it&#039;s easy to get the args out of order, or to mis-interpret the return type. Compare:
    public int transferAccount(int accountIdToMove, int targetCustomerId);
    public Customer.Id transferAccount(AccountId toMove, Customer.Id target);
- We have different services that each define their own customer Id. It&#039;s impossible to pass a service A ID to a method that wants a service B ID. 
- toString() stands on its own.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve started to use typesafe ID classes:</p>
<p>class Customer {<br />
  static class Id {<br />
    private final int internalForm;<br />
    public Id(int internalForm) { &#8230; }<br />
    public int internalForm() { &#8230; }<br />
    @Override boolean equals(Object other) { &#8230; }<br />
    @Override boolean hashCode(Object other) { &#8230; }<br />
    @Override String toString() { return &#8220;(Customer.Id:&#8221; + internalForm + &#8220;)&#8221;; }<br />
  }<br />
}</p>
<p>Although the Id class is slightly annoying to write, I think it&#8217;s worthwhile:<br />
- Self-documenting APIs. With methods like this, it&#8217;s easy to get the args out of order, or to mis-interpret the return type. Compare:<br />
    public int transferAccount(int accountIdToMove, int targetCustomerId);<br />
    public Customer.Id transferAccount(AccountId toMove, Customer.Id target);<br />
- We have different services that each define their own customer Id. It&#8217;s impossible to pass a service A ID to a method that wants a service B ID.<br />
- toString() stands on its own.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fernando</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11676</link>
		<dc:creator>Fernando</dc:creator>
		<pubDate>Tue, 20 May 2008 18:42:28 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11676</guid>
		<description>Well Ian, that&#039;s why I have autoboxing disabled at my projects (and lots of other restrictions). People tends to do wrong things by nature.

Always one of my partners tells me &quot;I have found a different way to do X&quot;, I shudder... I wonder why people always looks for different (more complex, error prone, slow and long) ways of doing something and rarely comes up with a better solution.</description>
		<content:encoded><![CDATA[<p>Well Ian, that&#8217;s why I have autoboxing disabled at my projects (and lots of other restrictions). People tends to do wrong things by nature.</p>
<p>Always one of my partners tells me &#8220;I have found a different way to do X&#8221;, I shudder&#8230; I wonder why people always looks for different (more complex, error prone, slow and long) ways of doing something and rarely comes up with a better solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fernando</title>
		<link>http://stuffthathappens.com/blog/2008/05/20/bad-better-best/comment-page-1/#comment-11675</link>
		<dc:creator>Fernando</dc:creator>
		<pubDate>Tue, 20 May 2008 18:39:32 +0000</pubDate>
		<guid isPermaLink="false">http://stuffthathappens.com/blog/?p=476#comment-11675</guid>
		<description>I always have done it that way, but my partners at work seem to simply not get it (I don&#039;t know why they can&#039;t understand such a simple thing).

Browsing other coding sites I have also seen things such as:

public class Customer {
  private int id; // A null id makes no sense
}

But... well. I use to have id&#039;s as nullable in my entities, an entity with null ID in my code means that it is not stored yet. I also create and assign the ID (if needed) in the DAO save methods.

I wonder why other people in programming blogs tend to create entity IDs as not null and how they do work with that.

What do you think?</description>
		<content:encoded><![CDATA[<p>I always have done it that way, but my partners at work seem to simply not get it (I don&#8217;t know why they can&#8217;t understand such a simple thing).</p>
<p>Browsing other coding sites I have also seen things such as:</p>
<p>public class Customer {<br />
  private int id; // A null id makes no sense<br />
}</p>
<p>But&#8230; well. I use to have id&#8217;s as nullable in my entities, an entity with null ID in my code means that it is not stored yet. I also create and assign the ID (if needed) in the DAO save methods.</p>
<p>I wonder why other people in programming blogs tend to create entity IDs as not null and how they do work with that.</p>
<p>What do you think?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.262 seconds -->

