<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Medieval Programming &#187; java</title>
	<atom:link href="http://blog.hma-info.de/category/programming/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hma-info.de</link>
	<description>Fabians random thoughts about work and private life</description>
	<lastBuildDate>Thu, 16 Jun 2011 09:12:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Ugliest Code of the Year</title>
		<link>http://blog.hma-info.de/2010/01/13/ugliest-code-of-the-year/</link>
		<comments>http://blog.hma-info.de/2010/01/13/ugliest-code-of-the-year/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 11:03:20 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.hma-info.de/?p=209</guid>
		<description><![CDATA[Usually I rant about code from others. But this is something different. this is my code: PdfPCell pdfPCell = table.getRow&#40;0&#41;.getCells&#40;&#41;&#91;0&#93;; List compositeElements = pdfPCell.getCompositeElements&#40;&#41;; Paragraph p = &#40;Paragraph&#41; compositeElements.get&#40;0&#41;; Chunk c = &#40;Chunk&#41; p.get&#40;0&#41;; Jpeg jpeg = &#40;Jpeg&#41; &#40;&#40;&#40;Object&#91;&#93;&#41;c.getAttributes&#40;&#41;.get&#40;&#34;IMAGE&#34;&#41;&#41;&#91;0&#93;&#41;; Now comes my excuse for this crap. I need to parse this HTML and render it [...]]]></description>
			<content:encoded><![CDATA[<p>Usually I rant about code from others. But this is something different. this is my code:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">PdfPCell pdfPCell = table.<span style="color: #006633;">getRow</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCells</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003399; font-weight: bold;">List</span> compositeElements = pdfPCell.<span style="color: #006633;">getCompositeElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Paragraph p = <span style="color: #009900;">&#40;</span>Paragraph<span style="color: #009900;">&#41;</span> compositeElements.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Chunk c = <span style="color: #009900;">&#40;</span>Chunk<span style="color: #009900;">&#41;</span> p.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Jpeg jpeg = <span style="color: #009900;">&#40;</span>Jpeg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>c.<span style="color: #006633;">getAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;IMAGE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now comes my excuse for this crap. I need to parse this HTML and render it in a PDF (currently using iText):</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot;&gt;
&lt;tr&gt;
&lt;td width=&quot;1%&quot;&gt;&lt;img height=&quot;100&quot; border=&quot;0&quot; width=&quot;150&quot; src=&quot;/pat_to.jpg&quot; /&gt;&lt;/td&gt;
&lt;td&gt;some fancy text&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</pre></div></div>

<p>iText cannot automatically resize columns. So the column needs an explicit width. I don&#8217;t know the width of the table, because its not on the page, so I need the page width. I need to delve into the cell of the table which I know to contain the image. I need to know that its an Jpeg and that it had no alignment because if it had it would not be wrapped as chunk in a paragraph.<br />
This is among the ugliest I ever wrote. But now my excuse. It is not my faul <img src='http://blog.hma-info.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The iText API (in 2.7.1) is not consistent at all, you have Arrays, Lists, Maps mixed and matched, keys as String, Constant (public or private constant) or no keys at all. Properties of images stored for each type in a different way. And you need to know a lot on yout parsed html structure, because iText cannot discover it. The way the HTML parser is implemented is way to basic and not extendable.</p>
<p>Currently thinking about switching to POI or rewriting the iTextParser&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hma-info.de/2010/01/13/ugliest-code-of-the-year/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why do people code like that? And how do you review it?</title>
		<link>http://blog.hma-info.de/2009/11/01/why-do-people-code-like-that-and-how-do-you-review-it/</link>
		<comments>http://blog.hma-info.de/2009/11/01/why-do-people-code-like-that-and-how-do-you-review-it/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 21:13:09 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.hma-info.de/?p=203</guid>
		<description><![CDATA[if &#40;!&#34;&#34;==paramString.trim&#40;&#41; &#38;&#38; paramString.trim&#40;&#41;.length&#40;&#41; &#62; 0 &#38;&#38; paramString != null&#41; I do like to coach colleagues and totally stangers in writing good code. I believe there is also a lot I can learn. My colleague Thomas tweeted: unless&#40;!disable_message_hiding&#41; &#123;...&#125; quad negation. !@#$@# (via @mhevery) I think I could have done this myself some time ago. [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">&quot;&quot;</span>==paramString.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> paramString.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> paramString <span style="color: #339933;">!</span>= <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>I do like to coach colleagues and totally stangers in writing good code. I believe there is also a lot I can learn.<br />
<a href="http://twitter.com/ThomasJaspers/status/5309684159">My colleague Thomas tweeted</a>:</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;">unless<span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>disable_message_hiding<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>...<span style="color: #009900;">&#125;</span></pre></div></div>

<p>quad negation. !@#$@# (via @mhevery)</p></blockquote>
<p>I think I could have done this myself some time ago. You have to learn to avoid negations so this doesn&#8217;t pile up like that. I can understand that somebody might have coded that.<br />
But coming back to the line at the beginning of this post:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #0000ff;">&quot;&quot;</span>==paramString.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> paramString.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> paramString <span style="color: #339933;">!</span>= <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>How can somebody write this code? Obviously not test driven, because test would have showed that this code is actually mostly nonfunctional.<br />
Ok, when beginning with Java it can happen to you that you check String equality with == and not with String.equals(). Interestingly this does work quite often (but people don&#8217;t know <a href="http://en.wikipedia.org/wiki/String_interning">why</a>).<br />
trim() shows already some more advanced understanding, because why else would you understand that you want to remove spaces from the string first.<br />
But after having understood that we need to trim() before comparing to empty string, why the additional length check?<br />
And why the hell the not null check? I suspect there was once a stacktrace in the log and this was supposed to fix this. Obviously in reality this method almost never gets null.</p>
<p>So: How could this code have been created?  I think the author had no understanding of what he was doing there.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>paramString.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>is code Newbies would write. Its not bad. it is actually covering most of the normal cases. It is almost not worse than the previous example but much easier to read.</p>
<p>Such &#8220;empty String&#8221; checking is almost in every code. This is why commons-lang provided us with something neat:</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> StringUtils.<span style="color: #006633;">isEmpty</span><span style="color: #009900;">&#40;</span>paramString<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>How do you handle talking about bad code in code reviews? Pair programming?<br />
I found it hard. So i decided to go the way Douglas Crockford goes when he talks about <a href="http://www.jslint.com/lint.html">JSlint</a>:</p>
<blockquote><p><strong>Warning!</strong><br />
JSLint will hurt your feelings.</p></blockquote>
<p>I say: &#8220;that code makes no sense&#8221;, &#8220;that code is stupid&#8221;, &#8220;that can be done way shorter&#8221;, &#8220;code repetition &#8211; thats evil&#8221;.<br />
It is like the standard measure for code reviews:</p>
<div class="wp-caption alignnone" style="width: 510px"><img title="WTFs per Minute" src="http://www.codinghorror.com/blog/images/the-only-valid-measurement-of-code-quality-wtfs-per-minute.png" alt="WTFs per Minute" width="500" height="453" /><p class="wp-caption-text">WTFs per Minute</p></div>
<p>I usually try to avoid to call the author stupid. But I try also to be very clear on the code. Usually it helps showing how this can be done much better.<br />
Can somebody recommend a paper or book on the topic?</p>
<p>Oh, in case I did review your code and say something nasty:<strong> I apologize</strong>. I want to make the code better. I want us all to produce better code. Better code saves us weekends!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hma-info.de/2009/11/01/why-do-people-code-like-that-and-how-do-you-review-it/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>State of the Art Dependency Injection for PHP</title>
		<link>http://blog.hma-info.de/2009/06/30/state-of-the-art-dependency-injection-for-php/</link>
		<comments>http://blog.hma-info.de/2009/06/30/state-of-the-art-dependency-injection-for-php/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 09:04:37 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://blog.hma-info.de/?p=163</guid>
		<description><![CDATA[The second symfony component has gone live. It is the Dependency Injection Monkey. For me as a Java guy, who is used to Spring or Guice it is a relief to see that finally there is a compact and great PHP DI container available. If you never have heard about dependency injection (also called Inversion [...]]]></description>
			<content:encoded><![CDATA[<p>The second<a href="http://components.symfony-project.org/"> symfony component</a> has gone live. It is the <a href="http://components.symfony-project.org/dependency-injection/" target="_blank">Dependency Injection Monkey</a>. For me as a Java guy, who is used to <a href="http://www.springsource.org/">Spring</a> or <a href="http://code.google.com/p/google-guice/">Guice</a> it is a relief to see that finally there is a compact and great PHP DI container available. If you never have heard about <a href="http://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a> (also called Inversion of Control) you should try to understand it. If you have and are developing PHP you should try the symfony dependency injection. Or better If you are on Java, try Spring <img src='http://blog.hma-info.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hma-info.de/2009/06/30/state-of-the-art-dependency-injection-for-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Blogging live from JAX</title>
		<link>http://blog.hma-info.de/2009/04/21/blogging-live-from-jax/</link>
		<comments>http://blog.hma-info.de/2009/04/21/blogging-live-from-jax/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 12:56:38 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.hma-info.de/?p=149</guid>
		<description><![CDATA[I am currently standing at out booth in the Rheingoldhalle in Mainz, where the JAX 2009 is taking place. Quite an amazing amount of high quality talks, and good talks and networking inbetween the session. codecentric is silver sponsor, we are having three nice sessions for you to attend and are also blogging live from [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently standing at out booth in the Rheingoldhalle in Mainz, where the<a href="http://it-republik.de/jaxenter/jax/"> JAX 2009</a> is taking place. Quite an amazing amount of <a href="http://it-republik.de/jaxenter/jax/">high quality talks</a>, and good talks and networking inbetween the session. <a href="http://www.codecentric.de/">codecentric</a> is silver sponsor, we are having three nice sessions for you to attend and are also <a href="http://it-republik.de/jaxenter/news/Eindruecke-von-der-JAX-Turmbau-zu-Babel-048459.html">blogging live</a> from here, and advertising <a href="http://www.meettheexperts.de">meet the experts</a>.</p>
<p>I already had a great talk from <a href="http://www.angelikalanger.com/">Angelika Langer</a> which caused some worries about concurrency in my mind, and a talk about <a href="http://www.jboss.com/products/jbpm/">jBPM</a> which looks really like a BPM solution one can include in an existing Java Architecture. I especially liked that you can JUnit test it.</p>
<p>Tonight we will have dinner at the famous Waldgeist Hofheim, where you can get a 2.5 kg Schnitzel! Hmmm tasty <img src='http://blog.hma-info.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Update</strong><br />
Mirko just put up a new blog posting on our company blog including a nice picture showing us at our booth. I shamelessly copy it <img src='http://blog.hma-info.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<img src="http://blog.codecentric.de/wp-content/uploads/2009/04/jax-02.jpg" alt="" align="center"/></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hma-info.de/2009/04/21/blogging-live-from-jax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Want to ask a guru?</title>
		<link>http://blog.hma-info.de/2009/03/30/want-to-ask-a-guru/</link>
		<comments>http://blog.hma-info.de/2009/03/30/want-to-ask-a-guru/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 08:24:02 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://blog.hma-info.de/?p=145</guid>
		<description><![CDATA[Andrew Hunt writes in Pragmatic Progammer (an excellent book by the way) that you should consult a Guru on a topic where you find it difficult to find a good solution for a problem. But he admits that many companies are short of Gurus. He claims that the internet might be a good source to [...]]]></description>
			<content:encoded><![CDATA[<p>Andrew Hunt writes in <a href="http://www.amazon.de/gp/product/020161622X?ie=UTF8&amp;tag=exfuror&amp;link_code=as3&amp;camp=2514&amp;creative=9386&amp;creativeASIN=020161622X" target="_blank">Pragmatic Progammer</a> (an excellent book by the way) that you should consult a Guru on a topic where you find it difficult to find a good solution for a problem. But he admits that many companies are short of Gurus. He claims that the internet might be a good source to find Gurus.</p>
<p>I don&#8217;t think it is that easy. While there are really helpful Gurus participating in mailing lists and forums, written discussion is a problematic transport for your issues. And sometimes its not easy to select the appropriate Guru for your problem. Wouldn&#8217;t it be better to be able to talk to a Guru in person?</p>
<p>My employer <a href="http://www.codecentric.de" target="_blank">codecentric</a> now launches a new quarterly workshop series called &#8220;<a href="http://blog.codecentric.de/en/2009/03/meet-the-expertsmeet-the-experts/" target="_blank">Meet the experts</a>&#8220;. Because we are and want to continue to be among the thought leaders in Java Technology, Agile Software Development, Architecture and Performance, we decided to invite top notch Gurus to spend a day on our premises and have a full day with interesting talks and an <a href='http://en.wikipedia.org/wiki/Open_Space_Technology' target='_blank'>Open Space</a> session in the evening, which everybody can attend (well at least as long we still have seats left).</p>
<p>The first &#8220;meet the experts&#8221; will be held on 26th of June with &#8220;Performance&#8221; as it’s topic. <a href="http://www.javaspecialists.eu/">Dr. Heinz Kabutz</a>, Java Champion, and <a href="http://www.kodewerk.com/">Kirk Pepperdine</a> from javaperformancetuning.com, <a href="http://www.dynatrace.com/en/">Alois Reitbauer</a> from dynaTrace and my boss <a href="http://www.codecentric.de/de/unternehmen/team/solingen/Geschaeftsfuehrung/MirkoNovakovic/index.html">Mirko Novakovic</a> will have a talk.</p>
<p>I am really excited about that day and have high expectations. And we have the next events already in the pipe, which I hope that I am allowed to talk about soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hma-info.de/2009/03/30/want-to-ask-a-guru/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google rates blogs very high</title>
		<link>http://blog.hma-info.de/2009/03/23/google-rates-blogs-very-high/</link>
		<comments>http://blog.hma-info.de/2009/03/23/google-rates-blogs-very-high/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 11:55:40 +0000</pubDate>
		<dc:creator>Fabian</dc:creator>
				<category><![CDATA[blog]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.hma-info.de/?p=144</guid>
		<description><![CDATA[I always knew that Google somehow favours blogs, because they represent current informaton, rather than aged and decayed information found on &#8220;static&#8221; sites. But somehow I am blown away by the Google ranking a recent blog post on our corporate blog produced. I wrote about a possible addition to StringUtils. Not very elaborated, but a [...]]]></description>
			<content:encoded><![CDATA[<p>I always knew that Google somehow favours blogs, because they represent current informaton, rather than aged and decayed information found on &#8220;static&#8221; sites.</p>
<p>But somehow I am blown away by the Google ranking a recent blog post on our corporate blog produced. I wrote about a <a href="http://blog.codecentric.de/2009/02/stringutils-camelizestring/">possible addition to StringUtils</a>. Not very elaborated, but a good base to start from.</p>
<p>Today I needed to search for a method in StringUtils at a colleagues desk. We went to google and <a href="http://www.google.de/search?q=stringutils">searched for StringUtils</a>.</p>
<p>I expected the API link on top, but never ever expected the second most relevant hit to be my blog posting. That is pretty cool <img src='http://blog.hma-info.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hma-info.de/2009/03/23/google-rates-blogs-very-high/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

