<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-766045451035049369</id><updated>2011-04-22T06:17:11.825+02:00</updated><category term='while'/><category term='OutOfMemoryError'/><category term='solar winds'/><category term='isEmpty'/><category term='apache.org'/><category term='catch'/><category term='business'/><category term='=='/><category term='type'/><category term='Integer'/><category term='logic'/><category term='finally'/><category term='brackets'/><category term='europa'/><category term='bug'/><category term='constant'/><category term='javadoc'/><category term='intro'/><category term='Date'/><category term='String'/><category term='new'/><category term='solar flares'/><category term='parsing'/><category term='memory'/><category term='code design'/><category term='switch'/><category term='null'/><category term='naming conventions'/><category term='test'/><category term='for'/><category term='try'/><category term='cast'/><category term='toString'/><category term='copy/paste'/><category term='Iterator'/><category term='log'/><category term='eclipse.org'/><category term='joke'/><category term='code style'/><category term='performance'/><category term='data'/><category term='error'/><category term='if'/><category term='boolean'/><category term='database'/><title type='text'>all about stupid java code</title><subtitle type='html'>This blog is about all stupid line of codes wrote by java developers.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-8950921519014791653</id><published>2008-04-25T23:06:00.004+02:00</published><updated>2008-04-25T23:18:16.418+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='performance'/><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='memory'/><title type='text'>LOG kills</title><content type='html'>Never activates log in DEBUG mode. That kills memory and performance. Always use INFO. Debug should be used with AOP to trace execution only.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-8950921519014791653?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/8950921519014791653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=8950921519014791653' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8950921519014791653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8950921519014791653'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2008/04/log-kills.html' title='LOG kills'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-1334174233258415323</id><published>2008-04-16T22:15:00.001+02:00</published><updated>2008-04-16T22:18:39.703+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='code style'/><category scheme='http://www.blogger.com/atom/ns#' term='type'/><category scheme='http://www.blogger.com/atom/ns#' term='bug'/><title type='text'>Money money money, bug me honey</title><content type='html'>&lt;pre&gt;&lt;br /&gt;Money&lt;br /&gt;   int value;&lt;br /&gt;   String currency;&lt;br /&gt;&lt;br /&gt;Money add(Money initial, Money toAdd) {&lt;br /&gt;   int value = initial.getValue() + dogAmount.getValue();&lt;br /&gt;   Money money = new AnimalMoney(value, initial.getCurrency())&lt;br /&gt;&lt;br /&gt;   return money;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Everything looks alright, but it's not.&lt;br /&gt;&lt;br /&gt;Try to add money using these one :&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;   Money cat = new AnimalMoney(5, "cat");&lt;br /&gt;   Money dog = new AnimalMoney(1, "dog");&lt;br /&gt;&lt;br /&gt;   Money deal = add(cat, dog);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You will obtain 6 values of cat. Does 5 cats plus 1 dog equals 6 cats. I think not.&lt;br /&gt;&lt;br /&gt;Always think about the type of what you deal with. Remember your physics lectures when we calculate the result kind, like multiply hours by km per hour.&lt;br /&gt;&lt;br /&gt;One solution can be to lower the accessibility of the inner elements. Money value and currency should not be manipulated outside its package. Outside package code must only use helper function to manipulate them.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-1334174233258415323?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/1334174233258415323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=1334174233258415323' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1334174233258415323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1334174233258415323'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2008/04/money-money-money-bug-me-honey.html' title='Money money money, bug me honey'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-6419673428993691799</id><published>2008-04-15T01:50:00.005+02:00</published><updated>2008-04-15T02:02:20.668+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OutOfMemoryError'/><category scheme='http://www.blogger.com/atom/ns#' term='log'/><category scheme='http://www.blogger.com/atom/ns#' term='bug'/><title type='text'>OutOfMemoryError Problem To Log</title><content type='html'>How appears a vicious OutOfMemoryError on 2/3 of the dev computer ?&lt;br /&gt;&lt;br /&gt;The same JVM, the same sources, the same web server...&lt;br /&gt;&lt;br /&gt;Everything is the same ! Everything ? Not the application config file nor the log4j config file.&lt;br /&gt;&lt;br /&gt;Yep, OutOfMemory because of DEBUG level, others with INFO. Why ? Because of the fuck root handler the gives the DEBUG level for every API that use log4j, and so for the one that log the application database access. More than 1GB while we use only 300MB ordinary.&lt;br /&gt;&lt;br /&gt;Becareful with logger. Always use root INFO and provides category for your application packages.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-6419673428993691799?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/6419673428993691799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=6419673428993691799' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/6419673428993691799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/6419673428993691799'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2008/04/outofmemoryerror-problem-to-log.html' title='OutOfMemoryError Problem To Log'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-8151262875685031652</id><published>2007-09-20T18:33:00.000+02:00</published><updated>2007-09-20T18:41:26.199+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='null'/><category scheme='http://www.blogger.com/atom/ns#' term='if'/><category scheme='http://www.blogger.com/atom/ns#' term='toString'/><title type='text'>To be null or not to be ?</title><content type='html'>&lt;pre&gt;&lt;br /&gt;Book myBook = getBookFromSomeWhere();&lt;br /&gt;System.out.println("myBook: " + myBook);&lt;br /&gt;&lt;br /&gt;if (myBook == null) {&lt;br /&gt;    System.out.println("myBook is null");&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;    System.out.println("myBook is not null");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Run it ! And that display :&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;myBook: null&lt;br /&gt;myBook is not null&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;How is it possible ?&lt;br /&gt;&lt;br /&gt;Hahaha.&lt;br /&gt;&lt;br /&gt;It is because we have:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Book {&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;public String toString() {&lt;br /&gt;    return "null";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Funny, isn't it ?&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-8151262875685031652?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/8151262875685031652/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=8151262875685031652' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8151262875685031652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8151262875685031652'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/09/to-be-null-or-not-to-be.html' title='To be null or not to be ?'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-8537359578811926985</id><published>2007-08-29T16:15:00.000+02:00</published><updated>2007-08-29T16:23:21.206+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='error'/><category scheme='http://www.blogger.com/atom/ns#' term='bug'/><category scheme='http://www.blogger.com/atom/ns#' term='business'/><title type='text'>Out of subject : Errare Humanum Est</title><content type='html'>Basically the implementation look like :&lt;br /&gt;&lt;br /&gt;if client =&gt; send email to client&lt;br /&gt;if enterprise =&gt; send email to client&lt;br /&gt;if others =&gt; send email to client&lt;br /&gt;&lt;br /&gt;BUT this behavior was not as specified. It should be :&lt;br /&gt;&lt;br /&gt;if client =&gt; send NO email&lt;br /&gt;if enterprise =&gt; send email to enterprise&lt;br /&gt;if others =&gt; send email to enterprise&lt;br /&gt;&lt;br /&gt;And guess what, it was in production because of ME. Yes, ME. I'm gonna kill myself. How it could be, how I could make such a mistake. By focusing too much on code aspect.&lt;br /&gt;&lt;br /&gt;This teach me a great thing. Of course the code aspect, the architecture and so on are important, but the business target IS MORE IMPORTANT than every thing.&lt;br /&gt;&lt;br /&gt;Today, I was the stupid guy because Errare Humanum Est.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-8537359578811926985?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/8537359578811926985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=8537359578811926985' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8537359578811926985'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8537359578811926985'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/08/out-of-subject-errare-humanum-est.html' title='Out of subject : Errare Humanum Est'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-8721263442954419880</id><published>2007-08-03T14:13:00.000+02:00</published><updated>2007-08-03T14:27:20.860+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Date'/><category scheme='http://www.blogger.com/atom/ns#' term='=='/><title type='text'>What time is it ?</title><content type='html'>&lt;pre&gt;&lt;br /&gt;// defined previously&lt;br /&gt;// Date aDate = ...&lt;br /&gt;&lt;br /&gt;Date date = new Date();&lt;br /&gt;date = new Date(date.getTime());&lt;br /&gt;&lt;br /&gt;if (aDate != null &amp;&amp; aDate == date) {&lt;br /&gt;    date = new Date(date.getTime() + 10);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Hum, the biggest problem with this one is the equality condition test (aDate == date).&lt;br /&gt;In java, == DOESN'T compare value, except for primitive data type, it compares pointer.&lt;br /&gt;That's it, it test if two objects are same. To test if two object are equal (in value) use Object.equals method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then, it is trivial that&lt;br /&gt;&lt;pre&gt;Date date = new Date();&lt;br /&gt;date = new Date(date.getTime());&lt;br /&gt;&lt;/pre&gt; is stupid.&lt;br /&gt;&lt;pre&gt;Date date = new Date();&lt;/pre&gt; is sufficient.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-8721263442954419880?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/8721263442954419880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=8721263442954419880' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8721263442954419880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8721263442954419880'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/08/what-time-is-it.html' title='What time is it ?'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-677340913803087277</id><published>2007-07-13T15:52:00.000+02:00</published><updated>2007-07-13T16:30:46.950+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='new'/><category scheme='http://www.blogger.com/atom/ns#' term='javadoc'/><category scheme='http://www.blogger.com/atom/ns#' term='cast'/><title type='text'>cast it</title><content type='html'>&lt;pre&gt;&lt;br /&gt;public static int roundSup(float n){&lt;br /&gt;    int round=0;&lt;br /&gt;&lt;br /&gt;    if(n &gt; (new Float(n).intValue()))&lt;br /&gt;    round = new Float(n+1).intValue();&lt;br /&gt;    else round=new Float(n).intValue();&lt;br /&gt;&lt;br /&gt;    return round;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Sure it needs to create new Float object to do this operation. And the code is ugly.&lt;br /&gt;&lt;br /&gt;Try this,&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static int roundSup(&lt;br /&gt;        final float n&lt;br /&gt;) {&lt;br /&gt;    return ((int) n) + 1;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Wow ! Cleaner, clearer, better !&lt;br /&gt;Why just a cast  will do it ?&lt;br /&gt;&lt;br /&gt;See &lt;a href="http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.3"&gt;Java Language Specification 3rd : Narrowing Primitive Conversions&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;But don't forget to COMMENT you're code ! A code without comments it's like a life without meaning.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-677340913803087277?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/677340913803087277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=677340913803087277' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/677340913803087277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/677340913803087277'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/07/cast-it.html' title='cast it'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-1130537509020230730</id><published>2007-07-12T10:08:00.000+02:00</published><updated>2007-07-12T10:27:27.731+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='code style'/><category scheme='http://www.blogger.com/atom/ns#' term='naming conventions'/><title type='text'>Program Identifier Naming Conventions</title><content type='html'>&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs600/html/hunganotat.asp"&gt;Microsoft 1975 Charles Simonyi's explication of the Hungarian notation identifier naming convention.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What to say ? Most people thinks that they need to prefix program identifier (say variable, member...) with the system type. For boolean prefix with 'b' like bDone. For int prefix with 'i' like iCount.&lt;br /&gt;That's stupid to be so close to the system type. The thing that is important it's the meaning, count, or index, not the hard system type that can be changed.&lt;br /&gt;&lt;br /&gt;Let's read these:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.joelonsoftware.com/articles/Wrong.html"&gt;I’m Hungary&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/rick_schaut/archive/2004/02/14/73108.aspx"&gt;Hungarian Notation&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/oldnewthing/archive/2005/01/14/352949.aspx"&gt;Cleaner, more elegant, and harder to recognize&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://weblogs.asp.net/fbouma/archive/2005/07/01/414492.aspx"&gt;Dropping the 'I' from interface names?&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-1130537509020230730?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/1130537509020230730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=1130537509020230730' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1130537509020230730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1130537509020230730'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/07/program-identifier-naming-conventions.html' title='Program Identifier Naming Conventions'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-3063812285048015748</id><published>2007-07-10T14:47:00.000+02:00</published><updated>2007-07-10T17:41:44.425+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='catch'/><category scheme='http://www.blogger.com/atom/ns#' term='finally'/><category scheme='http://www.blogger.com/atom/ns#' term='try'/><title type='text'>try surprise me, catch my surprise, finally I'm surprised</title><content type='html'>&lt;pre&gt;&lt;br /&gt;public static int doSomething() {&lt;br /&gt;    int i = 0;&lt;br /&gt;    try {&lt;br /&gt;        i = 1;&lt;br /&gt;        System.out.print("a");&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;    catch (Exception e) {&lt;br /&gt;        i = 2;&lt;br /&gt;        System.out.print("b");&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;    finally {&lt;br /&gt;        i = 3;&lt;br /&gt;        System.out.print("c");&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;} // end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;return ?&lt;br /&gt;&lt;br /&gt;return 3 ! and print "ac".&lt;br /&gt;&lt;br /&gt;This code behave like the finally block is an inside method:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static int doSomething() {&lt;br /&gt;    int i = 0;&lt;br /&gt;    try {&lt;br /&gt;        i = 1;&lt;br /&gt;        System.out.print("a");&lt;br /&gt;        { // finally block&lt;br /&gt;            int another_i = 3;&lt;br /&gt;            System.out.print("c");&lt;br /&gt;            return another_i;&lt;br /&gt;        }&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;    catch (Exception e) {&lt;br /&gt;        i = 2;&lt;br /&gt;        System.out.print("b");&lt;br /&gt;        { // finally block&lt;br /&gt;            int another_i = 3;&lt;br /&gt;            System.out.print("c");&lt;br /&gt;            return another_i;&lt;br /&gt;        }&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;} // end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;...&lt;br /&gt;So, and if there is no return in finally block.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static int doSomething() {&lt;br /&gt;    int i = 0;&lt;br /&gt;    try {&lt;br /&gt;        i = 1;&lt;br /&gt;        System.out.print("a");&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;    catch (Exception e) {&lt;br /&gt;        i = 2;&lt;br /&gt;        System.out.print("b");&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;    finally {&lt;br /&gt;        i = 3;&lt;br /&gt;        System.out.print("c");&lt;br /&gt;        &lt;b&gt;// return i;&lt;/b&gt;&lt;br /&gt;    }&lt;br /&gt;} // end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It return 1 and print "ac".&lt;br /&gt;Behave like that:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public static int doSomething() {&lt;br /&gt;    int i = 0;&lt;br /&gt;    try {&lt;br /&gt;        i = 1;&lt;br /&gt;        System.out.print("a");&lt;br /&gt;        { // finally block&lt;br /&gt;            int another_i = 3;&lt;br /&gt;            System.out.print("c");&lt;br /&gt;        }&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;    catch (Exception e) {&lt;br /&gt;        i = 2;&lt;br /&gt;        System.out.print("b");&lt;br /&gt;        { // finally block&lt;br /&gt;            int another_i = 3;&lt;br /&gt;            System.out.print("c");&lt;br /&gt;        }&lt;br /&gt;        return i;&lt;br /&gt;    }&lt;br /&gt;} // end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The try-catch-finally doesn't really behave as first expected.&lt;br /&gt;See &lt;a href="http://www.cs.arizona.edu/projects/sumatra/hallofshame/"&gt;Java Hall Of Shame&lt;/a&gt;&lt;br /&gt;and &lt;a href="http://www.artima.com/underthehood/finally.html"&gt;finally&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-3063812285048015748?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/3063812285048015748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=3063812285048015748' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/3063812285048015748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/3063812285048015748'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/07/try-me-catch-my-surprise-finally-im.html' title='try surprise me, catch my surprise, finally I&apos;m surprised'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-1313540005043584792</id><published>2007-07-09T18:24:00.000+02:00</published><updated>2007-07-10T09:53:41.264+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='test'/><category scheme='http://www.blogger.com/atom/ns#' term='logic'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>space is too much</title><content type='html'>&lt;pre&gt;&lt;br /&gt;/**&lt;br /&gt; * Return the concatenation of first name and last name separated by a space.&lt;br /&gt; */&lt;br /&gt;public String getFullname() {&lt;br /&gt; String s = "";&lt;br /&gt;&lt;br /&gt; if (this.getFirstName() != null) {&lt;br /&gt;  s += this.getFirstName() + " ";&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; if (this.getLastName() != null) {&lt;br /&gt;  s += this.getLastName();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; return s;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Let's say that firstName = 'Pitt' and lastName = 'Dirk'. We got "Pitt Dirk". And what if the firstName is null, we got " Dirk". Hum, less good. &lt;br&gt;&lt;br /&gt;And what if both are null, we got " ", a space!&lt;br /&gt;&lt;br&gt;&lt;br /&gt;This f**king space mess up our database. The better, this kind of method are copied/pasted every where the same behavior was needed.&lt;br /&gt;&lt;br&gt;&lt;br /&gt;What do we need then ? A nice join method that concatenate elements of an Object array inserting a separator between elements and ignoring null and/or empty string.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-1313540005043584792?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/1313540005043584792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=1313540005043584792' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1313540005043584792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1313540005043584792'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/07/space-is-too-much.html' title='space is too much'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-974192657202106126</id><published>2007-07-03T22:22:00.000+02:00</published><updated>2007-07-03T22:24:51.637+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='europa'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse.org'/><title type='text'>Eclipse 3.3 Europa</title><content type='html'>&lt;object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="160" height="140" id="europa" align="middle"&gt;&lt;br /&gt;&lt;param name="allowScriptAccess" value="sameDomain" /&gt;&lt;br /&gt;&lt;param name="movie" value="http://www.eclipse.org/europa/images/europa.swf" /&gt;&lt;param name="quality" value="high" /&gt;&lt;param name="scale" value="noscale" /&gt;&lt;param name="bgcolor" value="#ffffff" /&gt;&lt;embed src="http://www.eclipse.org/europa/images/europa.swf" quality="high" scale="noscale" bgcolor="#ffffff" width="160" height="140" name="europa" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"&gt;&lt;/embed&gt;&lt;br /&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-974192657202106126?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/974192657202106126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=974192657202106126' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/974192657202106126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/974192657202106126'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/07/eclipse-33-europa.html' title='Eclipse 3.3 Europa'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-6331642151548365512</id><published>2007-06-29T23:05:00.000+02:00</published><updated>2007-06-29T23:24:00.051+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='data'/><category scheme='http://www.blogger.com/atom/ns#' term='copy/paste'/><category scheme='http://www.blogger.com/atom/ns#' term='test'/><category scheme='http://www.blogger.com/atom/ns#' term='database'/><title type='text'>Copy/Paste</title><content type='html'>&lt;pre&gt;&lt;br /&gt;client.setSiteId(clientForm.getSiteId());&lt;br /&gt;client.setPrestaId(clientForm.getSiteId());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;(Stupid)&lt;/i&gt;: Oooops boss. I've done a copy/paste bug 1 year ago. And now the database is a mess.&lt;br&gt;&lt;br /&gt;&lt;i&gt;(Boss)&lt;/i&gt;: Stupid ! You're fired !&lt;br&gt;&lt;br /&gt;&lt;br /&gt;I'd would be this boss BUT if this kind of bug is forgivable, it is unforgivable to let this bug pass tests. So, this boss is not a good boss.&lt;br /&gt;&lt;br /&gt;Data in database are EVERYTHING for the application. Applications without data are useless. See google ! They sell data, they make free software ;-)&lt;br /&gt;&lt;br /&gt;Copy/paste ok ! Human being makes a lot of stupid error. So, make test !!!&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-6331642151548365512?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/6331642151548365512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=6331642151548365512' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/6331642151548365512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/6331642151548365512'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/copypaste.html' title='Copy/Paste'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-7475987230143856028</id><published>2007-06-26T13:57:00.000+02:00</published><updated>2007-07-10T14:51:02.550+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='catch'/><category scheme='http://www.blogger.com/atom/ns#' term='joke'/><category scheme='http://www.blogger.com/atom/ns#' term='solar flares'/><category scheme='http://www.blogger.com/atom/ns#' term='try'/><category scheme='http://www.blogger.com/atom/ns#' term='solar winds'/><title type='text'>SolarFlaresException</title><content type='html'>&lt;pre&gt;&lt;br /&gt;try {&lt;br /&gt; doSomethingInSpace();&lt;br /&gt;}&lt;br /&gt;catch (SolarFlaresException e) {&lt;br /&gt; LOG.warn("Watch the solar winds !" + e);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is just a joke from an article about programming for spacecraft.&lt;br&gt;&lt;br /&gt;&lt;a href="http://www.pcworld.com/printable/article/id,114712/printable.html"&gt;Three Minutes With Mike Deliman&lt;/a&gt;&lt;br&gt;&lt;br /&gt;&lt;a href="http://acmqueue.com/modules.php?name=Content&amp;pa=printer_friendly&amp;pid=227&amp;page=4"&gt;A Conversation with Mike Deliman&lt;/a&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-7475987230143856028?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/7475987230143856028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=7475987230143856028' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/7475987230143856028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/7475987230143856028'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/solarflaresexception.html' title='SolarFlaresException'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-6625383753343141052</id><published>2007-06-25T12:27:00.000+02:00</published><updated>2007-06-25T12:34:15.363+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='boolean'/><title type='text'>Bool It</title><content type='html'>&lt;pre&gt;&lt;br /&gt;new Boolean(true);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Correct ? No ! Because&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;new Boolean(true) != new Boolean(true);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Boolean.TRUE == Boolean.TRUE;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Boolean.valueOf(true) == Boolean.valueOf(true);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It is a java design problem but it is too late to correct it, the constructor is public.&lt;br /&gt;Some serialization and deserialization failed because of it.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-6625383753343141052?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/6625383753343141052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=6625383753343141052' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/6625383753343141052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/6625383753343141052'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/bool-it.html' title='Bool It'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-5896043061795017867</id><published>2007-06-20T17:57:00.000+02:00</published><updated>2007-06-20T18:05:22.825+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='while'/><category scheme='http://www.blogger.com/atom/ns#' term='Iterator'/><category scheme='http://www.blogger.com/atom/ns#' term='for'/><title type='text'>for a while</title><content type='html'>&lt;pre&gt;&lt;br /&gt;for (Iterator iter = myList.iterator(); iter.hasNext(); /* noop */) {&lt;br /&gt;    Object element = iter.next();&lt;br /&gt;    ...&lt;br /&gt;} // end for iter&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Iterator iter = myList.iterator();&lt;br /&gt;while (iter.hasNext()) {&lt;br /&gt;    Object element = iter.next();&lt;br /&gt;    ...&lt;br /&gt;} // end while iter&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-5896043061795017867?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/5896043061795017867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=5896043061795017867' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/5896043061795017867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/5896043061795017867'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/for-while.html' title='for a while'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-8105303610736923711</id><published>2007-06-20T14:10:00.000+02:00</published><updated>2007-06-20T17:55:14.498+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='constant'/><category scheme='http://www.blogger.com/atom/ns#' term='code design'/><category scheme='http://www.blogger.com/atom/ns#' term='if'/><title type='text'>Constant++</title><content type='html'>&lt;pre&gt;&lt;br /&gt;// FYI: Constants is a class (not an interface)&lt;br /&gt;&lt;br /&gt;if (ts != null &amp;&amp; ts.getTs().intValue() == 1){&lt;br /&gt; nbPc = Constants.CONST1A;&lt;br /&gt; Constants.CONST1A = Constants.CONST1A + 1;&lt;br /&gt;&lt;br /&gt; nbPs = Constants.CONST1B;&lt;br /&gt; Constants.CONST1B = Constants.CONST1B + 1;&lt;br /&gt;} else if (ts != null &amp;&amp; ts.getTs().intValue() == 2){&lt;br /&gt; nbPc = Constants.CONST2A;&lt;br /&gt; Constants.CONST2A = Constants.CONST2A + 1;&lt;br /&gt;&lt;br /&gt; nbPs = Constants.CONST2B;&lt;br /&gt; Constants.CONST2B = Constants.CONST2B + 1;&lt;br /&gt;} else if (ts != null &amp;&amp; ts.getTs().intValue() == 3){&lt;br /&gt; nbPc = Constants.CONST3A;&lt;br /&gt; Constants.CONST3A = Constants.CONST3A + 1;&lt;br /&gt;&lt;br /&gt; nbPs = Constants.CONST3B;&lt;br /&gt; Constants.CONST3B = Constants.CONST3B + 1;&lt;br /&gt;} else if (ts != null &amp;&amp; ts.getTs().intValue() == 4){&lt;br /&gt; nbPc = Constants.CONST4A;&lt;br /&gt; Constants.CONST4A = Constants.CONST4A + 1;&lt;br /&gt;&lt;br /&gt; nbPs = Constants.CONST4B;&lt;br /&gt; Constants.CONST4B = Constants.CONST4B + 1;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Oh that ignominious code.&lt;br /&gt;First, it appears that if some fields were in a Class named Constants, they will be final.&lt;br /&gt;The ts variable can be tested different from null only once.&lt;br /&gt;Use myVariable++ instead of myVariable = myVariable + 1&lt;br /&gt;At last, the use of if-statement to compare ts.getTs().intValue() to an int is not the best technic.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-8105303610736923711?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/8105303610736923711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=8105303610736923711' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8105303610736923711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8105303610736923711'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/how-to-do-non-comprehensive-and.html' title='Constant++'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-863500778526174815</id><published>2007-06-20T11:08:00.000+02:00</published><updated>2007-06-20T17:56:58.915+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='isEmpty'/><category scheme='http://www.blogger.com/atom/ns#' term='apache.org'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Is empty String ?</title><content type='html'>How to test that a String is empty?&lt;br /&gt;&lt;br /&gt;A lot of people use:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;myString.equals("")&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Some use:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;"".equals(myString)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Few use:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;myString.length() == 0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Fewer use:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;myString != null &amp;&amp; myString.length() == 0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Lazy people use:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;org.apache.commons.lang.StringUtils.isEmpty(myString)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Which one is the best solution ?&lt;br /&gt;&lt;br /&gt;I tell you ! Be lazy ! Knows libraries like you learn new word from dictionary.&lt;br /&gt;Why ? Because, apache people ARE good. Because it is already done by another. Because it is free.&lt;br /&gt;&lt;br /&gt;Else? Use&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;myString != null &amp;&amp; myString.length() == 0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;because a String might be null and because it is really fast to test the String length instead of its content.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-863500778526174815?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/863500778526174815/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=863500778526174815' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/863500778526174815'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/863500778526174815'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/is-empty-string.html' title='Is empty String ?'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-1275515776957473638</id><published>2007-06-20T09:43:00.000+02:00</published><updated>2007-06-20T17:55:39.396+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='code style'/><category scheme='http://www.blogger.com/atom/ns#' term='if'/><category scheme='http://www.blogger.com/atom/ns#' term='brackets'/><title type='text'>No brackets !</title><content type='html'>Let's have:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (condition)&lt;br /&gt;    doSomething();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And later, add doOtherThing() method to the condition.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (condition)&lt;br /&gt;    doSomething();&lt;br /&gt;    doOtherThing();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And later, it appends. Ooops. I forgot the brackets.&lt;br /&gt;So, I don't know why it is not required in every languages, BUT you MUST always use brackets.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (condition) {&lt;br /&gt;    doSomething();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And then&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if (condition) {&lt;br /&gt;    doSomething();&lt;br /&gt;    doOtherThing();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This time I didn't forget the brackets 8-))&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-1275515776957473638?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/1275515776957473638/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=1275515776957473638' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1275515776957473638'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/1275515776957473638'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/its-not-my-fault-ive-missed-brackets.html' title='No brackets !'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-8968768948174972753</id><published>2007-06-14T23:41:00.000+02:00</published><updated>2007-06-20T17:56:15.737+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='code design'/><category scheme='http://www.blogger.com/atom/ns#' term='switch'/><title type='text'>Switch for dummy</title><content type='html'>&lt;pre&gt;&lt;br /&gt;// sql is a StringBuffer&lt;br /&gt;// params is an array of String defined previously&lt;br /&gt;// paramsTmp is a String.&lt;br /&gt;&lt;br /&gt;switch(i) {&lt;br /&gt;    case 1 :&lt;/span&gt;&lt;br /&gt;        sql.append(", ");&lt;/span&gt;&lt;br /&gt;        i++;&lt;/span&gt;&lt;br /&gt;        params[1] = paramsTmp;&lt;/span&gt;&lt;br /&gt;        break;&lt;/span&gt;&lt;br /&gt;    case 2:&lt;/span&gt;&lt;br /&gt;        sql.append(", ");&lt;/span&gt;&lt;br /&gt;        i++;&lt;/span&gt;&lt;br /&gt;        params[2] = paramsTmp;&lt;/span&gt;&lt;br /&gt;        break;&lt;/span&gt;&lt;br /&gt;    case 3:&lt;/span&gt;&lt;br /&gt;        sql.append(", ");&lt;/span&gt;&lt;br /&gt;        i++;&lt;/span&gt;&lt;br /&gt;        params[3] = paramsTmp;&lt;/span&gt;&lt;br /&gt;        break;&lt;/span&gt;&lt;br /&gt;    case 4 :&lt;/span&gt;&lt;br /&gt;        sql.append(", ");&lt;/span&gt;&lt;br /&gt;        i++;&lt;/span&gt;&lt;br /&gt;        params[4] = paramsTmp;&lt;/span&gt;&lt;br /&gt;        break;&lt;/span&gt;&lt;br /&gt;    case 5 :&lt;/span&gt;&lt;br /&gt;        sql.append(", ");&lt;/span&gt;&lt;br /&gt;        i++;&lt;/span&gt;&lt;br /&gt;        params[5] = paramsTmp;&lt;/span&gt;&lt;br /&gt;        break;&lt;/span&gt;&lt;br /&gt;    case 6 :&lt;/span&gt;&lt;br /&gt;        sql.append(", ");&lt;/span&gt;&lt;br /&gt;        i++;&lt;/span&gt;&lt;br /&gt;        params[6] = paramsTmp;&lt;/span&gt;&lt;br /&gt;        break;&lt;/span&gt;&lt;br /&gt;    case 7 :&lt;/span&gt;&lt;br /&gt;        sql.append(", ");&lt;/span&gt;&lt;br /&gt;        i++;&lt;/span&gt;&lt;br /&gt;        params[7] = paramsTmp;&lt;/span&gt;&lt;br /&gt;        break;&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is insane. The guy who develops this is seriously sick. I'd known him ;-p&lt;br /&gt;He told me: "Just 3 lines? How are you sure that's working ?"&lt;br /&gt;These kind of developers don't understand what they do.&lt;br /&gt;&lt;br /&gt;Of course a simpler solution was:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sql.append(", ");&lt;br /&gt;params[i] = paramsTmp;&lt;br /&gt;i++;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Not 40 lines, just 3 lines and very clear ones.&lt;br /&gt;&lt;br /&gt;Generally, we don't need a switch. It is for bad developer, one who doesn't know pattern. Use if-else statement instead but there are better solutions.&lt;br /&gt;Use an array or a List when possible, like:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;final String[] myValues = {"a", "b", "c"};&lt;br /&gt;final String value = myValues[index];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If the switch values is a fixed enumeration, use enum pattern instead. It is really powerfull.&lt;br /&gt;Look at &lt;a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html"&gt;Java 1.5 Enums&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;You can do such thing:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/**&lt;br /&gt; * MyEnum declaration.&lt;br /&gt; */&lt;br /&gt;enum MyEnum {&lt;br /&gt;    A("A"),&lt;br /&gt;    B("B");&lt;br /&gt;&lt;br /&gt;    private final String mValue;&lt;br /&gt;&lt;br /&gt;    MyEnum(&lt;br /&gt;        final String value&lt;br /&gt;    ) {&lt;br /&gt;        this.mValue = value;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getValue() {&lt;br /&gt;        return this.mValue;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static MyEnum forValue(&lt;br /&gt;        final String value&lt;br /&gt;    ) {&lt;br /&gt;        for (final MyEnum myEnum : values()) {&lt;br /&gt;            if (myEnum.getValue().equals(value)) {&lt;br /&gt;                return myEnum;&lt;br /&gt;            }&lt;br /&gt;            return null;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;MyEnum use:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;final String aValue = getValueSomewhere(...)&lt;br /&gt;MyEnum.forValue(aValue);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;See? no more switch needed.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-8968768948174972753?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/8968768948174972753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=8968768948174972753' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8968768948174972753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/8968768948174972753'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/switch-strictly-forbidden-for-dummy.html' title='Switch for dummy'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-2404352041725415924</id><published>2007-06-14T17:56:00.000+02:00</published><updated>2007-06-14T18:12:04.022+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='parsing'/><category scheme='http://www.blogger.com/atom/ns#' term='Integer'/><category scheme='http://www.blogger.com/atom/ns#' term='String'/><title type='text'>Code completion and a lazy developer</title><content type='html'>&lt;span style="font-family:courier new;"&gt;(Integer) Integer.getInteger("12345")&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Wow, that a nice stupid code. I lost 1 hour because of it. Thanks to YOU! The static Integer.getInteger(String) method return the value of a SYSTEM, I repeat a SYSTEM, property as an Integer. Hey! Lazy developers, read the javadoc before code completion.&lt;br /&gt;&lt;br /&gt;Use this instead:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;(Integer) &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;Integer.valueOf(String)&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:courier new;"&gt;(int) &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;Integer.parseInt(String)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-2404352041725415924?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/2404352041725415924/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=2404352041725415924' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/2404352041725415924'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/2404352041725415924'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/code-completion-and-lazy-developer.html' title='Code completion and a lazy developer'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-766045451035049369.post-3363781977596756837</id><published>2007-06-14T17:34:00.000+02:00</published><updated>2007-06-17T22:03:49.051+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='String'/><category scheme='http://www.blogger.com/atom/ns#' term='intro'/><title type='text'>Intro</title><content type='html'>This blog is about all stupid line of codes wrote by java developers (mostly). I will comment why they're stupid.&lt;br /&gt;&lt;br /&gt;Let's start:&lt;br /&gt;&lt;pre style="font-family: courier new;"&gt;new String("").toString();&lt;/pre&gt;It is a really usefull code. Just to be sure that we've got an empty String. Yes, why not complete it like that just to be sure we have an empty String.&lt;br /&gt;&lt;pre style="font-family: courier new;"&gt;new String("").toString().substring(0, 0).trim();&lt;/pre&gt;Of course it is a stupid code. You want an empty String.&lt;br /&gt;&lt;pre style="font-family: courier new;"&gt;""&lt;/pre&gt;Got it.&lt;br /&gt;&lt;br /&gt;It is stupid to do so because "" will create a new instance of String(), new String("") will do the same and toString() is just a shortcut to this String.&lt;div class="blogger-post-footer"&gt;&lt;script src="http://www.google-analytics.com/urchin.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script type="text/javascript"&gt;
_uacct = "UA-2148887-1";
urchinTracker();
&lt;/script&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/766045451035049369-3363781977596756837?l=stupid-code.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://stupid-code.blogspot.com/feeds/3363781977596756837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=766045451035049369&amp;postID=3363781977596756837' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/3363781977596756837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/766045451035049369/posts/default/3363781977596756837'/><link rel='alternate' type='text/html' href='http://stupid-code.blogspot.com/2007/06/intro.html' title='Intro'/><author><name>amertum</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
