<?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>Sadek Drobi's Blog &#187; Spring Framework</title>
	<atom:link href="http://sadekdrobi.com/category/spring-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://sadekdrobi.com</link>
	<description>Sadek Drobi</description>
	<lastBuildDate>Tue, 08 Mar 2011 22:56:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Who told Java Checked Exceptions were a Bad Idea?</title>
		<link>http://sadekdrobi.com/2009/01/04/who-told-java-checked-exceptions-were-a-bad-idea/</link>
		<comments>http://sadekdrobi.com/2009/01/04/who-told-java-checked-exceptions-were-a-bad-idea/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 00:50:22 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[DOTNET]]></category>
		<category><![CDATA[Decipline]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Framework]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/01/04/who-told-java-checked-exceptions-were-a-bad-idea/</guid>
		<description><![CDATA[
One of the few things that lack seriously, IMO, in C# is the power of Java checked exceptions. In Java world? things happen weirdly. Maybe it is a result of crowd intelligence and a bad side effect of open source. Often, people in J2EE world tend to believe the opposite. Anyway you see the effect [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/01/dsc-02851.jpg"><img style="border-right: 0px; border-top: 0px; margin: 0px 15px 10px 0px; border-left: 0px; border-bottom: 0px" height="315" alt="DSC_0285" src="http://sadekdrobi.com/wp-content/uploads/2009/01/dsc-0285-thumb1.jpg" width="459" align="left" border="0"></a>
<p>One of the few things that lack seriously, IMO, in C# is the power of Java checked exceptions. In Java world? things happen weirdly. Maybe it is a result of <a href="http://en.wikipedia.org/wiki/The_Wisdom_of_Crowds#Failures_of_crowd_intelligence">crowd intelligence</a> and a bad side effect of open source. Often, people in J2EE world tend to believe the opposite. Anyway you see the effect in most preferred frameworks (such as today&#8217;s popular ORMs and Containers) of wrapping checked Java exceptions and rethrowing them as runtime ones. </p>
<p><span id="more-569"></span></p>
<p>I guess offering runtime exceptions together with compile time ones did a hole in the Java type system, but this hole was left to discipline, in a way of giving the tools and letting smart enterprise programmers decide for the right tool for the job. Things turned to happen differently in the enterprise world.&nbsp; Programmers abused of this freedom of choice and mainstream frameworks designers decided to dismiss and bury one of the most interesting features of the Java type system.</p>
<p>Why do I like Java checked exceptions? Well simply because it saves me from surprises. And I tend not to like surprises much!</p>
<p>The funny thing is that, in my experience, it is mostly architects that dismiss Java checked exceptions whereas Compile time exceptions are a very good asset for cleaner and bug free architecture.</p>
<p>I just take a look at a &#8220;standard&#8221; DAO method that gets an entity</p>
<p>Customer getCustomer(CustomerId id);</p>
<p>This method lies! what if there is no connection? what if the Id is incorrect? The signature of the methods gives quite a promise that under all circumstances it will returns a Customer. Now for any architecture this is bad. It used to be better before some popular frameworks decided to completely omit it! Before? well I used to control my architecture better!</p>
<p>Before these &#8220;good practices&#8221; become mainstream, imposed in mainstream frameworks, It used to be often more predictable the return type a method has. For my example, the signature would tell me that the method will either return a customer OR throws a &#8220;Dao Exception&#8221;.</p>
<p>Customer getCustomer(CustomerId id) throws DaoException;</p>
<p>No surprise. Now when I use this method, I will certainly need to handle the case when the method will return something else than a Customer. Now of course, a Java &#8220;enterprise developer&#8221; could do one of to things:</p>
<p>1- Out of laziness or incompetence, keep rethrowing data access exceptions up until you&#8217;ll have to deal with it up in the GUI logic (where handling an infrastructure error does not often belong)</p>
<p>This often sounds for me the main argument for dismissing Java Compile Time Exceptions claiming that it is a &#8220;code boilerplate&#8221;. The thing is that you&#8217;ll have to deal with these exceptions once even when you turn them into runtime. The fact of wrapping them into runtime does not eliminate them (even if I wish it did). But having them as compile time will make easy to spot where a &#8220;bad&#8221; developer did not handle the exception correctly simply by following the signature and type system. Then the solution will be to wrap them into more business friendly, context meaningful Compile Time Exceptions that need to be handled. This way the contract communicated better the result of executing a piece of logic.</p>
<p>This turns to be as useful for &#8220;void&#8221; return type methods. With Compile Time Exception a method can simply communicate the fact that it will either return &#8220;void&#8221; or will throw an exception to be handled.</p>
<p>2- Out of laziness or incompetence, frustrated developers will start &#8220;catch&#8221;ing checked exception without rethrowing them.</p>
<p>This one is a result of the hole in the type system that is left intentionally to leave some place for flexibility relying on discipline. Nevertheless, and before the big favor of generous frameworks I mentioned earlier, this turned out to be an easy problem to spot. Most IDEs and code analyses tools can find easily empty catch clauses and warn me about them.</p>
<p>&nbsp;</p>
<p>I often get surprised of the limited use of Java language wealth in enterprise J2EE applications!</p>
<p>Good thing: C# and .Net are introducing checked exceptions together with other DbC stuff (like non null objects) in the next release. Sad thing: Java has Compile Time Exceptions since version 1, open source chose to unvalue them!</p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/01/04/who-told-java-checked-exceptions-were-a-bad-idea/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>I just do not get it! Why use Spring Beans?</title>
		<link>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/</link>
		<comments>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 15:14:44 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Spring Framework]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/</guid>
		<description><![CDATA[ 
In short, I do believe that Spring framework forced you for a long time to use a subset of Java, a subset of frameworks you use, and has been implicitly very intrusive on all the frameworks that support it. It constrains innovation and limit choices. And more!

Unfortunately I would not be able to list [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2008/12/photo1.jpg"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="photo" src="http://sadekdrobi.com/wp-content/uploads/2008/12/photo-thumb1.jpg" width="260" height="179" /></a> </p>
<p>In short, I do believe that Spring framework forced you for a long time to use a subset of Java, a subset of frameworks you use, and has been implicitly very intrusive on all the frameworks that support it. It constrains innovation and limit choices. And more!</p>
<p><span id="more-566"></span></p>
<p>Unfortunately I would not be able to list in this post all the arguments I have because of lack of time. I would rather provide few examples that shows why the Spring culture is unacceptable for me. Of course you can reply saying that Spring will support this, or is supporting this starting with version x. Well I am afraid I don&#8217;t care. Spring existed for a long time now, and my judgement is based on a long history. Besides what I am targeting is the culture of the framework.</p>
<p>First of all, if you want to use Spring Beans you need to believe in magic. Don&#8217;t agree?</p>
<p>class MyServiceClass {   <br />&#160; private IMyDao myDao;    <br />&#160; // Other stuff goes here.    <br />}</p>
<p>this field &quot;myDao&quot; is never initialized, not by any constructor and it is private. But if you believe in magic, then you can use it. Because you know what? There is a wizard config file that you can find if you search enough in your project that will &quot;inject&quot; it. What?!!</p>
<p>First of all this solution violates member visibility rules in Java. But ignoring that, this results in a practice or a habit to ignore a never initialized field believing in magic! A framework that offers and advocates such a violating is not worth even trying IMHO!</p>
<p>Now the suggested solution is to write a setter for this field that then will be used by Spring, but this changes nothing as anyway you will either make it public (allowing any public user of your API to set you DAO!) or put it back private and back to the never initialized field! Did I mention &quot;final&quot; yet? :)</p>
<p>Spring claims that it is not intrusive. What? Now imagine that you remove Spring from your dependencies list, your application is no more useful and you suddenly get null pointer exception everywhere my friend! Who will inject the private field? or a private setter? This claim is ridiculous!</p>
<p>Now did it happen to you to forget to declare or mistype your beans in your config? What happens? Runtime exception! What? I thought Java applications are statically typed!</p>
<p>Now I can hear you, use annotations! Annotations solves your problem! Well I am afraid not. Annotations like @Required or @AutoWired is just like begging the user not delete the field or property, and it is not mandatory and not forced by any checker. Remember, I am talking culture here&#8230;</p>
<p>Now if you are a defender of injection using constructors, then I believe you got something right and most probably you reject most of the hacks I mentioned above (Including setters based injection, private field injection,&#160; aspects based injection (in short 80% of what Spring Beans mainly offers and actually does)). But then, you turned anyway your architecture dependency into dynamic, never checked and its composition specified in desperate XML files! Think of code navigability, and software flow and dependencies that you can not trace without the help of a debugger using this approach.</p>
<p>Oh, what about JavaConfig. Well yeah, <a href="http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12">I do not need Spring to do that</a>! &quot;new&quot;, you remember the keyword &quot;new&quot;? yeah OOP, new, instances. That is Java programming. Trust me &quot;new&quot; is no evil, and guess what, you need no dependencies to any framework to resolve your dependencies in a statically checked, navigable, readable, simple, clear, elegant, concise, safe and beautiful way!</p>
<p>Last thing for now, you need to learn Spring-FU to use any, any framework that wasn&#8217;t designed specifically for use with Spring and yet you may not succeed (though framework designers are forced to be distracted by Spring design when defining their architecture, for examples see Restlet and Jersey) ! That reminds me of something&#8230;</p>
<p>YAGNI!</p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2008/12/30/i-just-do-not-get-it-why-use-spring-beans/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
	</channel>
</rss>

