<?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: Never, never, never use String in Java (or at least less often :-)</title>
	<atom:link href="http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/feed/" rel="self" type="application/rss+xml" />
	<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/</link>
	<description></description>
	<lastBuildDate>Wed, 09 May 2012 22:39:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-939296</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 25 Apr 2012 03:04:35 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-939296</guid>
		<description>@Chuck: Thx, changed the link.</description>
		<content:encoded><![CDATA[<p>@Chuck: Thx, changed the link.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck Krutsinger</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-938894</link>
		<dc:creator>Chuck Krutsinger</dc:creator>
		<pubDate>Tue, 24 Apr 2012 15:59:10 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-938894</guid>
		<description>The link in your article to &quot;object calisthenics&quot; is broken.  Could you please send the correct link?</description>
		<content:encoded><![CDATA[<p>The link in your article to &#8220;object calisthenics&#8221; is broken.  Could you please send the correct link?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Rosencrantz</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-849288</link>
		<dc:creator>Nick Rosencrantz</dc:creator>
		<pubDate>Mon, 30 Jan 2012 17:37:15 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-849288</guid>
		<description>Take it further, why use datatypes at all? You could just name the proprties and not care whether it&#039;s a boolean, a String or a Film. Python does this with so-called expando prorties and Java will or should already do that too. Do you agree?</description>
		<content:encoded><![CDATA[<p>Take it further, why use datatypes at all? You could just name the proprties and not care whether it&#8217;s a boolean, a String or a Film. Python does this with so-called expando prorties and Java will or should already do that too. Do you agree?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Someone1234</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-845930</link>
		<dc:creator>Someone1234</dc:creator>
		<pubDate>Thu, 26 Jan 2012 20:09:10 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-845930</guid>
		<description>You, Sir, went too far in creating a class for a FirstName property.

That is overengineering par excellence.

While I can see your point, I must ask you to stop giving bad advice on the web or to alter your (bad) example.</description>
		<content:encoded><![CDATA[<p>You, Sir, went too far in creating a class for a FirstName property.</p>
<p>That is overengineering par excellence.</p>
<p>While I can see your point, I must ask you to stop giving bad advice on the web or to alter your (bad) example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: meriu</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-831638</link>
		<dc:creator>meriu</dc:creator>
		<pubDate>Sat, 14 Jan 2012 13:40:40 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-831638</guid>
		<description>dont use eclipse with its stupid internal compiler (i really wonder how is it they still didnt fix it) and thise problem

call bookTicket(String arg0, String arg1, String arg2, int arg3, String arg4)

wont force you to use custom types ;-)

didnt read further, first argument totally disappointed me, sorry</description>
		<content:encoded><![CDATA[<p>dont use eclipse with its stupid internal compiler (i really wonder how is it they still didnt fix it) and thise problem</p>
<p>call bookTicket(String arg0, String arg1, String arg2, int arg3, String arg4)</p>
<p>wont force you to use custom types ;-)</p>
<p>didnt read further, first argument totally disappointed me, sorry</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas v James.com &#8212; Confusing Domain and Context?</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-717609</link>
		<dc:creator>Thomas v James.com &#8212; Confusing Domain and Context?</dc:creator>
		<pubDate>Sun, 16 Oct 2011 06:35:51 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-717609</guid>
		<description>[...] Never, never, never use String in Java (or at least less often) [...]</description>
		<content:encoded><![CDATA[<p>[...] Never, never, never use String in Java (or at least less often) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-671702</link>
		<dc:creator>Liam</dc:creator>
		<pubDate>Thu, 15 Sep 2011 18:57:02 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-671702</guid>
		<description>I completely don&#039;t understand you. Your example for detractors is &quot;When you read someone else code with String id and you wonder what on earth the id is, come back and read this post.&quot; This looks like a poorly named variable name. But if my classes were just as poorly named, I&#039;d have &quot;Guid id&quot;, and I wouldn&#039;t have any better clue what &quot;id&quot; was than when I started; I&#039;ve added nothing by calling it a &quot;Guid&quot;.

Furthermore, &quot;String orderId&quot; tells me a lot more than &quot;OrderId order&quot;, because at least with &quot;String orderId&quot;, I know what type orderId is... with OrderId, what does that return? Some sort of business object that I now have to go look at to see how to interact with it?

Isn&#039;t this only useful when you see the class name in isolation from the variable name (which is fairly infrequent)? Otherwise, I have the variable right there to tell me what I&#039;m dealing with... What price do I pay with string representation that can&#039;t be solved by better variable names?

Given the fact that extra classes take extra time to write, they are not immediately familiar to users (whereas the API for String etc is pretty commonly understood) and so therefore can cause confusion, and that your examples almost completely duplicate the variable name when defining the class name, and that class names are so much less visible than variable names, I must say I&#039;m at a complete loss for your motivation, especially in large projects where all of these issues would compound themselves. Can you please provide a more elaborate use case where perhaps you couldn&#039;t make inferences from the variable names, or thereabouts?

I can see your point perhaps if you have a type that may change over time... for example, if you start with &quot;int id&quot;, but then need to move to &quot;Guid id&quot;, better to write that up front, but that doesn&#039;t seem to be what you&#039;re saying. Please tell me I&#039;m misunderstanding you?</description>
		<content:encoded><![CDATA[<p>I completely don&#8217;t understand you. Your example for detractors is &#8220;When you read someone else code with String id and you wonder what on earth the id is, come back and read this post.&#8221; This looks like a poorly named variable name. But if my classes were just as poorly named, I&#8217;d have &#8220;Guid id&#8221;, and I wouldn&#8217;t have any better clue what &#8220;id&#8221; was than when I started; I&#8217;ve added nothing by calling it a &#8220;Guid&#8221;.</p>
<p>Furthermore, &#8220;String orderId&#8221; tells me a lot more than &#8220;OrderId order&#8221;, because at least with &#8220;String orderId&#8221;, I know what type orderId is&#8230; with OrderId, what does that return? Some sort of business object that I now have to go look at to see how to interact with it?</p>
<p>Isn&#8217;t this only useful when you see the class name in isolation from the variable name (which is fairly infrequent)? Otherwise, I have the variable right there to tell me what I&#8217;m dealing with&#8230; What price do I pay with string representation that can&#8217;t be solved by better variable names?</p>
<p>Given the fact that extra classes take extra time to write, they are not immediately familiar to users (whereas the API for String etc is pretty commonly understood) and so therefore can cause confusion, and that your examples almost completely duplicate the variable name when defining the class name, and that class names are so much less visible than variable names, I must say I&#8217;m at a complete loss for your motivation, especially in large projects where all of these issues would compound themselves. Can you please provide a more elaborate use case where perhaps you couldn&#8217;t make inferences from the variable names, or thereabouts?</p>
<p>I can see your point perhaps if you have a type that may change over time&#8230; for example, if you start with &#8220;int id&#8221;, but then need to move to &#8220;Guid id&#8221;, better to write that up front, but that doesn&#8217;t seem to be what you&#8217;re saying. Please tell me I&#8217;m misunderstanding you?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Kern</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-671679</link>
		<dc:creator>Jon Kern</dc:creator>
		<pubDate>Thu, 15 Sep 2011 18:30:01 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-671679</guid>
		<description>Of course, you could switch to Ruby where you don&#039;t need to put in extra cruft in your code to help out the lazy compiler .

def book_ticket( name, first_name, film, count, cinema)
   ...
end</description>
		<content:encoded><![CDATA[<p>Of course, you could switch to Ruby where you don&#8217;t need to put in extra cruft in your code to help out the lazy compiler .</p>
<p>def book_ticket( name, first_name, film, count, cinema)<br />
   &#8230;<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 永远不要在Java中使用String(至少也尽量少用:-) &#124; 形愁者思远</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-452770</link>
		<dc:creator>永远不要在Java中使用String(至少也尽量少用:-) &#124; 形愁者思远</dc:creator>
		<pubDate>Tue, 15 Mar 2011 12:42:58 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-452770</guid>
		<description>[...] ［文章翻译自：http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/&#160;请任意转载］ [...]</description>
		<content:encoded><![CDATA[<p>[...] ［文章翻译自：http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/&#160;请任意转载］ [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: String is evil &#124; KOPIS.DE</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-386758</link>
		<dc:creator>String is evil &#124; KOPIS.DE</dc:creator>
		<pubDate>Thu, 23 Dec 2010 14:30:40 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-386758</guid>
		<description>[...] wrote a good article about evil Strings over at codemonkeyism, so I won&#8217;t give another example here. But if you are tempted to add a integer parameter or a [...]</description>
		<content:encoded><![CDATA[<p>[...] wrote a good article about evil Strings over at codemonkeyism, so I won&#8217;t give another example here. But if you are tempted to add a integer parameter or a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raphael</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-382455</link>
		<dc:creator>Raphael</dc:creator>
		<pubDate>Fri, 17 Dec 2010 14:51:10 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-382455</guid>
		<description>Some of your arguments, Stephan, have merit, others don&#039;t. As long as you are wrapping for the sake of later expandability, I agree fully. I consider your arguments regarding clarity invalid, though. &quot;Name name&quot; does not hold more information than &quot;String name&quot;; both require sufficient parameter documentation. Especially so since you will soon have (subtypes of) Name in several packages or in flavors as CarName, PersonName, ...

You fail to outline further problems your approach might introduce. For example, using Id instead of int as identifiers: Having two objects A, B representing the same database entry, will A.id == B.id? Or in above vision of namespace pollution, which *Name to choose?</description>
		<content:encoded><![CDATA[<p>Some of your arguments, Stephan, have merit, others don&#8217;t. As long as you are wrapping for the sake of later expandability, I agree fully. I consider your arguments regarding clarity invalid, though. &#8220;Name name&#8221; does not hold more information than &#8220;String name&#8221;; both require sufficient parameter documentation. Especially so since you will soon have (subtypes of) Name in several packages or in flavors as CarName, PersonName, &#8230;</p>
<p>You fail to outline further problems your approach might introduce. For example, using Id instead of int as identifiers: Having two objects A, B representing the same database entry, will A.id == B.id? Or in above vision of namespace pollution, which *Name to choose?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Poka-Yoke Your Code &#171; The Hacker Chick Blog</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-323421</link>
		<dc:creator>Poka-Yoke Your Code &#171; The Hacker Chick Blog</dc:creator>
		<pubDate>Mon, 06 Sep 2010 17:26:42 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-323421</guid>
		<description>[...] up from run-time detection to compile time detection. Using thing like using generics and favoring objects over primitives. And avoiding hacks like hiding things in String or Object types that might feel flexible but that [...]</description>
		<content:encoded><![CDATA[<p>[...] up from run-time detection to compile time detection. Using thing like using generics and favoring objects over primitives. And avoiding hacks like hiding things in String or Object types that might feel flexible but that [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-299830</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 17 Jun 2010 13:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-299830</guid>
		<description>@Chad: Thanks, yes because as I said on another post:

&quot;I was using named parameters the first time during the 80 I guess with a programming language called E on the Amiga (or was it the 90s?). I like the idea since then, but Java regretfully doesn’t have them.&quot;</description>
		<content:encoded><![CDATA[<p>@Chad: Thanks, yes because as I said on another post:</p>
<p>&#8220;I was using named parameters the first time during the 80 I guess with a programming language called E on the Amiga (or was it the 90s?). I like the idea since then, but Java regretfully doesn’t have them.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-299167</link>
		<dc:creator>Chad</dc:creator>
		<pubDate>Mon, 14 Jun 2010 23:37:33 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-299167</guid>
		<description>I can&#039;t believe all the haters on this blog. Take the example and use it as appropriate. My god.

Thanks for taking the time to share this Stephan. What it first hit me as is a way to emulate named parameters in Java. Very useful and thanks again.</description>
		<content:encoded><![CDATA[<p>I can&#8217;t believe all the haters on this blog. Take the example and use it as appropriate. My god.</p>
<p>Thanks for taking the time to share this Stephan. What it first hit me as is a way to emulate named parameters in Java. Very useful and thanks again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; String is evil :KOPIS.DE</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-292026</link>
		<dc:creator>&#187; String is evil :KOPIS.DE</dc:creator>
		<pubDate>Tue, 18 May 2010 11:05:30 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-292026</guid>
		<description>[...] wrote a good article about evil Strings over at codemonkeyism, so I won&#8217;t give another example here. But if you are tempted to add a integer parameter or a [...]</description>
		<content:encoded><![CDATA[<p>[...] wrote a good article about evil Strings over at codemonkeyism, so I won&#8217;t give another example here. But if you are tempted to add a integer parameter or a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-282160</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 08 Apr 2010 04:48:12 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-282160</guid>
		<description>@Mark: Thanks. Most of the time it isn&#039;t easy - and I&#039;ve been through my share of alt.*.advocacy Usenet flame wars.

But in the last years I&#039;m really more interested in &quot;truth&quot;, not opinion, which is hard in our business. A real impact on me had the Hacknot essays.</description>
		<content:encoded><![CDATA[<p>@Mark: Thanks. Most of the time it isn&#8217;t easy &#8211; and I&#8217;ve been through my share of alt.*.advocacy Usenet flame wars.</p>
<p>But in the last years I&#8217;m really more interested in &#8220;truth&#8221;, not opinion, which is hard in our business. A real impact on me had the Hacknot essays.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Kaiser</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-282057</link>
		<dc:creator>Mark Kaiser</dc:creator>
		<pubDate>Wed, 07 Apr 2010 19:11:41 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-282057</guid>
		<description>Stephan,

It really amazes me how often people in our business like to condescend and patronize using straw man arguments and ad hominem attacks while responding to a post with which they disagree.  You would think that folks seemingly used to the clean logic of code would be able to have a debate based upon the logic and merits of the argument itself, and not attack the author.

I laud you for your thoughtful ideas and measured responses, when it would be easy to stoop to such a level.   I also noticed that you were often the only person in this long long list of responses that would admit shortcomings in your argument and correct yourself in the process - when your opposition would often just keep trying to hammer their point.   I am very impressed.

This pattern you present is definitely worth consideration - and I agree - NEVER use double for any kind of money representation.  At the very least, use BigDecimal.  ;)  

I really like it for ids for domain objects.   the interface for most any id can be the same for them all - Identifier - with OrderIdentifier(Impl) having different implementations than ProductIdentifier(Impl) than SomeOtherIdentifier(Impl).  That seems a beautiful and elegant way to keep those implementations hidden - who really cares how to construct the id, except the data access layer?  Everyone else in the stack can just pass that Identifier around, use accessor methods, and call toString for the UI to use if needed.  

Nifty!  Thanks.</description>
		<content:encoded><![CDATA[<p>Stephan,</p>
<p>It really amazes me how often people in our business like to condescend and patronize using straw man arguments and ad hominem attacks while responding to a post with which they disagree.  You would think that folks seemingly used to the clean logic of code would be able to have a debate based upon the logic and merits of the argument itself, and not attack the author.</p>
<p>I laud you for your thoughtful ideas and measured responses, when it would be easy to stoop to such a level.   I also noticed that you were often the only person in this long long list of responses that would admit shortcomings in your argument and correct yourself in the process &#8211; when your opposition would often just keep trying to hammer their point.   I am very impressed.</p>
<p>This pattern you present is definitely worth consideration &#8211; and I agree &#8211; NEVER use double for any kind of money representation.  At the very least, use BigDecimal.  ;)  </p>
<p>I really like it for ids for domain objects.   the interface for most any id can be the same for them all &#8211; Identifier &#8211; with OrderIdentifier(Impl) having different implementations than ProductIdentifier(Impl) than SomeOtherIdentifier(Impl).  That seems a beautiful and elegant way to keep those implementations hidden &#8211; who really cares how to construct the id, except the data access layer?  Everyone else in the stack can just pass that Identifier around, use accessor methods, and call toString for the UI to use if needed.  </p>
<p>Nifty!  Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-280035</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Tue, 30 Mar 2010 04:17:28 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-280035</guid>
		<description>@Lukasz: pollutung the design? I suggest watching

http://www.infoq.com/presentations/Value-Objects-Dan-Bergh-Johnsson</description>
		<content:encoded><![CDATA[<p>@Lukasz: pollutung the design? I suggest watching</p>
<p><a href="http://www.infoq.com/presentations/Value-Objects-Dan-Bergh-Johnsson" rel="nofollow">http://www.infoq.com/presentations/Value-Objects-Dan-Bergh-Johnsson</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lukasz</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-280021</link>
		<dc:creator>Lukasz</dc:creator>
		<pubDate>Tue, 30 Mar 2010 03:08:14 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-280021</guid>
		<description>The author discourages the use of Strings and primitive types for method arguments in favor of descriptive classes because his IDE doesn&#039;t show the names of variables during code completion. 

An effective javadoc in an effective IDE can solve the author&#039;s problem without unnecessarily polluting the design.</description>
		<content:encoded><![CDATA[<p>The author discourages the use of Strings and primitive types for method arguments in favor of descriptive classes because his IDE doesn&#8217;t show the names of variables during code completion. </p>
<p>An effective javadoc in an effective IDE can solve the author&#8217;s problem without unnecessarily polluting the design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-278155</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Sat, 20 Mar 2010 19:18:37 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-278155</guid>
		<description>Interesting.  Not only almost entirely your opinion regarding whether this is a good idea or not, but bad practice.

I wonder why the Sun code base doesn&#039;t do this ... oh yeah, bloated overhead is also a bad practice.

In truth, proper design and docs alleviates what a method does.  I mean really, do you have a sticker on your car keys that say &quot;this is used to start my car&quot;?

If you need this much direction on anything, then maybe we need a batch file that executes java that says &quot;this is how we compile code.bat&quot;.

In the end, things MUST be of a primitive nature, either in code or in persistence (no Classes in databases).  If you ever took the time to unwrap the Integer class, at the base, is an INT .. hmmm, maybe you should check out the Java source code.

Oh well, good luck with this strange way of trying to be efficient.

Peter</description>
		<content:encoded><![CDATA[<p>Interesting.  Not only almost entirely your opinion regarding whether this is a good idea or not, but bad practice.</p>
<p>I wonder why the Sun code base doesn&#8217;t do this &#8230; oh yeah, bloated overhead is also a bad practice.</p>
<p>In truth, proper design and docs alleviates what a method does.  I mean really, do you have a sticker on your car keys that say &#8220;this is used to start my car&#8221;?</p>
<p>If you need this much direction on anything, then maybe we need a batch file that executes java that says &#8220;this is how we compile code.bat&#8221;.</p>
<p>In the end, things MUST be of a primitive nature, either in code or in persistence (no Classes in databases).  If you ever took the time to unwrap the Integer class, at the base, is an INT .. hmmm, maybe you should check out the Java source code.</p>
<p>Oh well, good luck with this strange way of trying to be efficient.</p>
<p>Peter</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-275891</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Tue, 09 Mar 2010 17:21:14 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-275891</guid>
		<description>@Emilien: Encoding the (Sub-)Type in the name of classes is not a practice I favor, it leads to tighter - syntactic - coupling.</description>
		<content:encoded><![CDATA[<p>@Emilien: Encoding the (Sub-)Type in the name of classes is not a practice I favor, it leads to tighter &#8211; syntactic &#8211; coupling.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emilien</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-275889</link>
		<dc:creator>Emilien</dc:creator>
		<pubDate>Tue, 09 Mar 2010 17:13:27 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-275889</guid>
		<description>Hello, 

I found this article and the comments very interesting -I just read many- and, as a java beginner, I wondered if a name convention for the &quot;String objects&quot; like NameString (for the Bookticket object) would be a good idea to explain this way of thinking ?

Emilien.</description>
		<content:encoded><![CDATA[<p>Hello, </p>
<p>I found this article and the comments very interesting -I just read many- and, as a java beginner, I wondered if a name convention for the &#8220;String objects&#8221; like NameString (for the Bookticket object) would be a good idea to explain this way of thinking ?</p>
<p>Emilien.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-274944</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 04 Mar 2010 11:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-274944</guid>
		<description>@Antonio: I disagree for the reasons mentioned in the post.</description>
		<content:encoded><![CDATA[<p>@Antonio: I disagree for the reasons mentioned in the post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antonio</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-274943</link>
		<dc:creator>Antonio</dc:creator>
		<pubDate>Thu, 04 Mar 2010 10:59:03 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-274943</guid>
		<description>Come on, use common sense this is unnecessary and verbose. Then is not convincing even from a theoretical point of view. 
In programming the abstraction is never an end in itself but is functional to the problem. The definition of a class &quot;Name&quot; would make sense only if you have to do special processing on the names.

bye
Antonio</description>
		<content:encoded><![CDATA[<p>Come on, use common sense this is unnecessary and verbose. Then is not convincing even from a theoretical point of view.<br />
In programming the abstraction is never an end in itself but is functional to the problem. The definition of a class &#8220;Name&#8221; would make sense only if you have to do special processing on the names.</p>
<p>bye<br />
Antonio</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-274914</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 04 Mar 2010 06:33:35 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-274914</guid>
		<description>&quot;Howerver I considerthat like all rules for good design, more important than merely applying them it to know them, know when to apply them, why to apply them and how to apply them.&quot;

I agrre with that, and will reread Fowler.</description>
		<content:encoded><![CDATA[<p>&#8220;Howerver I considerthat like all rules for good design, more important than merely applying them it to know them, know when to apply them, why to apply them and how to apply them.&#8221;</p>
<p>I agrre with that, and will reread Fowler.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Ribeiro</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-274888</link>
		<dc:creator>Daniel Ribeiro</dc:creator>
		<pubDate>Thu, 04 Mar 2010 04:12:09 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-274888</guid>
		<description>Good post. Caught my attention due to your current layout improvement, and the fact that was one of the few posts I had not read.

But this being such an old post, I was amazed that no-one mentioned &quot;Primitive obssesion&quot; code smell from Martin Folwer&#039;s book. Jeff Atwood comments on this as well: http://www.codinghorror.com/blog/2006/05/code-smells.html.

Howerver I considerthat like all rules for good design, more important than merely applying them it to know them,  know when to apply them, why to apply them and how to apply them. But I am a TDD/agressive refactoring/XP fan, therefore I do not fear old bad design decisions.

On the other hand, primitive obsession is very damaging to DDD, as it really defies the purpose of ubiquitous language and business readable code (at least for business rules). And not only to static languages, but on dynamic languages as well (for instance, Folwer kept the code smell on his Refactoring Ruby with Jay Fields), even though the looser coupling due to lack of type annotations focus more on good names than on good types (and makes it easier to refactor).</description>
		<content:encoded><![CDATA[<p>Good post. Caught my attention due to your current layout improvement, and the fact that was one of the few posts I had not read.</p>
<p>But this being such an old post, I was amazed that no-one mentioned &#8220;Primitive obssesion&#8221; code smell from Martin Folwer&#8217;s book. Jeff Atwood comments on this as well: <a href="http://www.codinghorror.com/blog/2006/05/code-smells.html" rel="nofollow">http://www.codinghorror.com/blog/2006/05/code-smells.html</a>.</p>
<p>Howerver I considerthat like all rules for good design, more important than merely applying them it to know them,  know when to apply them, why to apply them and how to apply them. But I am a TDD/agressive refactoring/XP fan, therefore I do not fear old bad design decisions.</p>
<p>On the other hand, primitive obsession is very damaging to DDD, as it really defies the purpose of ubiquitous language and business readable code (at least for business rules). And not only to static languages, but on dynamic languages as well (for instance, Folwer kept the code smell on his Refactoring Ruby with Jay Fields), even though the looser coupling due to lack of type annotations focus more on good names than on good types (and makes it easier to refactor).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LuisKarlos</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-247725</link>
		<dc:creator>LuisKarlos</dc:creator>
		<pubDate>Sun, 11 Oct 2009 01:39:20 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-247725</guid>
		<description>mm.. it removes the generics from my code... :(</description>
		<content:encoded><![CDATA[<p>mm.. it removes the generics from my code&#8230; :(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LuisKarlos</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-247702</link>
		<dc:creator>LuisKarlos</dc:creator>
		<pubDate>Sat, 10 Oct 2009 19:19:22 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-247702</guid>
		<description>We found a possible nice solution for the thousands of classes problem.
In our case we were using integers as ID for some objects (after reading your article we thought that it is a very interesting point), so we decided to look for a solution... and this was it:

//THE PROBLEM
//Concrete classes
class User
{
  private int id; //strong typed int, messy primitive
  ...

class Role
{
  private int id; //strong typed int, messy primitive

Instead of using a simple int as ID we created this class:

//THE SOLUTION
public class ID
{
  private int id;
  
  public ID(int id)
  {
    this.id = id;
  }
  
  public void setId(int id)
  {
    this.id = id;
  }
  
  public int getId()
  {
    return id;
  }  
}


but now we have:

class User
{
  private ID id;//Strong typed ID
  ...

class Role
{
  private ID id;
  ...

This is a really nice enforcement of types. Now we can have:

  List&lt;ID&gt; usersID = ....
  List&lt;ID&gt; roleID = ....

  instead of

  List usersID = .....
  List roleID = ....


An even more Generic Solution:

//THE SOLUTION
public class ID
{
  private R id;
  
  public ID(R id)
  {
    this.id = id;
  }
  
  public void setId(R id)
  {
    this.id = id;
  }
  
  public R getId()
  {
    return id;
  }  
}</description>
		<content:encoded><![CDATA[<p>We found a possible nice solution for the thousands of classes problem.<br />
In our case we were using integers as ID for some objects (after reading your article we thought that it is a very interesting point), so we decided to look for a solution&#8230; and this was it:</p>
<p>//THE PROBLEM<br />
//Concrete classes<br />
class User<br />
{<br />
  private int id; //strong typed int, messy primitive<br />
  &#8230;</p>
<p>class Role<br />
{<br />
  private int id; //strong typed int, messy primitive</p>
<p>Instead of using a simple int as ID we created this class:</p>
<p>//THE SOLUTION<br />
public class ID<br />
{<br />
  private int id;</p>
<p>  public ID(int id)<br />
  {<br />
    this.id = id;<br />
  }</p>
<p>  public void setId(int id)<br />
  {<br />
    this.id = id;<br />
  }</p>
<p>  public int getId()<br />
  {<br />
    return id;<br />
  }<br />
}</p>
<p>but now we have:</p>
<p>class User<br />
{<br />
  private ID id;//Strong typed ID<br />
  &#8230;</p>
<p>class Role<br />
{<br />
  private ID id;<br />
  &#8230;</p>
<p>This is a really nice enforcement of types. Now we can have:</p>
<p>  List&lt;ID&gt; usersID = &#8230;.<br />
  List&lt;ID&gt; roleID = &#8230;.</p>
<p>  instead of</p>
<p>  List usersID = &#8230;..<br />
  List roleID = &#8230;.</p>
<p>An even more Generic Solution:</p>
<p>//THE SOLUTION<br />
public class ID<br />
{<br />
  private R id;</p>
<p>  public ID(R id)<br />
  {<br />
    this.id = id;<br />
  }</p>
<p>  public void setId(R id)<br />
  {<br />
    this.id = id;<br />
  }</p>
<p>  public R getId()<br />
  {<br />
    return id;<br />
  }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cd</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-245387</link>
		<dc:creator>cd</dc:creator>
		<pubDate>Wed, 23 Sep 2009 15:53:16 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-245387</guid>
		<description>ulf,
Create ur own String object.
Unzip src.zip in ur JDK directory and change the package name on the String object.
Then ur set.</description>
		<content:encoded><![CDATA[<p>ulf,<br />
Create ur own String object.<br />
Unzip src.zip in ur JDK directory and change the package name on the String object.<br />
Then ur set.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cd</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-245383</link>
		<dc:creator>cd</dc:creator>
		<pubDate>Wed, 23 Sep 2009 15:31:34 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-245383</guid>
		<description>When does the headache end?
Never, never, never use (unwrapped) String or long or int?
Give me a break.
The next thing u will be saying is to make objects for objects for objects for objects ...

Here is a idea you can use &quot;KISS&quot;.
(K)eep (I)t (S)imple (S)tupid

Over complicating a simple data holding object is a waste of time, memory, and processing.</description>
		<content:encoded><![CDATA[<p>When does the headache end?<br />
Never, never, never use (unwrapped) String or long or int?<br />
Give me a break.<br />
The next thing u will be saying is to make objects for objects for objects for objects &#8230;</p>
<p>Here is a idea you can use &#8220;KISS&#8221;.<br />
(K)eep (I)t (S)imple (S)tupid</p>
<p>Over complicating a simple data holding object is a waste of time, memory, and processing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mebigfatguy</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-244506</link>
		<dc:creator>mebigfatguy</dc:creator>
		<pubDate>Fri, 18 Sep 2009 14:28:21 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-244506</guid>
		<description>The humorous thing isn&#039;t the post itself, but the rush by people to agree hardily to anything that has been written in a blog. Just Hilarious.</description>
		<content:encoded><![CDATA[<p>The humorous thing isn&#8217;t the post itself, but the rush by people to agree hardily to anything that has been written in a blog. Just Hilarious.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ulf</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-240879</link>
		<dc:creator>ulf</dc:creator>
		<pubDate>Tue, 25 Aug 2009 09:00:40 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-240879</guid>
		<description>If only String wasn&#039;t final, then this could be so easy. And we could use those &quot;semantified primitives&quot; directly with existing APIs (&quot;semantified primitives&quot;, that&#039;s how i call them, even if i only really used that idea once, due to the obvious overhead).

Of course, a non-final String would be evil in many other aspects, so what we&#039;d really need would be a langauge change that made it legal to extend final classes whenever the implementation is not changed:

[code]class Name extends String; //empty implementation![/code]

or, for more complex cases:

[code]class Name extends String implements OneOfMyEmptyInterfaces; //empty implementation![/code]

Guess this will be left to languages like scala.</description>
		<content:encoded><![CDATA[<p>If only String wasn&#8217;t final, then this could be so easy. And we could use those &#8220;semantified primitives&#8221; directly with existing APIs (&#8220;semantified primitives&#8221;, that&#8217;s how i call them, even if i only really used that idea once, due to the obvious overhead).</p>
<p>Of course, a non-final String would be evil in many other aspects, so what we&#8217;d really need would be a langauge change that made it legal to extend final classes whenever the implementation is not changed:</p>
<p>[code]class Name extends String; //empty implementation![/code]</p>
<p>or, for more complex cases:</p>
<p>[code]class Name extends String implements OneOfMyEmptyInterfaces; //empty implementation![/code]</p>
<p>Guess this will be left to languages like scala.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fabian</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-3/#comment-239342</link>
		<dc:creator>Fabian</dc:creator>
		<pubDate>Fri, 14 Aug 2009 12:26:30 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-239342</guid>
		<description>Hi Stephen,

I&#039;ve read your post and I found it _really_ interesting in terms of OO programming. That&#039;s the kinda things I love to learn and understand. So thx for this :-)

Still, I wonder what the consequences are on O/R mapping. I haven&#039;t had the time to read all the comments, I just saw some people asking about mapping with Hibernate, and didn&#039;t find any anwser on that topic. If you define Name and FirstName classes that can be used by several other classes, handle the O/R mapping will be a nightmare, won&#039;t it? (I guess you won&#039;t create a specific table for Name and another one for FirstName, as you would have too many joints) Do you then have to handle the persistance layer by yourself without a O/R mapping framework? (or you just use object databases ;-))

Cheers!
Fab</description>
		<content:encoded><![CDATA[<p>Hi Stephen,</p>
<p>I&#8217;ve read your post and I found it _really_ interesting in terms of OO programming. That&#8217;s the kinda things I love to learn and understand. So thx for this :-)</p>
<p>Still, I wonder what the consequences are on O/R mapping. I haven&#8217;t had the time to read all the comments, I just saw some people asking about mapping with Hibernate, and didn&#8217;t find any anwser on that topic. If you define Name and FirstName classes that can be used by several other classes, handle the O/R mapping will be a nightmare, won&#8217;t it? (I guess you won&#8217;t create a specific table for Name and another one for FirstName, as you would have too many joints) Do you then have to handle the persistance layer by yourself without a O/R mapping framework? (or you just use object databases ;-))</p>
<p>Cheers!<br />
Fab</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niclas Hedhman</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-228664</link>
		<dc:creator>Niclas Hedhman</dc:creator>
		<pubDate>Sun, 19 Apr 2009 11:53:17 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-228664</guid>
		<description>@Alberto; You may think so, probably deriving it from an observation that you have approx 10 strings in every hibernate class, hence the 10 times as many classes. In reality, you will find that the bigger the program the greater the benefit, i.e. each type of string is showing up in many, many places and with an explicit type you get additional &#039;communication of intent&#039;.
I happen to be of the opinion that there are a few exceptions. System.out.println( String message ) is a classic example, but as soon as the string has a format, range, or implicit meaning, i.e. most of the time, then Stephan&#039;s suggestion is very, very good for long-term maintenance.</description>
		<content:encoded><![CDATA[<p>@Alberto; You may think so, probably deriving it from an observation that you have approx 10 strings in every hibernate class, hence the 10 times as many classes. In reality, you will find that the bigger the program the greater the benefit, i.e. each type of string is showing up in many, many places and with an explicit type you get additional &#8216;communication of intent&#8217;.<br />
I happen to be of the opinion that there are a few exceptions. System.out.println( String message ) is a classic example, but as soon as the string has a format, range, or implicit meaning, i.e. most of the time, then Stephan&#8217;s suggestion is very, very good for long-term maintenance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-228662</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sun, 19 Apr 2009 11:41:54 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-228662</guid>
		<description>@Alberto: Could be that I&#039;ve only worked on &quot;toy programs&quot;, I don&#039;t know what you consider &quot;big&quot;. The largest apps I&#039;ve worked with were &gt;10k classes and 1.5 MLOC. 

And I&#039;m not sure either what you consider &quot;experienced&quot; - because you don&#039;t give a definition. I&#039;ve written code for around 30 years in around 20 programming languages. 

For more information see the link label &quot;About me&quot; at the top.</description>
		<content:encoded><![CDATA[<p>@Alberto: Could be that I&#8217;ve only worked on &#8220;toy programs&#8221;, I don&#8217;t know what you consider &#8220;big&#8221;. The largest apps I&#8217;ve worked with were >10k classes and 1.5 MLOC. </p>
<p>And I&#8217;m not sure either what you consider &#8220;experienced&#8221; &#8211; because you don&#8217;t give a definition. I&#8217;ve written code for around 30 years in around 20 programming languages. </p>
<p>For more information see the link label &#8220;About me&#8221; at the top.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alberto gori</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-228659</link>
		<dc:creator>alberto gori</dc:creator>
		<pubDate>Sun, 19 Apr 2009 11:17:28 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-228659</guid>
		<description>I wonder how an experienced programmer could end up with such proposal.

Have you ever worked on some big projects or only toy programs with ten classes?

For example, if I follow your apprach, mapping hundreds of hibernate entities, I would end up with thousands of new classes. 

It&#039;s simply impossible to code, read and mantain.</description>
		<content:encoded><![CDATA[<p>I wonder how an experienced programmer could end up with such proposal.</p>
<p>Have you ever worked on some big projects or only toy programs with ten classes?</p>
<p>For example, if I follow your apprach, mapping hundreds of hibernate entities, I would end up with thousands of new classes. </p>
<p>It&#8217;s simply impossible to code, read and mantain.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel C</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-227883</link>
		<dc:creator>Gabriel C</dc:creator>
		<pubDate>Wed, 08 Apr 2009 23:20:07 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-227883</guid>
		<description>I&#039;ve expanded my point of view in a blog post:
http://gabrielsw.blogspot.com/2009/04/spare-change-at-whole-static-vs-dynamic.html</description>
		<content:encoded><![CDATA[<p>I&#8217;ve expanded my point of view in a blog post:<br />
<a href="http://gabrielsw.blogspot.com/2009/04/spare-change-at-whole-static-vs-dynamic.html" rel="nofollow">http://gabrielsw.blogspot.com/2009/04/spare-change-at-whole-static-vs-dynamic.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Faanes</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-226361</link>
		<dc:creator>Aaron Faanes</dc:creator>
		<pubDate>Tue, 03 Mar 2009 09:37:08 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-226361</guid>
		<description>I know this post is rather old, but I figured I&#039;d toss my two cents in:

For one, I completely agree with the opening post. I find the mocking replies to this post frankly offensive, on a few levels. The author does not suggest to meaninglessly wrap primitives simply to do so to make life harder. His suggestion is to not use ambiguous types where specific ones are more appropriate. String, double, int, and so forth, have no real context, no rules governing their use or mutability. (Beyond those introduced in the declaration through modifiers and visibility)

Primitives imply no meaning and leave it up to the developer to determine what is in fact valid and what is not. I mean, some replies said that doing this pattern &quot;simply [so] your IDE will do a better job of helping you understand the code.&quot; As though that is some travesty!

To say that the indirection is meaningless seems to assume that all values that a String can hold are also valid for someone&#039;s name. For example, Strings can be null, &quot;      &quot;, &quot;&quot;, &quot;$@##%%@%#&amp;^$%&quot;, &quot;a&quot;. Are these all suitable names? They must be, since using String directly for the name is apparently the trendy thing to do.

After listing those, to use TDD as an example that String is in fact the best data-type is simply absurd. The tests you make must have dreadfully poor coverage.

Of course, the easy solution to my scenario is to test for these cases in the setter, and throw IllegalArgumentException&#039;s whenever these situations occur. Indeed, one can jury-rig all kinds of conditions into this BookTicket class to assure validity. A previous reply by Xavier explains the reasons why this is a bad idea (Centralized validation, throwing exceptions at the logical place where the exception occurred, and so forth)

After all, it&#039;s highly unlikely this is the only place in this project where you would have a name - most likely, you&#039;d use it many places, and each would be vulnerable to the same invalid test-cases described above. An &#039;agile&#039;, YAGNI-inspired solution of &#039;using strings because its ez&#039; would waste time and force the developer and tester to ensure everywhere a name is used, that it&#039;s correct.

Beyond these practical concerns, a more pressing concern would arise. The BookTicket class&#039;s responsibility lies in accurately representing the state of a BookTicket. It should not have to worry about making sure someone&#039;s name doesn&#039;t consist of only letters. It should not have to worry about whether the orderID is already in use. It&#039;s a simple class, and should be made simply.

The idea of responsibility-driven design is an old one, and I think one that&#039;s often forgotten by people. It&#039;s become second-nature to just pile features and functionality unto one class, under the convenient guise of YAGNI to belie a hidden sense of downright laziness.

I doubt I am alone in finding a few, small classes _easier_ to understand, than one monolith, whose implementation must span the gamut between name validation, orderID validation, and BookTicket representation. This defiles the true intent of the class, and makes maintenance, extensibility, testing, and understanding the code a nightmare.

An analogy to this concept that comes to mind is HTML tables. I remember reading a post about how they&#039;re flagrantly abused to layout pages, when in fact they&#039;re simply intended to (surprise!) represent tabular data. Now, getting a consistent layout can be difficult, so I can understand being lax on that point, but there is *no* excuse for being amateur when it comes to Java.

A String should be used to represent arbitrary text. An integer should be used to represent an arbitrary integer value. If these are sufficient (e.g. can be null, random symbols, Chinese characters, etc. in the case of String), then by all means, but to assume that just because a name consists of letters means that it should be a String is madness.</description>
		<content:encoded><![CDATA[<p>I know this post is rather old, but I figured I&#8217;d toss my two cents in:</p>
<p>For one, I completely agree with the opening post. I find the mocking replies to this post frankly offensive, on a few levels. The author does not suggest to meaninglessly wrap primitives simply to do so to make life harder. His suggestion is to not use ambiguous types where specific ones are more appropriate. String, double, int, and so forth, have no real context, no rules governing their use or mutability. (Beyond those introduced in the declaration through modifiers and visibility)</p>
<p>Primitives imply no meaning and leave it up to the developer to determine what is in fact valid and what is not. I mean, some replies said that doing this pattern &#8220;simply [so] your IDE will do a better job of helping you understand the code.&#8221; As though that is some travesty!</p>
<p>To say that the indirection is meaningless seems to assume that all values that a String can hold are also valid for someone&#8217;s name. For example, Strings can be null, &#8221;      &#8220;, &#8220;&#8221;, &#8220;$@##%%@%#&amp;^$%&#8221;, &#8220;a&#8221;. Are these all suitable names? They must be, since using String directly for the name is apparently the trendy thing to do.</p>
<p>After listing those, to use TDD as an example that String is in fact the best data-type is simply absurd. The tests you make must have dreadfully poor coverage.</p>
<p>Of course, the easy solution to my scenario is to test for these cases in the setter, and throw IllegalArgumentException&#8217;s whenever these situations occur. Indeed, one can jury-rig all kinds of conditions into this BookTicket class to assure validity. A previous reply by Xavier explains the reasons why this is a bad idea (Centralized validation, throwing exceptions at the logical place where the exception occurred, and so forth)</p>
<p>After all, it&#8217;s highly unlikely this is the only place in this project where you would have a name &#8211; most likely, you&#8217;d use it many places, and each would be vulnerable to the same invalid test-cases described above. An &#8216;agile&#8217;, YAGNI-inspired solution of &#8216;using strings because its ez&#8217; would waste time and force the developer and tester to ensure everywhere a name is used, that it&#8217;s correct.</p>
<p>Beyond these practical concerns, a more pressing concern would arise. The BookTicket class&#8217;s responsibility lies in accurately representing the state of a BookTicket. It should not have to worry about making sure someone&#8217;s name doesn&#8217;t consist of only letters. It should not have to worry about whether the orderID is already in use. It&#8217;s a simple class, and should be made simply.</p>
<p>The idea of responsibility-driven design is an old one, and I think one that&#8217;s often forgotten by people. It&#8217;s become second-nature to just pile features and functionality unto one class, under the convenient guise of YAGNI to belie a hidden sense of downright laziness.</p>
<p>I doubt I am alone in finding a few, small classes _easier_ to understand, than one monolith, whose implementation must span the gamut between name validation, orderID validation, and BookTicket representation. This defiles the true intent of the class, and makes maintenance, extensibility, testing, and understanding the code a nightmare.</p>
<p>An analogy to this concept that comes to mind is HTML tables. I remember reading a post about how they&#8217;re flagrantly abused to layout pages, when in fact they&#8217;re simply intended to (surprise!) represent tabular data. Now, getting a consistent layout can be difficult, so I can understand being lax on that point, but there is *no* excuse for being amateur when it comes to Java.</p>
<p>A String should be used to represent arbitrary text. An integer should be used to represent an arbitrary integer value. If these are sufficient (e.g. can be null, random symbols, Chinese characters, etc. in the case of String), then by all means, but to assume that just because a name consists of letters means that it should be a String is madness.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niclas Hedhman</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-224287</link>
		<dc:creator>Niclas Hedhman</dc:creator>
		<pubDate>Sat, 10 Jan 2009 13:43:35 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-224287</guid>
		<description>Just want to announce that Qi4j now have its own equivalent recommended by this blog entry.

public interface SocialSecurityNumber extends Property
{}

which can then have constraint rules added to it centrally;

@Constraints( SocialSecurityNumberConstraint.class )
public interface SocialSecurityNumber extends Property
{}

I am pretty convinced that this technique will make apps a lot more robust in the long run.</description>
		<content:encoded><![CDATA[<p>Just want to announce that Qi4j now have its own equivalent recommended by this blog entry.</p>
<p>public interface SocialSecurityNumber extends Property<br />
{}</p>
<p>which can then have constraint rules added to it centrally;</p>
<p>@Constraints( SocialSecurityNumberConstraint.class )<br />
public interface SocialSecurityNumber extends Property<br />
{}</p>
<p>I am pretty convinced that this technique will make apps a lot more robust in the long run.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lumpynose</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-210408</link>
		<dc:creator>lumpynose</dc:creator>
		<pubDate>Fri, 05 Dec 2008 00:28:01 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-210408</guid>
		<description>@Dan: &quot;How many times do I have to look up TaskID to know it is ‘really’ an integer? In fact, I never have to look that up. I know it is an integer. Everyone working on this system knows it is an integer. And if we have a new developer, he will have to look at the TaskID class once to see it is an integer.&quot;

I definitely agree with your overall ideas, but for this particular part I tend to think that you&#039;re not likely to really or often need to know what&#039;s inside of a ProjectId or TaskId class; it could be a single primitive, or a salmagundi of things.  And that&#039;s good.</description>
		<content:encoded><![CDATA[<p>@Dan: &#8220;How many times do I have to look up TaskID to know it is ‘really’ an integer? In fact, I never have to look that up. I know it is an integer. Everyone working on this system knows it is an integer. And if we have a new developer, he will have to look at the TaskID class once to see it is an integer.&#8221;</p>
<p>I definitely agree with your overall ideas, but for this particular part I tend to think that you&#8217;re not likely to really or often need to know what&#8217;s inside of a ProjectId or TaskId class; it could be a single primitive, or a salmagundi of things.  And that&#8217;s good.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-197954</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 13 Nov 2008 14:49:12 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-197954</guid>
		<description>@Nathan: Thanks for your comment. Yes I had the problem also several times in the past.</description>
		<content:encoded><![CDATA[<p>@Nathan: Thanks for your comment. Yes I had the problem also several times in the past.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-197953</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Thu, 13 Nov 2008 14:43:39 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-197953</guid>
		<description>Just wanted to say that less than an hour after I read this I ran into a problem on my project: &quot;what is customerId, and how do I find it?&quot;  The answer wasn&#039;t pretty.  The code wasn&#039;t reusable.  I will definitely be using these ideas on projects I have more control over.</description>
		<content:encoded><![CDATA[<p>Just wanted to say that less than an hour after I read this I ran into a problem on my project: &#8220;what is customerId, and how do I find it?&#8221;  The answer wasn&#8217;t pretty.  The code wasn&#8217;t reusable.  I will definitely be using these ideas on projects I have more control over.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-196374</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Tue, 11 Nov 2008 06:32:27 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-196374</guid>
		<description>@Dan: &lt;i&gt;&quot;I think there is value in creating a ProjectID class and a TaskID class so that the compiler can guarantee, not just that the ID I have received is an integer, but that it is an integer representing the ID of a task, and not the ID of a project.&quot;&lt;/i&gt;

I&#039;ve tried this too lately, and I really like it.  It makes code more readable than using int/long/String for IDs. As you&#039;ve saif, ProjectId is something different than TaskId. And with a growing code base, problems will arise if every Id is String/Int/Long. (mostly because developers - if you take enough of them - won&#039;t name every ProjectId the same, some call it ProjectId, some PID, etc. all being Longs. They can&#039;t screw up with a ProjectId type)

Thanks for your long comment, thanks for the insights.</description>
		<content:encoded><![CDATA[<p>@Dan: <i>&#8220;I think there is value in creating a ProjectID class and a TaskID class so that the compiler can guarantee, not just that the ID I have received is an integer, but that it is an integer representing the ID of a task, and not the ID of a project.&#8221;</i></p>
<p>I&#8217;ve tried this too lately, and I really like it.  It makes code more readable than using int/long/String for IDs. As you&#8217;ve saif, ProjectId is something different than TaskId. And with a growing code base, problems will arise if every Id is String/Int/Long. (mostly because developers &#8211; if you take enough of them &#8211; won&#8217;t name every ProjectId the same, some call it ProjectId, some PID, etc. all being Longs. They can&#8217;t screw up with a ProjectId type)</p>
<p>Thanks for your long comment, thanks for the insights.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-196143</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Mon, 10 Nov 2008 22:53:54 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-196143</guid>
		<description>Wow, this post generated a lot of controversy, which I missed.  I think the most salient points are from Sean (in that case just use Ruby) and Gabriel (compiler benefit).

We are Java developers and we are using a statically typed language.  By defining types at compile time we are giving the compiler the information it needs to make certain guarantees.  We can not use booleans where Strings are expected.  We can not use Strings where doubles are expected.  When a method accepts an integer parameter, we know it is receiving one; the compiler makes and keeps that promise.

The question is, how much information do we want to give the compiler to gain this benefit?  A lot of people here seem to be arguing that we should only create classes for compound types, and for value types we should just use whatever classes are available, because (I guess) creating classes is too much work.

I haven&#039;t read Domain Driven Development (though I may, now) but this is something I&#039;ve been thinking about lately.  To use an example from my project, a task ID is not a project ID, even though they&#039;re both stored in the database as number(10,0) and represented in Java by an int.  I think there is value in creating a ProjectID class and a TaskID class so that the compiler can guarantee, not just that the ID I have received is an integer, but that it is an integer representing the ID of a task, and not the ID of a project.

It is true that the IDs are populated somewhere using an integer, but it still greatly reduces the number of places in code that the knowledge that the ProjectID is implemented by an integer is embedded.  Lots of people have been saying, &quot;YAGNI&quot;.  I don&#039;t see this as a question of building something you ain&#039;t gonna need.  That principle as I understand it is to avoid building something because you think it might add value later.  Creating these &#039;domain primitive&#039; classes adds value today, the moment they are written, in the form of those compiler guarantees.  Also in the form of IDE assistance etc. which is definitely nice to have but secondary.  Less repetition, easier refactoring, and knowing that you have a ProjectID are also real benefits.

As far as saying that the code is =less= readable when using domain primitives ... I find that baffling.  How many times do I have to look up TaskID to know it is &#039;really&#039; an integer?  In fact, I never have to look that up.  I know it is an integer.  Everyone working on this system knows it is an integer.  And if we have a new developer, he will have to look at the TaskID class once to see it is an integer.

Every time a developer looks at a TaskID, he will know it is an integer.  But the converse is not true.  I can be looking at an integer.  Is it a task ID?  I don&#039;t know.  Even if the variable is called taskID, I don&#039;t know.  You bring up method declarations with many variables of the same type.  It is trivially easy to mix up arguments of the same type.

The cost of this approach ... well, I will have to write a TaskID class.  I expect that to take one minute.  Developers will have to look at the TaskID class to comprehend that it is represented by an integer, if they are working on a system boundary where they care how it is implemented.  I expect that to take ten seconds.  If it saves two minutes of debugging, it&#039;s worth it.

I liken it to using generics.  When Java 5 was released, I added generics to parts of our code base and found many bugs that had been lurking there.

Thanks for this post, Stephan.  You&#039;ve really given me something to think about.  I&#039;m going to try this, so that I can more fully exploit the strict type system that is after all one of the reasons I am using Java.</description>
		<content:encoded><![CDATA[<p>Wow, this post generated a lot of controversy, which I missed.  I think the most salient points are from Sean (in that case just use Ruby) and Gabriel (compiler benefit).</p>
<p>We are Java developers and we are using a statically typed language.  By defining types at compile time we are giving the compiler the information it needs to make certain guarantees.  We can not use booleans where Strings are expected.  We can not use Strings where doubles are expected.  When a method accepts an integer parameter, we know it is receiving one; the compiler makes and keeps that promise.</p>
<p>The question is, how much information do we want to give the compiler to gain this benefit?  A lot of people here seem to be arguing that we should only create classes for compound types, and for value types we should just use whatever classes are available, because (I guess) creating classes is too much work.</p>
<p>I haven&#8217;t read Domain Driven Development (though I may, now) but this is something I&#8217;ve been thinking about lately.  To use an example from my project, a task ID is not a project ID, even though they&#8217;re both stored in the database as number(10,0) and represented in Java by an int.  I think there is value in creating a ProjectID class and a TaskID class so that the compiler can guarantee, not just that the ID I have received is an integer, but that it is an integer representing the ID of a task, and not the ID of a project.</p>
<p>It is true that the IDs are populated somewhere using an integer, but it still greatly reduces the number of places in code that the knowledge that the ProjectID is implemented by an integer is embedded.  Lots of people have been saying, &#8220;YAGNI&#8221;.  I don&#8217;t see this as a question of building something you ain&#8217;t gonna need.  That principle as I understand it is to avoid building something because you think it might add value later.  Creating these &#8216;domain primitive&#8217; classes adds value today, the moment they are written, in the form of those compiler guarantees.  Also in the form of IDE assistance etc. which is definitely nice to have but secondary.  Less repetition, easier refactoring, and knowing that you have a ProjectID are also real benefits.</p>
<p>As far as saying that the code is =less= readable when using domain primitives &#8230; I find that baffling.  How many times do I have to look up TaskID to know it is &#8216;really&#8217; an integer?  In fact, I never have to look that up.  I know it is an integer.  Everyone working on this system knows it is an integer.  And if we have a new developer, he will have to look at the TaskID class once to see it is an integer.</p>
<p>Every time a developer looks at a TaskID, he will know it is an integer.  But the converse is not true.  I can be looking at an integer.  Is it a task ID?  I don&#8217;t know.  Even if the variable is called taskID, I don&#8217;t know.  You bring up method declarations with many variables of the same type.  It is trivially easy to mix up arguments of the same type.</p>
<p>The cost of this approach &#8230; well, I will have to write a TaskID class.  I expect that to take one minute.  Developers will have to look at the TaskID class to comprehend that it is represented by an integer, if they are working on a system boundary where they care how it is implemented.  I expect that to take ten seconds.  If it saves two minutes of debugging, it&#8217;s worth it.</p>
<p>I liken it to using generics.  When Java 5 was released, I added generics to parts of our code base and found many bugs that had been lurking there.</p>
<p>Thanks for this post, Stephan.  You&#8217;ve really given me something to think about.  I&#8217;m going to try this, so that I can more fully exploit the strict type system that is after all one of the reasons I am using Java.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-186287</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Fri, 24 Oct 2008 04:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-186287</guid>
		<description>@Niclas: Verification has been discussed somewhere in this thread I think.

@Gabriel: Yes, I also think it makes code less error prone.</description>
		<content:encoded><![CDATA[<p>@Niclas: Verification has been discussed somewhere in this thread I think.</p>
<p>@Gabriel: Yes, I also think it makes code less error prone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niclas Hedhman</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-186275</link>
		<dc:creator>Niclas Hedhman</dc:creator>
		<pubDate>Fri, 24 Oct 2008 04:05:26 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-186275</guid>
		<description>@Gabriel; You mean like;

bookTicket( new Name( &quot;Apocalypse Now&quot; ), new Film(&quot;Gabriel&quot; ), new Count(1) );

;-)

The Strings are coming from &quot;somewhere&quot; and they can be messed up along the way, no matter what you come up with...</description>
		<content:encoded><![CDATA[<p>@Gabriel; You mean like;</p>
<p>bookTicket( new Name( &#8220;Apocalypse Now&#8221; ), new Film(&#8220;Gabriel&#8221; ), new Count(1) );</p>
<p>;-)</p>
<p>The Strings are coming from &#8220;somewhere&#8221; and they can be messed up along the way, no matter what you come up with&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabriel C</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-186183</link>
		<dc:creator>Gabriel C</dc:creator>
		<pubDate>Thu, 23 Oct 2008 22:37:38 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-186183</guid>
		<description>I came to the same conclusion. Although I believe that following the domain closely is a good reason, my main motivation is to avoid errors leveraging the Java type system.
Slightly modifying your example: 
bookTicket(String arg0, String arg1, int arg3) 
versus 
bookTicket(Name arg0,  Film arg2, Count arg3)

In the first case, nothing prevents me to book a ticket to see the &quot;Gabriel&quot; movie in the name of &quot;Apocalypse Now&quot;... is very easy to mix up the parameters. To catch that I have to actually write a unit test for something the compiler is giving me for free!
Even if wrapping the parameters takes the same amount of code than the test, I don&#039;t need to run it to have the result.

I believe that for non trivial projects, having the (type) contract enforced by the compiler is a good thing :)</description>
		<content:encoded><![CDATA[<p>I came to the same conclusion. Although I believe that following the domain closely is a good reason, my main motivation is to avoid errors leveraging the Java type system.<br />
Slightly modifying your example:<br />
bookTicket(String arg0, String arg1, int arg3)<br />
versus<br />
bookTicket(Name arg0,  Film arg2, Count arg3)</p>
<p>In the first case, nothing prevents me to book a ticket to see the &#8220;Gabriel&#8221; movie in the name of &#8220;Apocalypse Now&#8221;&#8230; is very easy to mix up the parameters. To catch that I have to actually write a unit test for something the compiler is giving me for free!<br />
Even if wrapping the parameters takes the same amount of code than the test, I don&#8217;t need to run it to have the result.</p>
<p>I believe that for non trivial projects, having the (type) contract enforced by the compiler is a good thing :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-186099</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 23 Oct 2008 21:01:35 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-186099</guid>
		<description>@Ralf: Nice try. but I&#039;ve read to much Hofstadter to fall for this one.</description>
		<content:encoded><![CDATA[<p>@Ralf: Nice try. but I&#8217;ve read to much Hofstadter to fall for this one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ralf Schneider</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-186038</link>
		<dc:creator>Ralf Schneider</dc:creator>
		<pubDate>Thu, 23 Oct 2008 16:28:02 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-186038</guid>
		<description>That&#039;s not enough!
Be aware all your classes like Name still contain things like strings, integers, ... !!!!
Could you add another layer of indirection, please?

I&#039;m happy people like you exists!</description>
		<content:encoded><![CDATA[<p>That&#8217;s not enough!<br />
Be aware all your classes like Name still contain things like strings, integers, &#8230; !!!!<br />
Could you add another layer of indirection, please?</p>
<p>I&#8217;m happy people like you exists!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185221</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 22 Oct 2008 12:26:36 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185221</guid>
		<description>&quot;I doubt that you know all domains, [...]&quot; 

No I don&#039;t you&#039;re right. 

&quot;I just try to say, &#039;Balance&#039;&quot;

Yes, as the title is &quot;Never, never, never use String in Java (or at least less often :-)&quot; which was my amateur attempt to balance it :-) I totally agree with you, most often it&#039;s not an &quot;Either/Or&quot; choice.</description>
		<content:encoded><![CDATA[<p>&#8220;I doubt that you know all domains, [...]&#8221; </p>
<p>No I don&#8217;t you&#8217;re right. </p>
<p>&#8220;I just try to say, &#8216;Balance&#8217;&#8221;</p>
<p>Yes, as the title is &#8220;Never, never, never use String in Java (or at least less often :-)&#8221; which was my amateur attempt to balance it :-) I totally agree with you, most often it&#8217;s not an &#8220;Either/Or&#8221; choice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niclas Hedhman</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185218</link>
		<dc:creator>Niclas Hedhman</dc:creator>
		<pubDate>Wed, 22 Oct 2008 12:21:54 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185218</guid>
		<description>&quot;not that many String-types as you think there are. &quot; 
I doubt that you know all domains, and I just look at the numbers in my current project. Anyway, as I said; for the string based domain concepts, it indeed makes sense. As you said, not too many of them. And they clearly communicate intent, purpose and adds clarity. I think we are in general agreement, but people always see these kinds of &quot;Best Practices&quot; as an &quot;Either/Or&quot; choice. I just trying to say, &quot;Balance&quot;.</description>
		<content:encoded><![CDATA[<p>&#8220;not that many String-types as you think there are. &#8221;<br />
I doubt that you know all domains, and I just look at the numbers in my current project. Anyway, as I said; for the string based domain concepts, it indeed makes sense. As you said, not too many of them. And they clearly communicate intent, purpose and adds clarity. I think we are in general agreement, but people always see these kinds of &#8220;Best Practices&#8221; as an &#8220;Either/Or&#8221; choice. I just trying to say, &#8220;Balance&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185214</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 22 Oct 2008 12:11:32 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185214</guid>
		<description>@Niclas: Sorry to disagree, this is not a silver bullet discussion. What led you to believe this is one? I don&#039;t claim 10x productivity, I don&#039;t claim this will solve all your problems.

&lt;i&gt;&quot;The metaphor of the silver bullet applies to any straightforward solution perceived to have extreme effectiveness.&quot;&lt;/i&gt; -Wikipedia

I consider it more of a &quot;Best practice&quot; post.

&lt;i&gt;&quot;Having one class per String usage (which is the extreme case) sounds like ‘class explosion’ to me, not doable in large domains.&quot;&lt;/i&gt;

You will notice that there are not that many String-types as you think there are. Most of the time the Strings are of the same &quot;type&quot; - Name, Description, Titel and so on. Which more or less proves my point when developers cannot or do not categorize Strings into types but perceive all of them different.</description>
		<content:encoded><![CDATA[<p>@Niclas: Sorry to disagree, this is not a silver bullet discussion. What led you to believe this is one? I don&#8217;t claim 10x productivity, I don&#8217;t claim this will solve all your problems.</p>
<p><i>&#8220;The metaphor of the silver bullet applies to any straightforward solution perceived to have extreme effectiveness.&#8221;</i> -Wikipedia</p>
<p>I consider it more of a &#8220;Best practice&#8221; post.</p>
<p><i>&#8220;Having one class per String usage (which is the extreme case) sounds like ‘class explosion’ to me, not doable in large domains.&#8221;</i></p>
<p>You will notice that there are not that many String-types as you think there are. Most of the time the Strings are of the same &#8220;type&#8221; &#8211; Name, Description, Titel and so on. Which more or less proves my point when developers cannot or do not categorize Strings into types but perceive all of them different.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niclas Hedhman</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185203</link>
		<dc:creator>Niclas Hedhman</dc:creator>
		<pubDate>Wed, 22 Oct 2008 11:45:53 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185203</guid>
		<description>There are (as usual) valid cases for both approaches. To me this is a &quot;Silver Bullet&quot;-discussion, and if you have not learned this yet, say after me; There are NO silver bullets.

Having one class per String usage (which is the extreme case) sounds like &#039;class explosion&#039; to me, not doable in large domains. But selective use of &#039;domain types&#039; makes sense to improve readability.</description>
		<content:encoded><![CDATA[<p>There are (as usual) valid cases for both approaches. To me this is a &#8220;Silver Bullet&#8221;-discussion, and if you have not learned this yet, say after me; There are NO silver bullets.</p>
<p>Having one class per String usage (which is the extreme case) sounds like &#8216;class explosion&#8217; to me, not doable in large domains. But selective use of &#8216;domain types&#8217; makes sense to improve readability.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185198</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 22 Oct 2008 11:39:01 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185198</guid>
		<description>@alepuzio: Usually you do not need this vor every attribute, Name, Description, Order, Id, Range, Duration and more are reusable over several classes of your domain model.

That aside, yes there will be more classes.

I don&#039;t think it&#039;s too much, I think it helps read code:

(String, String, String) as a signature 

versus

(Name, Firstname, Description)

I find the second one more readable and being more clear.</description>
		<content:encoded><![CDATA[<p>@alepuzio: Usually you do not need this vor every attribute, Name, Description, Order, Id, Range, Duration and more are reusable over several classes of your domain model.</p>
<p>That aside, yes there will be more classes.</p>
<p>I don&#8217;t think it&#8217;s too much, I think it helps read code:</p>
<p>(String, String, String) as a signature </p>
<p>versus</p>
<p>(Name, Firstname, Description)</p>
<p>I find the second one more readable and being more clear.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alepuzio</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185184</link>
		<dc:creator>alepuzio</dc:creator>
		<pubDate>Wed, 22 Oct 2008 11:06:05 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185184</guid>
		<description>Hi stephan, 
but if you create an apposite Class for every attribute, have&#039;nt you an explosion of class?
In this way, you destroy all the clarity gained (by the class closer to domain) in a lot - too much - class?
If I create a class Name what is a simple wrapper of String

public class Name{


}</description>
		<content:encoded><![CDATA[<p>Hi stephan,<br />
but if you create an apposite Class for every attribute, have&#8217;nt you an explosion of class?<br />
In this way, you destroy all the clarity gained (by the class closer to domain) in a lot &#8211; too much &#8211; class?<br />
If I create a class Name what is a simple wrapper of String</p>
<p>public class Name{</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185173</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 22 Oct 2008 10:17:56 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185173</guid>
		<description>@Buddy: Yes could be. I thought named parameters are nice in any language where I have used them.

I tend to disagree: The &quot;bloat&quot; is rather small but the benefits are great, 5 years into development it makes development much faster and productive and less error prone.</description>
		<content:encoded><![CDATA[<p>@Buddy: Yes could be. I thought named parameters are nice in any language where I have used them.</p>
<p>I tend to disagree: The &#8220;bloat&#8221; is rather small but the benefits are great, 5 years into development it makes development much faster and productive and less error prone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Buddy Casino</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-185121</link>
		<dc:creator>Buddy Casino</dc:creator>
		<pubDate>Wed, 22 Oct 2008 09:19:51 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-185121</guid>
		<description>I&#039;m not sure it is really worth the effort in Java. Maybe the following language constructs would help:

- Named method arguments, so you could write:
new Customer(firstName=&quot;Stephan&quot;, name=&quot;Schmidt&quot;); 
This would be great for DI, also.

- Having special constructs for such value objects, like Scala case classes.
Note that getters, setters, equals &amp; hashCode are constructed automatically by the compiler:
case class Name(name: String)

What you propose adds way to much bloat, and Java already has enough of that. Oh, and btw.: you can actually perform validation in setters, you don&#039;t need a separate class for that...</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure it is really worth the effort in Java. Maybe the following language constructs would help:</p>
<p>- Named method arguments, so you could write:<br />
new Customer(firstName=&#8221;Stephan&#8221;, name=&#8221;Schmidt&#8221;);<br />
This would be great for DI, also.</p>
<p>- Having special constructs for such value objects, like Scala case classes.<br />
Note that getters, setters, equals &amp; hashCode are constructed automatically by the compiler:<br />
case class Name(name: String)</p>
<p>What you propose adds way to much bloat, and Java already has enough of that. Oh, and btw.: you can actually perform validation in setters, you don&#8217;t need a separate class for that&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-91479</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Mon, 19 May 2008 04:50:08 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-91479</guid>
		<description>I&#039;ll do</description>
		<content:encoded><![CDATA[<p>I&#8217;ll do</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mert Nuhoglu</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-91119</link>
		<dc:creator>Mert Nuhoglu</dc:creator>
		<pubDate>Sun, 18 May 2008 20:11:10 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-91119</guid>
		<description>Very instructive article and discussion.

Stephan, could you blog at some suitable time your ideas on rule 8 in Object Calisthenics: &quot;Use First Class Collections&quot;.

I wonder whether it is really worth the extra effort or what are concrete benefits in that.</description>
		<content:encoded><![CDATA[<p>Very instructive article and discussion.</p>
<p>Stephan, could you blog at some suitable time your ideas on rule 8 in Object Calisthenics: &#8220;Use First Class Collections&#8221;.</p>
<p>I wonder whether it is really worth the extra effort or what are concrete benefits in that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-89424</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 15 May 2008 11:11:55 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-89424</guid>
		<description>@Niclas: Thanks for the clarification and the teaser. I&#039;ve mentioned Qi4J before, commented on Rickards blog and had some email exchanges with Rickard. So the &quot;in the passing&quot; is purely random.

I&#039;ve mentioned Qi4J in other posts like

http://stephan.reposita.org/archives/2008/01/09/qi4j-the-next-java-forget-scala/</description>
		<content:encoded><![CDATA[<p>@Niclas: Thanks for the clarification and the teaser. I&#8217;ve mentioned Qi4J before, commented on Rickards blog and had some email exchanges with Rickard. So the &#8220;in the passing&#8221; is purely random.</p>
<p>I&#8217;ve mentioned Qi4J in other posts like</p>
<p><a href="http://stephan.reposita.org/archives/2008/01/09/qi4j-the-next-java-forget-scala/" rel="nofollow">http://stephan.reposita.org/archives/2008/01/09/qi4j-the-next-java-forget-scala/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niclas Hedhman</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-89421</link>
		<dc:creator>Niclas Hedhman</dc:creator>
		<pubDate>Thu, 15 May 2008 11:03:17 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-89421</guid>
		<description>You mention Qi4j in the passing, without much context. And Qi4j is not OOP, but what we call Composite Oriented Programming and this kind of discussion is mostly meaningless and at the wrong level of focus.

Classes are Dead, Long live Interfaces.

To give this audience a teaser;

public interface Person extends HasName, HasAddress, HasSpouse
{}

and no more coding is required. No magic, pure Java, clever runtime....</description>
		<content:encoded><![CDATA[<p>You mention Qi4j in the passing, without much context. And Qi4j is not OOP, but what we call Composite Oriented Programming and this kind of discussion is mostly meaningless and at the wrong level of focus.</p>
<p>Classes are Dead, Long live Interfaces.</p>
<p>To give this audience a teaser;</p>
<p>public interface Person extends HasName, HasAddress, HasSpouse<br />
{}</p>
<p>and no more coding is required. No magic, pure Java, clever runtime&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-87307</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Sat, 10 May 2008 08:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-87307</guid>
		<description>@Oliver: Don&#039;t be personal, making incorrect assumptions about my field of work. FYI, I&#039;m working on nationwide EA systems.

@Stephan: Yes, your primary message was to make type check stronger. My primary objection to this is, that you say &quot;never, never, never&quot;. When a system gets over a certain size, you need to create tools that handle various kinds of information the same way - so that the code really doesn&#039;t know if the string is a name, a zip code or a product ID.</description>
		<content:encoded><![CDATA[<p>@Oliver: Don&#8217;t be personal, making incorrect assumptions about my field of work. FYI, I&#8217;m working on nationwide EA systems.</p>
<p>@Stephan: Yes, your primary message was to make type check stronger. My primary objection to this is, that you say &#8220;never, never, never&#8221;. When a system gets over a certain size, you need to create tools that handle various kinds of information the same way &#8211; so that the code really doesn&#8217;t know if the string is a name, a zip code or a product ID.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-87266</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 10 May 2008 02:12:12 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-87266</guid>
		<description>&quot;However, what Stephan is advocating, is not to reduce the number of places in your source code, where you write validation code, [...]&quot;

Interesting what you think that I&#039;m saying.

I do think it&#039;s good to have validation on object creation, though this topic is miles away from the post which was not to use Strings instead of classes.

If performance is an issue because of validation, have a &lt;code&gt;Valid&lt;/code&gt; interface with an &lt;code&gt;isValid()&lt;/code&gt; method. If you have different contexts of validation, change the validation code. If that&#039;s not possible, habe a &lt;code&gt;ValidatorService&lt;/code&gt;. As the title of the post - which noone seems to read - suggests, do the right thing don&#039;t follow a dogma.</description>
		<content:encoded><![CDATA[<p>&#8220;However, what Stephan is advocating, is not to reduce the number of places in your source code, where you write validation code, [...]&#8221;</p>
<p>Interesting what you think that I&#8217;m saying.</p>
<p>I do think it&#8217;s good to have validation on object creation, though this topic is miles away from the post which was not to use Strings instead of classes.</p>
<p>If performance is an issue because of validation, have a <code>Valid</code> interface with an <code>isValid()</code> method. If you have different contexts of validation, change the validation code. If that&#8217;s not possible, habe a <code>ValidatorService</code>. As the title of the post &#8211; which noone seems to read &#8211; suggests, do the right thing don&#8217;t follow a dogma.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sean</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-87260</link>
		<dc:creator>sean</dc:creator>
		<pubDate>Sat, 10 May 2008 00:31:13 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-87260</guid>
		<description>Oliver, great points.

People just don&#039;t seem to get that if their objects need logic, it should be encapsulated in that class.

E.g. instead of:

Collections.sort(users, new Comparator(){ etc etc}

it should be:

Collections.sort(users, User.COMPARE_FULL_NAMES);

There are many, many reasons for this, but the primary is that all logic for the object should be as close to the object as possible, at worst in another class in the same package.

I have been stuck with codebases of my own design that used the former. What happens when the customer wants to change the sorting method? Code search. We may as well use ruby in that case.</description>
		<content:encoded><![CDATA[<p>Oliver, great points.</p>
<p>People just don&#8217;t seem to get that if their objects need logic, it should be encapsulated in that class.</p>
<p>E.g. instead of:</p>
<p>Collections.sort(users, new Comparator(){ etc etc}</p>
<p>it should be:</p>
<p>Collections.sort(users, User.COMPARE_FULL_NAMES);</p>
<p>There are many, many reasons for this, but the primary is that all logic for the object should be as close to the object as possible, at worst in another class in the same package.</p>
<p>I have been stuck with codebases of my own design that used the former. What happens when the customer wants to change the sorting method? Code search. We may as well use ruby in that case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-87253</link>
		<dc:creator>Oliver</dc:creator>
		<pubDate>Fri, 09 May 2008 23:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-87253</guid>
		<description>@Lars D:

I welcome you to an average enterprise project, where code is not being written as the books and best practices would have it. 8-)

Jokes aside, I think too much emphasis on this thread has been placed on validation (but it is a large part of business applications), and the original blog post tries to make a point on domain modeling.

The original blog post argued that domain modeling needs to occur at the lowest possible level. At some point, every project, starts introducing domain model. 

That concept, &#039;shields&#039; (in a way) developers from thinking about low level implementation, and let&#039;s them focus on higher level constructs and interactions within the system. 

For illustration purposes, somewhere in the code, one WILL eventually have classes named Order, Person, Customer, Report (depending on what the application does, of course).

When does one start introducing the domain objects? At what level?

Stephan&#039;s post argues that domain starts at the very bottom, at the lowest possible level. The rest should then build on top of it.

He chose to illustrate his point with the simpler examples of Names, and some comments jumped on that. My comment was that I agree with him, even for those simpler examples, and wanted to support his view with a real life example.

I would say, if there are business rules around the thing you are modeling, it becomes a domain class.

- Date of birth for a person in your application needs to be within certain date range? You just got yourself a DateOfBirth class.

- Password is between 6 and 8 characters, and has to have 2 digits and a special character? Guess what, the model just got a Password class.


Domain classes allow for better immutability, reuse, and yes, they should encapsulate their values, as well as their behaviour. Validation? In most cases, it should probably be a part of the domain class, as it is the place that has the most knowledge on what is being validated.

Is it an overkill to model even the Names in such a way? Maybe in simpler cases. However on larger projects, where the data may come from several databases, mainframes, web services, you as a developer, really need to rely on something telling you what that String/int/long really IS. Domain model lets you do that.

Now, the biggest problem actually is not writing this code properly, but to get the business stakeholders actually agree on the business domain. Is contact address the same as principal residence address? Does it have the same fields and which values should be in those fields? What is a &#039;valid&#039; mailing address? What &#039;is&#039; a Person?

I&#039;ve never worked on such a project that had domain constructs at such low level, but after seeing the issues we are encountering, and having recently read Domain Driven Design and blog entries like this, I really want to try use such concepts on the next projects.

There is a push back from nearly all developers I&#039;ve worked with, and that&#039;s why I welcomed reading this blog entry. Most developers are arguing against such modeling, but they will happily use java.util.Date (for now, let&#039;s put aside the suckage of that class), instead of a String, or long, or three Strings/ints (day, month, year), or 6 Strings/ints (day, month, year, hour, minute, second). 

When you look at it, Date IS a domain model, raising above the primitives to model a real world concept (with some internal validation and &#039;business&#039; rules).


Finally, to comment on your points:
1) [increasing the number of places that the validation code is executed, impacting application performance]

I am not sure if the domain modeling increases the number of places validation code is executed. As you are accepting the data in your application, you have to validate the data anyway. On some projects, just because you are reading data from the database, does not mean it&#039;s good (valid). Some other application sharing the database might have put the wrong data in.

As for the performance impact, who knows. Profile the code and see where the problem lies. Then fix it. Anything else is just an assumption.


2) [co-locating the validation code with a class that is used to contain the data, adding dependencies that may be unwanted]

I don&#039;t know what dependencies are you having in mind, but you will have them in your code anyway. Just because you use a String for a password on your Account class, and have a separate class named PasswordValidator in a separate package, does not mean they don&#039;t depend on one another.

Actually, I am arguing that having such code close to one another actually makes the dependency visible, tangible, easily understandable, exposing business rules and making developers aware of it, stopping them from writing yet another password validation somewhere else.

Huh. Time to go home.</description>
		<content:encoded><![CDATA[<p>@Lars D:</p>
<p>I welcome you to an average enterprise project, where code is not being written as the books and best practices would have it. 8-)</p>
<p>Jokes aside, I think too much emphasis on this thread has been placed on validation (but it is a large part of business applications), and the original blog post tries to make a point on domain modeling.</p>
<p>The original blog post argued that domain modeling needs to occur at the lowest possible level. At some point, every project, starts introducing domain model. </p>
<p>That concept, &#8216;shields&#8217; (in a way) developers from thinking about low level implementation, and let&#8217;s them focus on higher level constructs and interactions within the system. </p>
<p>For illustration purposes, somewhere in the code, one WILL eventually have classes named Order, Person, Customer, Report (depending on what the application does, of course).</p>
<p>When does one start introducing the domain objects? At what level?</p>
<p>Stephan&#8217;s post argues that domain starts at the very bottom, at the lowest possible level. The rest should then build on top of it.</p>
<p>He chose to illustrate his point with the simpler examples of Names, and some comments jumped on that. My comment was that I agree with him, even for those simpler examples, and wanted to support his view with a real life example.</p>
<p>I would say, if there are business rules around the thing you are modeling, it becomes a domain class.</p>
<p>- Date of birth for a person in your application needs to be within certain date range? You just got yourself a DateOfBirth class.</p>
<p>- Password is between 6 and 8 characters, and has to have 2 digits and a special character? Guess what, the model just got a Password class.</p>
<p>Domain classes allow for better immutability, reuse, and yes, they should encapsulate their values, as well as their behaviour. Validation? In most cases, it should probably be a part of the domain class, as it is the place that has the most knowledge on what is being validated.</p>
<p>Is it an overkill to model even the Names in such a way? Maybe in simpler cases. However on larger projects, where the data may come from several databases, mainframes, web services, you as a developer, really need to rely on something telling you what that String/int/long really IS. Domain model lets you do that.</p>
<p>Now, the biggest problem actually is not writing this code properly, but to get the business stakeholders actually agree on the business domain. Is contact address the same as principal residence address? Does it have the same fields and which values should be in those fields? What is a &#8216;valid&#8217; mailing address? What &#8216;is&#8217; a Person?</p>
<p>I&#8217;ve never worked on such a project that had domain constructs at such low level, but after seeing the issues we are encountering, and having recently read Domain Driven Design and blog entries like this, I really want to try use such concepts on the next projects.</p>
<p>There is a push back from nearly all developers I&#8217;ve worked with, and that&#8217;s why I welcomed reading this blog entry. Most developers are arguing against such modeling, but they will happily use java.util.Date (for now, let&#8217;s put aside the suckage of that class), instead of a String, or long, or three Strings/ints (day, month, year), or 6 Strings/ints (day, month, year, hour, minute, second). </p>
<p>When you look at it, Date IS a domain model, raising above the primitives to model a real world concept (with some internal validation and &#8216;business&#8217; rules).</p>
<p>Finally, to comment on your points:<br />
1) [increasing the number of places that the validation code is executed, impacting application performance]</p>
<p>I am not sure if the domain modeling increases the number of places validation code is executed. As you are accepting the data in your application, you have to validate the data anyway. On some projects, just because you are reading data from the database, does not mean it&#8217;s good (valid). Some other application sharing the database might have put the wrong data in.</p>
<p>As for the performance impact, who knows. Profile the code and see where the problem lies. Then fix it. Anything else is just an assumption.</p>
<p>2) [co-locating the validation code with a class that is used to contain the data, adding dependencies that may be unwanted]</p>
<p>I don&#8217;t know what dependencies are you having in mind, but you will have them in your code anyway. Just because you use a String for a password on your Account class, and have a separate class named PasswordValidator in a separate package, does not mean they don&#8217;t depend on one another.</p>
<p>Actually, I am arguing that having such code close to one another actually makes the dependency visible, tangible, easily understandable, exposing business rules and making developers aware of it, stopping them from writing yet another password validation somewhere else.</p>
<p>Huh. Time to go home.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-87245</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Fri, 09 May 2008 21:33:38 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-87245</guid>
		<description>@Oliver: If you have the same validation code in many places, something is definitely wrong... and I&#039;m shocked to hear about a solution where you would check for the minimum length of a name in multiple places.

However, what Stephan is advocating, is not to reduce the number of places in your source code, where you write validation code, but to:

1) Increase the number of places that the validation code is executed, even to places where the check would reduce the app performance maybe 100 times or more.

2) Co-locate the validation code with a class that is used to contain the data, adding dependencies that may be unwanted

You can achieve much better validation with better performance and better maintainability in other ways.</description>
		<content:encoded><![CDATA[<p>@Oliver: If you have the same validation code in many places, something is definitely wrong&#8230; and I&#8217;m shocked to hear about a solution where you would check for the minimum length of a name in multiple places.</p>
<p>However, what Stephan is advocating, is not to reduce the number of places in your source code, where you write validation code, but to:</p>
<p>1) Increase the number of places that the validation code is executed, even to places where the check would reduce the app performance maybe 100 times or more.</p>
<p>2) Co-locate the validation code with a class that is used to contain the data, adding dependencies that may be unwanted</p>
<p>You can achieve much better validation with better performance and better maintainability in other ways.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-87175</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Fri, 09 May 2008 16:15:13 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-87175</guid>
		<description>@Oliver: A heartfully thanks :-)</description>
		<content:encoded><![CDATA[<p>@Oliver: A heartfully thanks :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-87153</link>
		<dc:creator>Oliver</dc:creator>
		<pubDate>Fri, 09 May 2008 14:38:24 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-87153</guid>
		<description>Hi Stephan,

I am so happy to know that I am not alone in this &#039;fully domain development&#039; way of thinking you are describing in your blog entry.

Maybe the people got hung up on the FirstName and Name examples, which, at first, do not sound like good candidates for wrapping Strings into Domain objects.

But we actually had a problem with the last names on the project I am currently on. The business wanted to limit the last name length to minimum 2 characters, and of course, the code was littered with length checking, from the ui level to the database.

A couple of months later, they dropped that requirement, and it took us ages to find all the checking throughout the code and remove it.

Yes, you can argue that we could have created a LastNameValidator, but the situation was not that simple, because of the way presentation, business and integration tier handled last name for their purposes.

Also, if you are creating LastNameValidator, what better place to put it then the LastName domain object, since that&#039;s the place that should know how last name &#039;looks&#039; like. And once you need to soundex/reverse soundex the names, where does that go?

It&#039;s also no fun to deal with international phone numbers as strings formatted in who knows what way (with/without dashes, braces...). Validation and formatting code all over the place.


Then again, project after project, I&#039;ve seen this emphasis on using Strings everywhere, even in the places where Java already has nice domain representations.

Those developers have no objection on using Strings for email addresses and urls, and then fix endless stream of defects logged against their validation and parsing, even though one line use of java.net.URL and javax.mail.internet.InternetAddress would eliminate the problems before they even happened.</description>
		<content:encoded><![CDATA[<p>Hi Stephan,</p>
<p>I am so happy to know that I am not alone in this &#8216;fully domain development&#8217; way of thinking you are describing in your blog entry.</p>
<p>Maybe the people got hung up on the FirstName and Name examples, which, at first, do not sound like good candidates for wrapping Strings into Domain objects.</p>
<p>But we actually had a problem with the last names on the project I am currently on. The business wanted to limit the last name length to minimum 2 characters, and of course, the code was littered with length checking, from the ui level to the database.</p>
<p>A couple of months later, they dropped that requirement, and it took us ages to find all the checking throughout the code and remove it.</p>
<p>Yes, you can argue that we could have created a LastNameValidator, but the situation was not that simple, because of the way presentation, business and integration tier handled last name for their purposes.</p>
<p>Also, if you are creating LastNameValidator, what better place to put it then the LastName domain object, since that&#8217;s the place that should know how last name &#8216;looks&#8217; like. And once you need to soundex/reverse soundex the names, where does that go?</p>
<p>It&#8217;s also no fun to deal with international phone numbers as strings formatted in who knows what way (with/without dashes, braces&#8230;). Validation and formatting code all over the place.</p>
<p>Then again, project after project, I&#8217;ve seen this emphasis on using Strings everywhere, even in the places where Java already has nice domain representations.</p>
<p>Those developers have no objection on using Strings for email addresses and urls, and then fix endless stream of defects logged against their validation and parsing, even though one line use of java.net.URL and javax.mail.internet.InternetAddress would eliminate the problems before they even happened.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-86520</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Thu, 08 May 2008 05:40:56 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-86520</guid>
		<description>This is how we validate zip codes:

When entering data: Depending on the country chosen for the person, and depending on the system policies for the database, we look up the zip code in a table. For some countries, the zip code must be present in the table, and for countries that we don&#039;t know details about, we accept anything that complies with the max length of the database field.

When importing data about a person from other places, we cannot reject zip codes that we consider wrong, so we only check that their length is ok.

In other words, our standard validator for zip codes could be described as:

bool ValidateZipCode (zipcode, country, systempolicy, nationalzipcodelists, maxfieldlength);

I wouldn&#039;t have a clue how to call this validator from the constructor of a zipcode object. I&#039;m also not sure if this actually belongs with a zip code object, because that would introduce dependencies from the zip code class to the country class, which might be an unwanted dependency.</description>
		<content:encoded><![CDATA[<p>This is how we validate zip codes:</p>
<p>When entering data: Depending on the country chosen for the person, and depending on the system policies for the database, we look up the zip code in a table. For some countries, the zip code must be present in the table, and for countries that we don&#8217;t know details about, we accept anything that complies with the max length of the database field.</p>
<p>When importing data about a person from other places, we cannot reject zip codes that we consider wrong, so we only check that their length is ok.</p>
<p>In other words, our standard validator for zip codes could be described as:</p>
<p>bool ValidateZipCode (zipcode, country, systempolicy, nationalzipcodelists, maxfieldlength);</p>
<p>I wouldn&#8217;t have a clue how to call this validator from the constructor of a zipcode object. I&#8217;m also not sure if this actually belongs with a zip code object, because that would introduce dependencies from the zip code class to the country class, which might be an unwanted dependency.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lumpynose</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-86513</link>
		<dc:creator>lumpynose</dc:creator>
		<pubDate>Thu, 08 May 2008 05:08:11 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-86513</guid>
		<description>Regarding validation with Stephan&#039;s method, instead of putting validation in the constructor could you have a separate method that you call when necessary to do the validation; e.g.

public class Zipcode {
    ...
    public boolean validate() { ... }
}

And could you have different constructors, one that does validation and one that doesn&#039;t?

And different validators; for example, validateOldStyle() and validateNewStyle().

Stephan, how do you do the getters when you need to use the primitives?  I&#039;m thinking that you&#039;d use the &#039;as&#039; style, for example, firstName.asString().

I would also like to see a more fleshed out example.  I&#039;m also curious to see how it would work with Hibernate, and Spring&#039;s MVC with its forms.</description>
		<content:encoded><![CDATA[<p>Regarding validation with Stephan&#8217;s method, instead of putting validation in the constructor could you have a separate method that you call when necessary to do the validation; e.g.</p>
<p>public class Zipcode {<br />
    &#8230;<br />
    public boolean validate() { &#8230; }<br />
}</p>
<p>And could you have different constructors, one that does validation and one that doesn&#8217;t?</p>
<p>And different validators; for example, validateOldStyle() and validateNewStyle().</p>
<p>Stephan, how do you do the getters when you need to use the primitives?  I&#8217;m thinking that you&#8217;d use the &#8216;as&#8217; style, for example, firstName.asString().</p>
<p>I would also like to see a more fleshed out example.  I&#8217;m also curious to see how it would work with Hibernate, and Spring&#8217;s MVC with its forms.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-86052</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Wed, 07 May 2008 10:47:06 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-86052</guid>
		<description>Rereading this discussion, I&#039;d say there are several subissues:

1) Type check. It&#039;s good to be sure that the order ID values are always order ID values, and stored the same way. I can agree on that one.

2) Debugging. By using a class for order IDs everywhere, you can build debug code into the class generation, which catches specific bugs.

3) Simple validation: Checking the value&#039;s correctness, only by looking at the value itself. For instance, age should be between 0 and 200. If outside, it&#039;s a bug. Doing this check everywhere will definitely harm performance, possibly in ways that makes the app not comply with user expectations.

4) Full validation: Checking that the value is a real value. We usually do full validation, checking that the value is actually in the database etc. A full validation can take 0.1 seconds. Validating 1000 values can take 100 seconds. It does not make sense to build a validation like that into the constructor of a class that handles a simple string value.

The way that Stephan chooses to write his comments, it seems that Stephan is actually recommending a full validation with database lookups, national name service lookups etc., every time you create a new piece of data in your application. Since this is totally unrealistic, I guess that this is either philosophy, not well thought through, or misunderstood by me.

Even simple validation is something we can definitely disagree on, simply because I don&#039;t see the point of introducing new loops inside other loops that are already slow and consume 100% CPU time.</description>
		<content:encoded><![CDATA[<p>Rereading this discussion, I&#8217;d say there are several subissues:</p>
<p>1) Type check. It&#8217;s good to be sure that the order ID values are always order ID values, and stored the same way. I can agree on that one.</p>
<p>2) Debugging. By using a class for order IDs everywhere, you can build debug code into the class generation, which catches specific bugs.</p>
<p>3) Simple validation: Checking the value&#8217;s correctness, only by looking at the value itself. For instance, age should be between 0 and 200. If outside, it&#8217;s a bug. Doing this check everywhere will definitely harm performance, possibly in ways that makes the app not comply with user expectations.</p>
<p>4) Full validation: Checking that the value is a real value. We usually do full validation, checking that the value is actually in the database etc. A full validation can take 0.1 seconds. Validating 1000 values can take 100 seconds. It does not make sense to build a validation like that into the constructor of a class that handles a simple string value.</p>
<p>The way that Stephan chooses to write his comments, it seems that Stephan is actually recommending a full validation with database lookups, national name service lookups etc., every time you create a new piece of data in your application. Since this is totally unrealistic, I guess that this is either philosophy, not well thought through, or misunderstood by me.</p>
<p>Even simple validation is something we can definitely disagree on, simply because I don&#8217;t see the point of introducing new loops inside other loops that are already slow and consume 100% CPU time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-85971</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Wed, 07 May 2008 07:18:03 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-85971</guid>
		<description>Validation is definitely necessary, and any failed validation must be correctly reported to the user at the time of data entry or import, or to the external application in case of integration data transfer.

However, it doesn&#039;t make sense to validate simple values at the time of assignment to a variable - that&#039;s waste of CPU power. Try to imagine that you want to import a million order IDs into an array, sort them and output them again. That&#039;s simple: find some code that can read strings, sort them and output them again.

What Stephan basically says, is that this method is not so good, because it doesn&#039;t validate the orderIDs. Ok - let&#039;s say that we have 3 different order ID systems, and we want really good validation. In order to solve the &quot;sort the file of order IDs&quot;, Stephan&#039;s approach would then need:

- Find a way to get additional data about what kind of order IDs these are, so that we know how to validate them
- Implement a class for each kind of order ID validation
- Create one object for each object ID
etc.

It&#039;s totally overkill. You may regard this as a special case, because your projects don&#039;t do much of these things, but there are huge amounts of applications out there, that does these kinds of things very often. Therefore, Stephan&#039;s recommendation may apply to his project, but it surely doesn&#039;t apply to many huge applications deployed in public administration and big corporations.</description>
		<content:encoded><![CDATA[<p>Validation is definitely necessary, and any failed validation must be correctly reported to the user at the time of data entry or import, or to the external application in case of integration data transfer.</p>
<p>However, it doesn&#8217;t make sense to validate simple values at the time of assignment to a variable &#8211; that&#8217;s waste of CPU power. Try to imagine that you want to import a million order IDs into an array, sort them and output them again. That&#8217;s simple: find some code that can read strings, sort them and output them again.</p>
<p>What Stephan basically says, is that this method is not so good, because it doesn&#8217;t validate the orderIDs. Ok &#8211; let&#8217;s say that we have 3 different order ID systems, and we want really good validation. In order to solve the &#8220;sort the file of order IDs&#8221;, Stephan&#8217;s approach would then need:</p>
<p>- Find a way to get additional data about what kind of order IDs these are, so that we know how to validate them<br />
- Implement a class for each kind of order ID validation<br />
- Create one object for each object ID<br />
etc.</p>
<p>It&#8217;s totally overkill. You may regard this as a special case, because your projects don&#8217;t do much of these things, but there are huge amounts of applications out there, that does these kinds of things very often. Therefore, Stephan&#8217;s recommendation may apply to his project, but it surely doesn&#8217;t apply to many huge applications deployed in public administration and big corporations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sean</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-85573</link>
		<dc:creator>sean</dc:creator>
		<pubDate>Tue, 06 May 2008 16:26:15 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-85573</guid>
		<description>Lars,

I don&#039;t think you get it. Validation is necessary, but implemented correctly. 

Here is my thought process in code:

try{
zipCode = new ZipCode(&quot;90210&quot;);
insertIntoDb(zipCode); // stupid example
}catch(ValidationExceptione ){
     showToUser(e); // etc
}

Compared to what I think you are proposing:

Either you are proposing no validation:

String zipCode = &quot;badmonster&quot;;
insertIntoDb(zipCode);

Or some, but externalised:

String zipCode = &quot;badmonster&quot;;

if( ! validate(zipCode) ){
    showToUser(zipCode, &quot;Error message&quot;);
}
// somewhere else in the code:
String zipCode = &quot;90450&quot;;
if( doesntValidate(zipCode) ){
     showToUserInDialog(zipCode, &quot;Enter zipCode&quot;);
}

------------------------------------

If either of the two is what you are proposing (which I think is B) then my point is proven. By making the zipcode understand what is good data, you never have the risk of reimplementation of code. The object knows whether it&#039;s valid or not.

All your arguments against this are meaningless. I could easily have a ZipCode that determines the type of zipcode validation (for legacy integration) or use the correct one. One object responsibility in no way guarantees failure, far from it.</description>
		<content:encoded><![CDATA[<p>Lars,</p>
<p>I don&#8217;t think you get it. Validation is necessary, but implemented correctly. </p>
<p>Here is my thought process in code:</p>
<p>try{<br />
zipCode = new ZipCode(&#8220;90210&#8243;);<br />
insertIntoDb(zipCode); // stupid example<br />
}catch(ValidationExceptione ){<br />
     showToUser(e); // etc<br />
}</p>
<p>Compared to what I think you are proposing:</p>
<p>Either you are proposing no validation:</p>
<p>String zipCode = &#8220;badmonster&#8221;;<br />
insertIntoDb(zipCode);</p>
<p>Or some, but externalised:</p>
<p>String zipCode = &#8220;badmonster&#8221;;</p>
<p>if( ! validate(zipCode) ){<br />
    showToUser(zipCode, &#8220;Error message&#8221;);<br />
}<br />
// somewhere else in the code:<br />
String zipCode = &#8220;90450&#8243;;<br />
if( doesntValidate(zipCode) ){<br />
     showToUserInDialog(zipCode, &#8220;Enter zipCode&#8221;);<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>If either of the two is what you are proposing (which I think is B) then my point is proven. By making the zipcode understand what is good data, you never have the risk of reimplementation of code. The object knows whether it&#8217;s valid or not.</p>
<p>All your arguments against this are meaningless. I could easily have a ZipCode that determines the type of zipcode validation (for legacy integration) or use the correct one. One object responsibility in no way guarantees failure, far from it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84897</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Mon, 05 May 2008 05:15:18 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84897</guid>
		<description>Sadly you didn&#039;t go into my reporting argument, so I only can repeat it. Your requirements look a lot like a reporting problem.

I agree with your other argument though

&quot;If you do something 0%, you probably do something wrong.
If you do something 100%, you probably do something wrong, too.&quot;

Because of this the title of the post included 

&quot;(or at least less often :-)&quot;

:-)

Peace
-stephan</description>
		<content:encoded><![CDATA[<p>Sadly you didn&#8217;t go into my reporting argument, so I only can repeat it. Your requirements look a lot like a reporting problem.</p>
<p>I agree with your other argument though</p>
<p>&#8220;If you do something 0%, you probably do something wrong.<br />
If you do something 100%, you probably do something wrong, too.&#8221;</p>
<p>Because of this the title of the post included </p>
<p>&#8220;(or at least less often :-)&#8221;</p>
<p>:-)</p>
<p>Peace<br />
-stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84613</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Sun, 04 May 2008 20:39:52 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84613</guid>
		<description>@stephan:

To your question about validation: We validate a lot, and normally always in the interface where data comes in (GUI or API to external systems).

In the example I gave you, the order ID is validated because if it cannot find an order with the specified order ID, an exception is raised, telling very clearly what the problem is. Checking against a list of existing orders is probably the best validation you can get.

In a database, the same field may require different validation depending on the app that stores it and the current configuration at the time of creating a record. We usually assume that historic data is correct, even if it is created and validated under a data policy that stopped 5 minutes ago. It doesn&#039;t make sense to apply a validation rule that only exists for 1-2 years, if you want to create a system that is in production for 10-20 years.

With regard to principles, the only thing I will dare to really generalize is this:

If you do something 0%, you probably do something wrong.
If you do something 100%, you probably do something wrong, too.

This applies to OOP, UML, unit testing and a lot of other buzzwords/religions.</description>
		<content:encoded><![CDATA[<p>@stephan:</p>
<p>To your question about validation: We validate a lot, and normally always in the interface where data comes in (GUI or API to external systems).</p>
<p>In the example I gave you, the order ID is validated because if it cannot find an order with the specified order ID, an exception is raised, telling very clearly what the problem is. Checking against a list of existing orders is probably the best validation you can get.</p>
<p>In a database, the same field may require different validation depending on the app that stores it and the current configuration at the time of creating a record. We usually assume that historic data is correct, even if it is created and validated under a data policy that stopped 5 minutes ago. It doesn&#8217;t make sense to apply a validation rule that only exists for 1-2 years, if you want to create a system that is in production for 10-20 years.</p>
<p>With regard to principles, the only thing I will dare to really generalize is this:</p>
<p>If you do something 0%, you probably do something wrong.<br />
If you do something 100%, you probably do something wrong, too.</p>
<p>This applies to OOP, UML, unit testing and a lot of other buzzwords/religions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84592</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sun, 04 May 2008 19:58:17 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84592</guid>
		<description>@Lars: Or do you want to write a Customer/Order reporting tool and not store data? 

Then I would use something like Crystal Reports or any other tool and not write my own code.

And validation is not needed for reporting. As isn&#039;t a domain model.</description>
		<content:encoded><![CDATA[<p>@Lars: Or do you want to write a Customer/Order reporting tool and not store data? </p>
<p>Then I would use something like Crystal Reports or any other tool and not write my own code.</p>
<p>And validation is not needed for reporting. As isn&#8217;t a domain model.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84590</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sun, 04 May 2008 19:55:21 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84590</guid>
		<description>@Nick: 

&quot;new Name(&quot;John&quot;,&quot;Doe&quot;); // can still handle all the validations&quot;

So you do support a class for a name or not? I&#039;m not sure.

&quot;In fact to support Lars’ argument.&quot;

So you would use String firstName = &quot;John&quot;; String lastName = &quot;Doe&quot;?

And not &quot;new Name(...)&quot; ?

I&#039;m not clever enough to follow that logic.</description>
		<content:encoded><![CDATA[<p>@Nick: </p>
<p>&#8220;new Name(&#8220;John&#8221;,&#8221;Doe&#8221;); // can still handle all the validations&#8221;</p>
<p>So you do support a class for a name or not? I&#8217;m not sure.</p>
<p>&#8220;In fact to support Lars’ argument.&#8221;</p>
<p>So you would use String firstName = &#8220;John&#8221;; String lastName = &#8220;Doe&#8221;?</p>
<p>And not &#8220;new Name(&#8230;)&#8221; ?</p>
<p>I&#8217;m not clever enough to follow that logic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84588</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sun, 04 May 2008 19:50:30 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84588</guid>
		<description>@Lars: I&#039;ve lost you, you propose to have no validation at all?

&lt;i&gt;&quot;As you can see, it’s quite simple: You call a FetchCustomerIdForOrder (OrderId Id), and then you have the customer ID and can print everything.&quot;&lt;/i&gt;

So you do not have input validation on the file? And put your orders directly into your database without validation?

Then perhaps we have two very different styles of development and discussion on validation is futile.</description>
		<content:encoded><![CDATA[<p>@Lars: I&#8217;ve lost you, you propose to have no validation at all?</p>
<p><i>&#8220;As you can see, it’s quite simple: You call a FetchCustomerIdForOrder (OrderId Id), and then you have the customer ID and can print everything.&#8221;</i></p>
<p>So you do not have input validation on the file? And put your orders directly into your database without validation?</p>
<p>Then perhaps we have two very different styles of development and discussion on validation is futile.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick V</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84462</link>
		<dc:creator>Nick V</dc:creator>
		<pubDate>Sun, 04 May 2008 11:42:58 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84462</guid>
		<description>speaking of hibernate mappings.

With all the fragmentation of classes into smaller and smaller units of coherence, as you suggest. Mapping would become counterintuitive, filled with @embedded and @oneToOne relationships.

The idea you propose is good in certain scenarios, no doubt. But the imperative tone of the article, with the strong disclaimer as the title, is a little bold ;)

 -- FirstName firstName --

From a pragmatic viewpoint this is just painful. There is no good argument in design to break up entities to this level. In fact to support Lars&#039; argument. All this would do is promote unnecessary validation, creating a restrictive, impractical system.

new Name(&quot;John&quot;,&quot;Doe&quot;); // can still handle all the validations

new Name(firstName(&quot;John&quot;),lastName(&quot;Doe&quot;)) // Is over the top.

In fact it reminds me somewhat of Scala. A very academically though out language. But far too ugly for the real world.</description>
		<content:encoded><![CDATA[<p>speaking of hibernate mappings.</p>
<p>With all the fragmentation of classes into smaller and smaller units of coherence, as you suggest. Mapping would become counterintuitive, filled with @embedded and @oneToOne relationships.</p>
<p>The idea you propose is good in certain scenarios, no doubt. But the imperative tone of the article, with the strong disclaimer as the title, is a little bold ;)</p>
<p> &#8212; FirstName firstName &#8211;</p>
<p>From a pragmatic viewpoint this is just painful. There is no good argument in design to break up entities to this level. In fact to support Lars&#8217; argument. All this would do is promote unnecessary validation, creating a restrictive, impractical system.</p>
<p>new Name(&#8220;John&#8221;,&#8221;Doe&#8221;); // can still handle all the validations</p>
<p>new Name(firstName(&#8220;John&#8221;),lastName(&#8220;Doe&#8221;)) // Is over the top.</p>
<p>In fact it reminds me somewhat of Scala. A very academically though out language. But far too ugly for the real world.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84461</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Sun, 04 May 2008 11:35:32 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84461</guid>
		<description>&quot;No problem with an OrderId interface and different class implementations, depending on the date it was created. A no brainer.&quot;

Ok. Please show me the code that solves this task:

You receive a tab-separated file like this:

123-456 45
2345-22 78

Now, your code has to import this file. The first column contains order IDs, the second contains some value for this order ID. That could be statistical information or something completely different.

Your code must:
- Read this file
- Write a list of customer ID, order ID and this value

As you can see, it&#039;s quite simple: You call a FetchCustomerIdForOrder (OrderId Id), and then you have the customer ID and can print everything. According to your &quot;no brainer&quot; explanation, that doesn&#039;t work, because you don&#039;t have the date of order creation, so you cannot create an OrderId object.

In other words, your explanation is wrong, and &quot;no brainer&quot; is probably not the best way to describe an faulty method. You can then say that &quot;we create a non-checked orderid class&quot; (which would be, like, a string?!?) or &quot;we just retrieve the date from the database, too&quot; (which would harm performance), or perhaps something else. But I guess at this point, we already found out what the basic problem is: We&#039;re already way beyond a reasonable level of complexity.

Most apps are database applications, where data is not necessarily created by the application that reads it. In other words, you have one piece of data (a string) and multiple implementations that read and write it, maybe even in various languages (java, php, C# etc.). If you add to this, that you may even have various versions of each application, and many different installations, then you often end up in a situation where it doesn&#039;t make much sense to let the reader validate the data in a very high detail.

Some data may even pass multiple systems. I think that the longest path of data transmission, that I have been involved in, is to transmit very precise and structured data across at least 20 applications, using XML, tab-separated files, SQL and many other techniques, transferring data from the end-user to a national database. You don&#039;t want to update validation code in each of these systems every time the data standard changes a bit.

With regard to the other examples: The same GUI is usually used for all CPR-number registrations (requirement from users) and you wouldn&#039;t want to make a network transmission for every time you assign a name to a new variable in your code.</description>
		<content:encoded><![CDATA[<p>&#8220;No problem with an OrderId interface and different class implementations, depending on the date it was created. A no brainer.&#8221;</p>
<p>Ok. Please show me the code that solves this task:</p>
<p>You receive a tab-separated file like this:</p>
<p>123-456 45<br />
2345-22 78</p>
<p>Now, your code has to import this file. The first column contains order IDs, the second contains some value for this order ID. That could be statistical information or something completely different.</p>
<p>Your code must:<br />
- Read this file<br />
- Write a list of customer ID, order ID and this value</p>
<p>As you can see, it&#8217;s quite simple: You call a FetchCustomerIdForOrder (OrderId Id), and then you have the customer ID and can print everything. According to your &#8220;no brainer&#8221; explanation, that doesn&#8217;t work, because you don&#8217;t have the date of order creation, so you cannot create an OrderId object.</p>
<p>In other words, your explanation is wrong, and &#8220;no brainer&#8221; is probably not the best way to describe an faulty method. You can then say that &#8220;we create a non-checked orderid class&#8221; (which would be, like, a string?!?) or &#8220;we just retrieve the date from the database, too&#8221; (which would harm performance), or perhaps something else. But I guess at this point, we already found out what the basic problem is: We&#8217;re already way beyond a reasonable level of complexity.</p>
<p>Most apps are database applications, where data is not necessarily created by the application that reads it. In other words, you have one piece of data (a string) and multiple implementations that read and write it, maybe even in various languages (java, php, C# etc.). If you add to this, that you may even have various versions of each application, and many different installations, then you often end up in a situation where it doesn&#8217;t make much sense to let the reader validate the data in a very high detail.</p>
<p>Some data may even pass multiple systems. I think that the longest path of data transmission, that I have been involved in, is to transmit very precise and structured data across at least 20 applications, using XML, tab-separated files, SQL and many other techniques, transferring data from the end-user to a national database. You don&#8217;t want to update validation code in each of these systems every time the data standard changes a bit.</p>
<p>With regard to the other examples: The same GUI is usually used for all CPR-number registrations (requirement from users) and you wouldn&#8217;t want to make a network transmission for every time you assign a name to a new variable in your code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84420</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sun, 04 May 2008 08:11:53 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84420</guid>
		<description>@Lars: Excellent examples!

&quot;What about if a company changes it&#039;s order ID system. That would mean that orders from before 1990 must comply to xxx-xxx, orders from 1990-2005 must comply to yyyy-xx, and after 2005 they are again xxx-xxx, but restarting from zero.&quot;

No problem with an OrderId interface and different class implementations, depending on the date it was created. A no brainer.

With Strings? How do you validate an Id in a String without any further information? I guess that&#039;s impossible.

&quot;A national person identification number.&quot;

Excellent too, having different classes for an ID with different GUI frontend and Hibernate mappings, a no brainer. With a String this is much more difficult to implement (You need to encode the county in the number or something like that).

&quot;So I guess a name class would contain thousands of names in it’s source code? &quot;

Shouldn&#039;t that come from a NameService for your country which returns Name domain objects? With the validation in the service and the only possiblity to create names from the service, so you have always valid names? Compared to Strings which need to validated in lots of places?

Thanks for the examples, I could not have thought of better ones for my arguments.</description>
		<content:encoded><![CDATA[<p>@Lars: Excellent examples!</p>
<p>&#8220;What about if a company changes it&#8217;s order ID system. That would mean that orders from before 1990 must comply to xxx-xxx, orders from 1990-2005 must comply to yyyy-xx, and after 2005 they are again xxx-xxx, but restarting from zero.&#8221;</p>
<p>No problem with an OrderId interface and different class implementations, depending on the date it was created. A no brainer.</p>
<p>With Strings? How do you validate an Id in a String without any further information? I guess that&#8217;s impossible.</p>
<p>&#8220;A national person identification number.&#8221;</p>
<p>Excellent too, having different classes for an ID with different GUI frontend and Hibernate mappings, a no brainer. With a String this is much more difficult to implement (You need to encode the county in the number or something like that).</p>
<p>&#8220;So I guess a name class would contain thousands of names in it’s source code? &#8221;</p>
<p>Shouldn&#8217;t that come from a NameService for your country which returns Name domain objects? With the validation in the service and the only possiblity to create names from the service, so you have always valid names? Compared to Strings which need to validated in lots of places?</p>
<p>Thanks for the examples, I could not have thought of better ones for my arguments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84413</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Sun, 04 May 2008 07:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84413</guid>
		<description>@ Sean: I certainly know large systems (&gt;50 programmer manyears per app), and I don&#039;t recognize your support to not using string in projects of this size, because of the need for validation.

We could easily introduce a name verification, checking that first name and last name are both present, have initial caps letter etc. A University in USA once checked for presence of first name and last name, and then the son of our Queen wanted to study there, but as a royal he doesn&#039;t have a last name... so the IT system failed to help the University. Validation is good, but it should not prevent the user from getting things done.

Another example: A national person identification number. In Denmark, we use &quot;CPR-Numbers&quot;. However, if you check these fully, you will find that foreigners are suddenly excluded from your system, and you might end up being able to use your IT system for 90% of your work. The rest has to be done on paper, or you have to invent fake numbers. You can then discuss how to define person IDs, but you can be sure that the customer doesn&#039;t provide correct specs on this from the start.

What about if a company changes it&#039;s order ID system. That would mean that orders from before 1990 must comply to xxx-xxx, orders from 1990-2005 must comply to yyyy-xx, and after 2005 they are again xxx-xxx, but restarting from zero. An orderid class can do some checks but it cannot say, whether the orderID conforms to the current standard for orderIDs.

In Denmark, a validity test for names is quite easy: We have a list of approved names, so if the name doesn&#039;t appear in the list, it&#039;s not valid. So I guess a name class would contain thousands of names in it&#039;s source code? Doesn&#039;t make sense to me. Anyway, under certain rules, a name can be accepted, even if not on the list. This typically happens when somebody immigrates. In other words, the validity test depends on the context and external decisions.

Then we could discuss SQL string conformance test. Well - doesn&#039;t that depend on the database server? One of the big benefits with SQL is, that you can create a tool, and then use it for many different database systems, even for future database server versions that you haven&#039;t heard of yet. Can you validate SQL if you don&#039;t know the database server SQL standard, yet? Of course not, that would be utterly rubbish.

I could continue for a long time giving examples of where validation of strings or a stupid question: It&#039;s not WHETHER to validate or not, it&#039;s WHAT to validate and WHEN.

Basically, all this relates to how do you develop software. Do you use the waterfall model, agile software development or something else? Who provides the specs? How big a part of your costs goes to automating testing? If you spend close to 0% or 100% on automating testing, you&#039;re certainly spending your money unwise. A good projects spends something in-between, and good projects don&#039;t have unlimited access to money - because that makes them inefficient.</description>
		<content:encoded><![CDATA[<p>@ Sean: I certainly know large systems (&gt;50 programmer manyears per app), and I don&#8217;t recognize your support to not using string in projects of this size, because of the need for validation.</p>
<p>We could easily introduce a name verification, checking that first name and last name are both present, have initial caps letter etc. A University in USA once checked for presence of first name and last name, and then the son of our Queen wanted to study there, but as a royal he doesn&#8217;t have a last name&#8230; so the IT system failed to help the University. Validation is good, but it should not prevent the user from getting things done.</p>
<p>Another example: A national person identification number. In Denmark, we use &#8220;CPR-Numbers&#8221;. However, if you check these fully, you will find that foreigners are suddenly excluded from your system, and you might end up being able to use your IT system for 90% of your work. The rest has to be done on paper, or you have to invent fake numbers. You can then discuss how to define person IDs, but you can be sure that the customer doesn&#8217;t provide correct specs on this from the start.</p>
<p>What about if a company changes it&#8217;s order ID system. That would mean that orders from before 1990 must comply to xxx-xxx, orders from 1990-2005 must comply to yyyy-xx, and after 2005 they are again xxx-xxx, but restarting from zero. An orderid class can do some checks but it cannot say, whether the orderID conforms to the current standard for orderIDs.</p>
<p>In Denmark, a validity test for names is quite easy: We have a list of approved names, so if the name doesn&#8217;t appear in the list, it&#8217;s not valid. So I guess a name class would contain thousands of names in it&#8217;s source code? Doesn&#8217;t make sense to me. Anyway, under certain rules, a name can be accepted, even if not on the list. This typically happens when somebody immigrates. In other words, the validity test depends on the context and external decisions.</p>
<p>Then we could discuss SQL string conformance test. Well &#8211; doesn&#8217;t that depend on the database server? One of the big benefits with SQL is, that you can create a tool, and then use it for many different database systems, even for future database server versions that you haven&#8217;t heard of yet. Can you validate SQL if you don&#8217;t know the database server SQL standard, yet? Of course not, that would be utterly rubbish.</p>
<p>I could continue for a long time giving examples of where validation of strings or a stupid question: It&#8217;s not WHETHER to validate or not, it&#8217;s WHAT to validate and WHEN.</p>
<p>Basically, all this relates to how do you develop software. Do you use the waterfall model, agile software development or something else? Who provides the specs? How big a part of your costs goes to automating testing? If you spend close to 0% or 100% on automating testing, you&#8217;re certainly spending your money unwise. A good projects spends something in-between, and good projects don&#8217;t have unlimited access to money &#8211; because that makes them inefficient.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sean</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-2/#comment-84242</link>
		<dc:creator>sean</dc:creator>
		<pubDate>Sat, 03 May 2008 22:08:14 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84242</guid>
		<description>Lars is wrong in my opinion. If you have ever developed with large systems, especially those that don&#039;t use dependency injection (passing around 6  primitive/string objects) you will agree with stepan. 

I guess it depends on whether you understand OO. 

Lars, here is an example:

String orderId = &quot;2343590&quot;;

Where does the validation go? The answer is EVERY place you need it. Now your developers that want to user orderId need to put checks in everywhere. And your developers need to know how to validate an order - what was that class called again? Oh, and how are you going to retrieve it? I guess you could pass the order validator in, inject it or have a static service --- NOW you understand why code mess happens in most java projects!

Compare this to:

// throws OrderInvalidException
OrderId id id = new OrderId(&quot;2343590&quot;);

Now, whenever your developers have an OrderId, it is guaranteed to be valid, especially if it is defined as immutable. Simplicity.</description>
		<content:encoded><![CDATA[<p>Lars is wrong in my opinion. If you have ever developed with large systems, especially those that don&#8217;t use dependency injection (passing around 6  primitive/string objects) you will agree with stepan. </p>
<p>I guess it depends on whether you understand OO. </p>
<p>Lars, here is an example:</p>
<p>String orderId = &#8220;2343590&#8243;;</p>
<p>Where does the validation go? The answer is EVERY place you need it. Now your developers that want to user orderId need to put checks in everywhere. And your developers need to know how to validate an order &#8211; what was that class called again? Oh, and how are you going to retrieve it? I guess you could pass the order validator in, inject it or have a static service &#8212; NOW you understand why code mess happens in most java projects!</p>
<p>Compare this to:</p>
<p>// throws OrderInvalidException<br />
OrderId id id = new OrderId(&#8220;2343590&#8243;);</p>
<p>Now, whenever your developers have an OrderId, it is guaranteed to be valid, especially if it is defined as immutable. Simplicity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fred Swartz</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-84119</link>
		<dc:creator>Fred Swartz</dc:creator>
		<pubDate>Sat, 03 May 2008 18:37:40 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84119</guid>
		<description>I like your proposal, but understand the resistance to it.  Programming languages could make it easier by supporting more convenient type definitions, units, numeric subranges, operator overloading, etc.

Wrapping primitive numbers has advantages but without additional language support, it&#039;s hard to make use of numeric libraries (as was pointed out previously).

I&#039;ll try it on code I&#039;m working on now and see if it flies.</description>
		<content:encoded><![CDATA[<p>I like your proposal, but understand the resistance to it.  Programming languages could make it easier by supporting more convenient type definitions, units, numeric subranges, operator overloading, etc.</p>
<p>Wrapping primitive numbers has advantages but without additional language support, it&#8217;s hard to make use of numeric libraries (as was pointed out previously).</p>
<p>I&#8217;ll try it on code I&#8217;m working on now and see if it flies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-84054</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Sat, 03 May 2008 14:02:16 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84054</guid>
		<description>Good testing is about testing the most frequently used code and the most critical code.

I think it&#039;s more important to save manhours in the process of finding out, why a correct order ID retrieves a wrong order, than to optimize the unit tests for checking that the orders got the correct order ID.

You may construct examples where it makes sense to spend programming hours on encapsulating the data in a way that range checks, makes checksum calculations etc. every time a value is assigned, but there are surely many cases where the costs are bigger than the benefits.

The worst code you can get, is where almost everything is defined elsewhere. You don&#039;t need to add many programmers to a project like that, and you&#039;ll end up with huge overhead, low productivity or spaghetti code quickly.

Good code is where a new programmer, who doesn&#039;t know about the project, can add a new feature within an hour.</description>
		<content:encoded><![CDATA[<p>Good testing is about testing the most frequently used code and the most critical code.</p>
<p>I think it&#8217;s more important to save manhours in the process of finding out, why a correct order ID retrieves a wrong order, than to optimize the unit tests for checking that the orders got the correct order ID.</p>
<p>You may construct examples where it makes sense to spend programming hours on encapsulating the data in a way that range checks, makes checksum calculations etc. every time a value is assigned, but there are surely many cases where the costs are bigger than the benefits.</p>
<p>The worst code you can get, is where almost everything is defined elsewhere. You don&#8217;t need to add many programmers to a project like that, and you&#8217;ll end up with huge overhead, low productivity or spaghetti code quickly.</p>
<p>Good code is where a new programmer, who doesn&#8217;t know about the project, can add a new feature within an hour.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-84052</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 03 May 2008 13:39:17 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84052</guid>
		<description>&quot;[...] find bugs [...]&quot;

Excellent point. An &lt;code&gt;OrderId&lt;/code&gt; with validation logic, range checks etc can easily tested with unit tests to make it essentially bug free. See how much the Array bound checks in Java have helped with security problems. Because the logic is in the Array class.

A &lt;code&gt;String orderId&lt;/code&gt; is impossible to test, you need to test every input and output path of the code, and perhaps every usage to check for correct validation etc. Keeping logic local and encapsulated results in easier to test code I believe.</description>
		<content:encoded><![CDATA[<p>&#8220;[...] find bugs [...]&#8221;</p>
<p>Excellent point. An <code>OrderId</code> with validation logic, range checks etc can easily tested with unit tests to make it essentially bug free. See how much the Array bound checks in Java have helped with security problems. Because the logic is in the Array class.</p>
<p>A <code>String orderId</code> is impossible to test, you need to test every input and output path of the code, and perhaps every usage to check for correct validation etc. Keeping logic local and encapsulated results in easier to test code I believe.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-84050</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Sat, 03 May 2008 13:16:39 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84050</guid>
		<description>Readability is always important, but don&#039;t expect the reader to immediately understand identifiers that are not from the library.

OOP is very good, except when it makes source code much harder to understand for those readers, who needs to understand performance, security, find bugs etc.

Most source code is a compromise between readability, performance, productivity and safety, and it rarely makes sense to make one of these three parameters be dominate all code.</description>
		<content:encoded><![CDATA[<p>Readability is always important, but don&#8217;t expect the reader to immediately understand identifiers that are not from the library.</p>
<p>OOP is very good, except when it makes source code much harder to understand for those readers, who needs to understand performance, security, find bugs etc.</p>
<p>Most source code is a compromise between readability, performance, productivity and safety, and it rarely makes sense to make one of these three parameters be dominate all code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-84049</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 03 May 2008 13:12:06 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84049</guid>
		<description>@Lars: To make my point about encapsulation clear:

The user would get the OrderId for example by:

1. OrderId id = orderService.getNewId()
2. OrderId id = order.getId()
3. OrderId id = bookingSerivice book(Order order)

etc.

No need to know what the id is.

Or to follow your argumentation, &lt;i&gt;&quot;In order to fully understand the code&quot;&lt;/i&gt; one would always be forced to look into &lt;code&gt;String&lt;/code&gt; or &lt;code&gt;StringBuffer&lt;/code&gt; and understand the internal implementation (as you want to understand the OrderId implementation) to &lt;b&gt;fully&lt;/b&gt; understand the code. No one does that (except for finding bugs e.g. or to learn from the code)</description>
		<content:encoded><![CDATA[<p>@Lars: To make my point about encapsulation clear:</p>
<p>The user would get the OrderId for example by:</p>
<p>1. OrderId id = orderService.getNewId()<br />
2. OrderId id = order.getId()<br />
3. OrderId id = bookingSerivice book(Order order)</p>
<p>etc.</p>
<p>No need to know what the id is.</p>
<p>Or to follow your argumentation, <i>&#8220;In order to fully understand the code&#8221;</i> one would always be forced to look into <code>String</code> or <code>StringBuffer</code> and understand the internal implementation (as you want to understand the OrderId implementation) to <b>fully</b> understand the code. No one does that (except for finding bugs e.g. or to learn from the code)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-84044</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 03 May 2008 13:02:00 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84044</guid>
		<description>@Xavier: Thanks, agreement to my post is scarce and I thought I&#039;m living in a different universe ;-)</description>
		<content:encoded><![CDATA[<p>@Xavier: Thanks, agreement to my post is scarce and I thought I&#8217;m living in a different universe ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-84041</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 03 May 2008 12:59:28 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-84041</guid>
		<description>@Lars: Let’s compare these:

1. void book(String id);
2. void book(OrderId id); 

The second one is much clearer. If your system has an OrderId, the developer writing the book function needs to use the OrderId. He can then choose to poorly name the paramter &quot;id&quot;. In the first case if the developer chooses to name the parameter &quot;id&quot;, all others are lost.

&quot;The reader has no idea what is being passed. It could be a string, an integer, or a complicated object.&quot;

The reader doesn&#039;t need to care. That&#039;s the idea behind object oriented programming, which I understand is out of fashion our days (think encapsulation). 

&quot;In order to fully understand the code, you need to read in multiple places in the source code, which wastes programmer workhours.&quot;

See above, the developer gets an Id from the GUI or a service and doesn&#039;t care how the Id is implemented (again, encapsulation). 

Whereas with the String the user a.) knows implementation details of the id b.) build his application (book method) to the implementation of the id (String), not the semantic idea (id).</description>
		<content:encoded><![CDATA[<p>@Lars: Let’s compare these:</p>
<p>1. void book(String id);<br />
2. void book(OrderId id); </p>
<p>The second one is much clearer. If your system has an OrderId, the developer writing the book function needs to use the OrderId. He can then choose to poorly name the paramter &#8220;id&#8221;. In the first case if the developer chooses to name the parameter &#8220;id&#8221;, all others are lost.</p>
<p>&#8220;The reader has no idea what is being passed. It could be a string, an integer, or a complicated object.&#8221;</p>
<p>The reader doesn&#8217;t need to care. That&#8217;s the idea behind object oriented programming, which I understand is out of fashion our days (think encapsulation). </p>
<p>&#8220;In order to fully understand the code, you need to read in multiple places in the source code, which wastes programmer workhours.&#8221;</p>
<p>See above, the developer gets an Id from the GUI or a service and doesn&#8217;t care how the Id is implemented (again, encapsulation). </p>
<p>Whereas with the String the user a.) knows implementation details of the id b.) build his application (book method) to the implementation of the id (String), not the semantic idea (id).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xavier</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83995</link>
		<dc:creator>Xavier</dc:creator>
		<pubDate>Sat, 03 May 2008 10:48:35 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83995</guid>
		<description>Well, I perfectly understand your point... On one of our projects, we had a Person entity which of course had a &#039;name&#039; property as a String. When the testers came in, the first thing they tried when creating a Person instance (through our web ui) was to provide weird names (long names, names with forbidden characters)... we had to figure where to put the validation logic for names, we came up with 2 possibilities:

1) scatter that logic in the ui AND the entity (Person.setName) or
2) create a value object Name with the validation Logic.

In the end, I chose the second solution as it clearly had 2 advantages over the first one:

1) the validation was defined once and for all in one place (the Name class) and
2) when a wrong name was entered, the error was raised immediately when the Name object was created (in the ui), not when the entity was persisted (which is 2 layers deeper and harder too debug). I think this is related to the &#039;Fail fast&#039; principle: if the name is wrong, don&#039;t wait until you persist the Person to know about it.</description>
		<content:encoded><![CDATA[<p>Well, I perfectly understand your point&#8230; On one of our projects, we had a Person entity which of course had a &#8216;name&#8217; property as a String. When the testers came in, the first thing they tried when creating a Person instance (through our web ui) was to provide weird names (long names, names with forbidden characters)&#8230; we had to figure where to put the validation logic for names, we came up with 2 possibilities:</p>
<p>1) scatter that logic in the ui AND the entity (Person.setName) or<br />
2) create a value object Name with the validation Logic.</p>
<p>In the end, I chose the second solution as it clearly had 2 advantages over the first one:</p>
<p>1) the validation was defined once and for all in one place (the Name class) and<br />
2) when a wrong name was entered, the error was raised immediately when the Name object was created (in the ui), not when the entity was persisted (which is 2 layers deeper and harder too debug). I think this is related to the &#8216;Fail fast&#8217; principle: if the name is wrong, don&#8217;t wait until you persist the Person to know about it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lars D</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83967</link>
		<dc:creator>Lars D</dc:creator>
		<pubDate>Sat, 03 May 2008 09:15:42 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83967</guid>
		<description>Let&#039;s compare these:

1. void book(String orderId);        
2. void book(OrderId order);  

The first one:

- The reader understands immediately, that a string is passed, which represents an order ID
- Whereever this order ID is used inside the function, there is no doubt that it&#039;s an order ID

The second one:

- The reader has no idea what is being passed. It could be a string, an integer, or a complicated object.
- In order to fully understand the code, you need to read in multiple places in the source code, which wastes programmer workhours.
- Whereever the order variable is used, the code doesn&#039;t reveal that it contains an Order ID.

Therefore, it is quite obvious that the first of these two are the best choice.</description>
		<content:encoded><![CDATA[<p>Let&#8217;s compare these:</p>
<p>1. void book(String orderId);<br />
2. void book(OrderId order);  </p>
<p>The first one:</p>
<p>- The reader understands immediately, that a string is passed, which represents an order ID<br />
- Whereever this order ID is used inside the function, there is no doubt that it&#8217;s an order ID</p>
<p>The second one:</p>
<p>- The reader has no idea what is being passed. It could be a string, an integer, or a complicated object.<br />
- In order to fully understand the code, you need to read in multiple places in the source code, which wastes programmer workhours.<br />
- Whereever the order variable is used, the code doesn&#8217;t reveal that it contains an Order ID.</p>
<p>Therefore, it is quite obvious that the first of these two are the best choice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sean</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83934</link>
		<dc:creator>sean</dc:creator>
		<pubDate>Sat, 03 May 2008 06:57:41 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83934</guid>
		<description>I have definitely gone this way, consider the following:

public class Address {
  boolean multiline, virtual;
  String address;
  public Address(String add, boolean mul, boolean vir)// cant be bothered typing
}

I hate such code as it&#039;s hard to remember what the booleans mean some times. So I use now:

public class Address {
  enum Lines;
  enum Reality;
  String address;
  // you get the idea
}

This means you can create objects with meaningul names instead of booleans.
Eg. new Address(addr, Lines.MULTILINE, Reality.VIRTUAL);</description>
		<content:encoded><![CDATA[<p>I have definitely gone this way, consider the following:</p>
<p>public class Address {<br />
  boolean multiline, virtual;<br />
  String address;<br />
  public Address(String add, boolean mul, boolean vir)// cant be bothered typing<br />
}</p>
<p>I hate such code as it&#8217;s hard to remember what the booleans mean some times. So I use now:</p>
<p>public class Address {<br />
  enum Lines;<br />
  enum Reality;<br />
  String address;<br />
  // you get the idea<br />
}</p>
<p>This means you can create objects with meaningul names instead of booleans.<br />
Eg. new Address(addr, Lines.MULTILINE, Reality.VIRTUAL);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83905</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 03 May 2008 05:38:17 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83905</guid>
		<description>@Dan: &quot;[...] think it’s LIKELY that a String will satisfy all your needs.&quot; 

Perhaps you are right, but then it really doesn&#039;t matter for &lt;code&gt;FirstName&lt;/code&gt;, because you are mostly using the object only to construct a customer object you will use a dozen times. 

Look at another example, zip code. I bet most people in this thread use a primitive for zip code which creates a lot of problems when going i18n. And all those primitive defenders will use 

&lt;pre&gt;
Customer {
   String name;
   String street;
   String city;
   String zip;
}
&lt;/pre&gt;

instead of

&lt;pre&gt;
Customer {
   String name;
   Address address;
} 

Address {
   ZipCode code;
}
&lt;/pre&gt;

Are you still on the primitive side?</description>
		<content:encoded><![CDATA[<p>@Dan: &#8220;[...] think it’s LIKELY that a String will satisfy all your needs.&#8221; </p>
<p>Perhaps you are right, but then it really doesn&#8217;t matter for <code>FirstName</code>, because you are mostly using the object only to construct a customer object you will use a dozen times. </p>
<p>Look at another example, zip code. I bet most people in this thread use a primitive for zip code which creates a lot of problems when going i18n. And all those primitive defenders will use </p>
<pre>
Customer {
   String name;
   String street;
   String city;
   String zip;
}
</pre>
<p>instead of</p>
<pre>
Customer {
   String name;
   Address address;
} 

Address {
   ZipCode code;
}
</pre>
<p>Are you still on the primitive side?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83904</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 03 May 2008 05:31:39 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83904</guid>
		<description>@B.Waite: Sorry to disagree. 

&lt;i&gt;&quot;The main issue here is that the rest of the Java world uses primitives, and avoiding their use makes interacting with this world very difficult.&quot;&lt;/i&gt;

If you are using primitives all over, then your doing something wrong. Your methods should mostly use value objects and entities from the beginning (See parameter object pattern and others).

So we&#039;re only talking about 20 percent or less of primitives in method calls which I propose to replace with wrappers. 

&lt;i&gt;&quot;My advice (and what I understand to be a best practice) would be to choose the simplest possible solution.&quot;&lt;/i&gt;

Ah, but using a wrapper is simplier within your IDE than using String. And it is simpler to understand. You&#039;re against the idea because one time you need to write a little bit more code, say 10 lines. But code is written once (most of the time) by one develper but read a thousand times by dozens of developers. &lt;i&gt;I do know that currently writing less code is the hype, see Rails et al&lt;/i&gt;. But this is also wrong. It&#039;s not about writing less code, it&#039;s about writing maintainable code. 80% of costs will arise in maintenance, not in development.

So with a rapid development is the most important thing mindset, we will always disagree.</description>
		<content:encoded><![CDATA[<p>@B.Waite: Sorry to disagree. </p>
<p><i>&#8220;The main issue here is that the rest of the Java world uses primitives, and avoiding their use makes interacting with this world very difficult.&#8221;</i></p>
<p>If you are using primitives all over, then your doing something wrong. Your methods should mostly use value objects and entities from the beginning (See parameter object pattern and others).</p>
<p>So we&#8217;re only talking about 20 percent or less of primitives in method calls which I propose to replace with wrappers. </p>
<p><i>&#8220;My advice (and what I understand to be a best practice) would be to choose the simplest possible solution.&#8221;</i></p>
<p>Ah, but using a wrapper is simplier within your IDE than using String. And it is simpler to understand. You&#8217;re against the idea because one time you need to write a little bit more code, say 10 lines. But code is written once (most of the time) by one develper but read a thousand times by dozens of developers. <i>I do know that currently writing less code is the hype, see Rails et al</i>. But this is also wrong. It&#8217;s not about writing less code, it&#8217;s about writing maintainable code. 80% of costs will arise in maintenance, not in development.</p>
<p>So with a rapid development is the most important thing mindset, we will always disagree.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Java Primitive types - Blog@kohantech.com</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83877</link>
		<dc:creator>Java Primitive types - Blog@kohantech.com</dc:creator>
		<pubDate>Sat, 03 May 2008 03:50:39 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83877</guid>
		<description>[...] have been reading some articles on the net and I just read an interesting article about Java programming. The author in this article is explaining  the  reasons  why Java [...]</description>
		<content:encoded><![CDATA[<p>[...] have been reading some articles on the net and I just read an interesting article about Java programming. The author in this article is explaining  the  reasons  why Java [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Kaplan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83773</link>
		<dc:creator>Dan Kaplan</dc:creator>
		<pubDate>Fri, 02 May 2008 23:29:44 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83773</guid>
		<description>I can easily see the benefits of using a Price instead of a double under a lot of situations.  On the other hand, using a FirstName class instead of a String is a little iffy. I think it&#039;s LIKELY that a String will satisfy all your needs.</description>
		<content:encoded><![CDATA[<p>I can easily see the benefits of using a Price instead of a double under a lot of situations.  On the other hand, using a FirstName class instead of a String is a little iffy. I think it&#8217;s LIKELY that a String will satisfy all your needs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: B. Waite</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83667</link>
		<dc:creator>B. Waite</dc:creator>
		<pubDate>Fri, 02 May 2008 21:30:09 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83667</guid>
		<description>@stephan

I think the issue of semantics is a bit of a red herring.  If a parameter is poorly named and is undocumented, it&#039;s hardly the fault of the primitive.  It&#039;s sloppy coding.  I think it&#039;s fair to say that someone who won&#039;t go the extra inch to JavaDoc their code isn&#039;t going to go the extra mile and wrap their parameters.

The main issue here is that the rest of the Java world uses primitives, and avoiding their use makes interacting with this world very difficult.

For example, if I want to modify an ID&#039;s value using the Apache StringUtils class, I can&#039;t just pass the ID object.  I need to extract the String value from the ID, pass it to the StringUtils method, and finally construct a new wrapper using the result...

...that, or extend the ID class to include this functionality. Now, multiply this sort of problem by each framework or utility that you use.

My advice (and what I understand to be a best practice) would be to choose the simplest possible solution.  Use primitives whenever you can.  Like Visa, primitives are accepted everywhere.  When you outgrow one, just accept that you&#039;ll need to refactor and move on. ;-)</description>
		<content:encoded><![CDATA[<p>@stephan</p>
<p>I think the issue of semantics is a bit of a red herring.  If a parameter is poorly named and is undocumented, it&#8217;s hardly the fault of the primitive.  It&#8217;s sloppy coding.  I think it&#8217;s fair to say that someone who won&#8217;t go the extra inch to JavaDoc their code isn&#8217;t going to go the extra mile and wrap their parameters.</p>
<p>The main issue here is that the rest of the Java world uses primitives, and avoiding their use makes interacting with this world very difficult.</p>
<p>For example, if I want to modify an ID&#8217;s value using the Apache StringUtils class, I can&#8217;t just pass the ID object.  I need to extract the String value from the ID, pass it to the StringUtils method, and finally construct a new wrapper using the result&#8230;</p>
<p>&#8230;that, or extend the ID class to include this functionality. Now, multiply this sort of problem by each framework or utility that you use.</p>
<p>My advice (and what I understand to be a best practice) would be to choose the simplest possible solution.  Use primitives whenever you can.  Like Visa, primitives are accepted everywhere.  When you outgrow one, just accept that you&#8217;ll need to refactor and move on. ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83604</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Fri, 02 May 2008 20:24:34 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83604</guid>
		<description>I wonder how &lt;code&gt;Name&lt;/code&gt; works with Qi4j, where a &lt;code&gt;Name&lt;/code&gt; class could be configured into your Entity. Hmm. N8. All further comments need to wait till tomorrow to be moderated, no censorship just bedtime :-)</description>
		<content:encoded><![CDATA[<p>I wonder how <code>Name</code> works with Qi4j, where a <code>Name</code> class could be configured into your Entity. Hmm. N8. All further comments need to wait till tomorrow to be moderated, no censorship just bedtime :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/never-never-never-use-string-in-java-or-at-least-less-often/comment-page-1/#comment-83602</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Fri, 02 May 2008 20:15:02 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/05/02/never-never-never-use-string-in-java-or-at-least-less-often/#comment-83602</guid>
		<description>@Dan: in this case, obviously you don&#039;t need it. One method isn&#039;t complex enough to replace Strings. Considering thousands of methods - which every product grows into - this often needs to change. 

And I stand by my opinion: Using primitves (and as said before I consider String a primitive) as method paramters more often is a bad idea than not.

&quot;[...] the name of the variable is already semantic.&quot;

Yes, sometimes it is, sometimes it isn&#039;t. I&#039;m always for well named parameters and sometimes think about a parameter name for 10 minutes, and then change it again because I&#039;ve found something better. Having a object instead of a String/Long conveys the semantic better though - and I think it prevents bugs this way.

BUT reading all this comments bashing my post - most likely I&#039;m wrong :-)

(I&#039;d still use a Price class instead of double, and a PriceRange and a Money class, and - when there is semantic to a name - a Name class).</description>
		<content:encoded><![CDATA[<p>@Dan: in this case, obviously you don&#8217;t need it. One method isn&#8217;t complex enough to replace Strings. Considering thousands of methods &#8211; which every product grows into &#8211; this often needs to change. </p>
<p>And I stand by my opinion: Using primitves (and as said before I consider String a primitive) as method paramters more often is a bad idea than not.</p>
<p>&#8220;[...] the name of the variable is already semantic.&#8221;</p>
<p>Yes, sometimes it is, sometimes it isn&#8217;t. I&#8217;m always for well named parameters and sometimes think about a parameter name for 10 minutes, and then change it again because I&#8217;ve found something better. Having a object instead of a String/Long conveys the semantic better though &#8211; and I think it prevents bugs this way.</p>
<p>BUT reading all this comments bashing my post &#8211; most likely I&#8217;m wrong :-)</p>
<p>(I&#8217;d still use a Price class instead of double, and a PriceRange and a Money class, and &#8211; when there is semantic to a name &#8211; a Name class).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 1/105 queries in 0.200 seconds using disk
Object Caching 1900/1901 objects using disk

Served from: codemonkeyism.com @ 2012-05-21 18:14:08 -->
