tag:blogger.com,1999:blog-88083771892329971652024-03-04T21:38:38.726-08:00It's all about codeRants, code, but mainly rants about codePYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-8808377189232997165.post-52603175324639627352010-08-11T06:55:00.000-07:002010-08-11T06:55:25.558-07:00The same job over and overFor the past 10 years, I had many experiences in the IT field, within different industries (Finance, Telecoms, Retail, Governmental Agency,...). I started describing it all to a friend over a bottle of wine, and came the thought that all the applications were doing was :<br />
<br />
<ol><li>retrieving data</li>
<li>storing data</li>
<li>processing data</li>
<li>rendering/crashing data</li>
</ol>Did it many different ways, following the changes in technologies: from EJBs entities to Hibernate, from home made Web framework over JSP/ servlet to GWT, or from home made dependency injection framework to Spring, but either it is a retail product, a trade, a Telecoms router configuration or carrots those projects were just data management.<br />
<br />
So when most of the jobs require "previous Carrot {replace with your favorite domain} experience", it is basically only vocabulary, speaking the same language, something that can be learned in an intensive week, reading the " Carrot bible".<br />
<br />
<br />
<ol></ol>PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-46621267837808295922010-06-15T13:44:00.000-07:002010-06-15T13:47:33.547-07:00Working from home and remote locations communicationUsual question comes up in Scrum gatherings or on discussion boards :<br />
<br />
<b><i>How do you do Scrum with an Offshore Team ?</i></b><br />
<br />
One of the principle of Scrum is normally to have a collocated team. Communication being the main cause of failure of IT projects, off-shoring part of the team is just increasing the chances of failures.<br />
<br />
Communication is already difficult when people are located just next desk.<br />
Who never got an E-Mail from a colleague instead of walking over your desk?<br />
And what about working from home ? When the person does not answer instant messaging for half an hour ?<br />
Accepting a working from home situation is acknowledging that the communication within the team is already at risk. Next step could be to simply put the team in remote locations.<br />
<br />
But sometimes the decision is not ours, and in that case, the communication should be improved within the constraints. Any means to improve it is welcome.<br />
Phone, webcams, and occasional gatherings (trips) to ensure people trusts each other, and won't hesitate to pick up the phone to call another member if they have a question.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-29127704677932296742010-04-08T06:54:00.000-07:002010-04-08T06:57:15.666-07:00serializable, serialVersionUID and EclipseThe other day, I saw this in my current project<br />
<blockquote><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="font-size: small;">private static final long serialVersionUID = 1L</span></span>;</blockquote>Quick question around, "why are you adding the serial version UID to the class? Are you maintaining it, between different version of the class for clients of the application ? "<br />
Of course not, and I knew the answer : Eclipse throws a warning otherwise, or automatically generates one.<br />
Besides Eclipse configuration, again on an in-house when you exchange the object within the same application (lets say from application server to web server) what is the need of such ID ?<br />
<br />
From the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html">Serializable API</a><br />
<br />
<blockquote><span class="Apple-style-span" style="font-size: small;"> </span><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="font-size: small;">[...]it is </span><i><span class="Apple-style-span" style="font-size: small;">strongly recommended</span></i><span class="Apple-style-span" style="font-size: small;"> that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected </span></span><code><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="font-size: small;">InvalidClassException</span></span></code><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-style-span" style="font-size: small;">s during deserialization</span></span></blockquote><br />
First, I am wondering how many people having fun with different compiler within the same project.<br />
<br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Then, does it really happen that you have a different version between let's say a RMI client and the server. Again within the same application I am pretty sure that if you change the server code, you would like the client to have the same version.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">And finally, what happen when someone change an attribute of the class ? Well of course the serial version uid is not being changed. ( Similar to hascode/ equals implementations not being updated)</div><br />
<br />
Now let's have fun and check what would happen if I change the class with the same UID, and doing the worst case : deleting a field or renaming one. What happened ? nothing, no <code><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/InvalidClassException.html" title="class in java.io">InvalidClassException</a></code> no other exception, the object is just deserialized, with empty fields, since the previous ones have been removed.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-8273259356509673912010-03-22T15:42:00.000-07:002010-03-22T15:42:00.428-07:00Barbie geek !<span class="Apple-style-span" style="font-family: Arial; font-size: small;"><span class="Apple-style-span" style="font-size: 13px;">There is a new </span></span>Barbie doll that came up couple months ago : the computer engineer ! or should I say the Barbie Geek ?<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0MTY0guRquPcgMI0MuXOsrvt1wouW3tRSOHLkF8YAiE89j3ZjS2SvgWPqqxTFtPg2wmfnpbHhGnfP_X6Rb1AWoYvKMcGGruQ6qZbzrrl5RzlAn2RqoV4jhgbI7ffyzCFXIRoU81w2OD8/s1600-h/ComputerEngineerBarbie.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0MTY0guRquPcgMI0MuXOsrvt1wouW3tRSOHLkF8YAiE89j3ZjS2SvgWPqqxTFtPg2wmfnpbHhGnfP_X6Rb1AWoYvKMcGGruQ6qZbzrrl5RzlAn2RqoV4jhgbI7ffyzCFXIRoU81w2OD8/s320/ComputerEngineerBarbie.jpg" /></a></div><br />
Well I am not sure about the pink notebook, the binary screen is a bit Matrix-like and the T-Shirt quite ugly compared to Roy's fantastic T-Shirt collection. (RTFM Might not be appropriate though...)<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://farm2.static.flickr.com/1328/1422785621_e02c621a43.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="308" src="http://farm2.static.flickr.com/1328/1422785621_e02c621a43.jpg" width="320" /></a></div><br />
<br />
and Barbie's glasses looks like more a librarian than ones Moss have( <i><span class="Apple-style-span" style="font-size: small;">More on the great show </span></i><i><span class="Apple-style-span" style="font-size: small;"><a href="http://www.channel4.com/programmes/the-it-crowd">The It Crowd</a>)</span></i><br />
<br />
<br />
<br />
Well all that to say that IT, is definitely an area of men. But apparently, it is not always have been the case.<br />
In the 80's, there was about as many women as men in the IT field - what was 80's IT anyway? perforated cards ?. Some say that it was because computer had keyboard, and therefore linked to the type writing activity - activity linked to the female gender. I believe on the contrary, that it is more a transformation of our society that change a non gender specific activity to make it a male dominated field :towards the 90',s it then became almost exclusive to men.<br />
<br />
In the 80's, PCs became part of the house, and male fascination of the machine combined with gaming experience, led a bunch of boys naturally attracted towards the computer (including myself), wanting to know how that game worked, maybe trying to code their first game. This led them naturally to an IT career, wanting to go on and work on The Machine aka computer.<br />
<br />
Then on the computer class, that led of a difference of level : more at ease with the computer through their home hacking, that often discourage their female counterpart. It does not mean that they would be better students, even probably the contrary since they will not <a href="http://c2.com/cgi/wiki/Wiki?EmptyYourCup">empty their cup</a>.<br />
<br />
A later obstacle for a girl to pursue an IT career is the image of the IT student: a social image of someone sitting in front of a screen 24/7. Not very appealing for a girl, and neither for her parents.<br />
<br />
Women apparently have a different view of IT career, wanting to code for a real application like, for example medical research.<br />
In the meanwhile, in other scientific areas, the trend is to tend towards at least an equilibrium, alas not in IT.<br />
<br />
<br />
<i>Some links:</i><br />
<a href="http://www.womoz.org/blog/?p=13"><i>http://www.womoz.org/blog/?p=13</i></a><br />
<a href="http://people.mills.edu/spertus/Gender/gender.html"><i>http://people.mills.edu/spertus/Gender/gender.html</i></a><br />
<a href="http://www.cs.cmu.edu/afs/cs/project/gendergap/www/papers/IEEE99.html"><i>http://www.cs.cmu.edu/afs/cs/project/gendergap/www/papers/IEEE99.html</i></a><br />
<a href="http://www.cs.cmu.edu/afs/cs/project/gendergap/www/papers/sigcse97/sigcse97.html"><i>http://www.cs.cmu.edu/afs/cs/project/gendergap/www/papers/sigcse97/sigcse97.html</i></a><br />
<br />
<span class="Apple-style-span" style="font-size: small;"><i><br />
</i></span>PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-32018791854163266282010-03-17T13:40:00.000-07:002010-03-17T13:40:00.419-07:00Test Driven Reverse EngineeringI stumble upon a piece of code, trying to figure out what the code was doing.<br />
There was some<a href="http://py-code.blogspot.com/2010/02/commenting-old-code-is-useless.html"> useless comments</a>, and the method I was studying was simply too complex.<br />
To complete the picture, no unit test was available.<br />
<br />
So instead of trying to understand the code, probably missing a lot of subtle flows, I created a unit test from scratch. Doing so made me understand the behavior of the particular class.<br />
<br />
<br />
As in Test Driven Development, you are writing the behavior of the class in the unit test before implementing it.<br />
(<a href="http://www.blogger.com/%20http://martinfowler.com/articles/mocksArentStubs.html%20">Check the very good M. Fowler article</a>)<br />
In my case the code was there, so it was Test Driven Reverse Engineering.<br />
The end result was great :<br />
<ul><li>I could understand the behavior of the method</li>
<li>Having a working unit test, I could easily refactor with confidence to make the code understandable.</li>
</ul>PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-76799209516158006952010-03-16T14:55:00.000-07:002010-03-16T14:55:39.476-07:00Code generation and MDA"Wouldn't it be great if dummy code could be generated ? "<br />
<br />
Yes, a great idea that turns out not to be a great one at the end.<br />
<br />
I remember the code generation by the Rational Rose IDE. I used it back in early 2000's creating a lot of class, collaboration and sequence UML diagrams We even made some specific VBA to extrapolate state diagrams, and then generated nice classes, that were basically skeletons. So you have nice diagrams with the code matching it, and the "Architect" is happy with all this artwork.<br />
<br />
Then refactoring came in the picture, the upfront diagrams did not hold very well of course, and at the end those nice diagrams were out of sync with current code, making them quite useless, (but the "Architect" can still show off his MDA approach of the project to some gullible people).<br />
<br />
Another example : generating POJO classes from the database schema/<br />
You can use an hibernate tool to generate, from the database, the associate mapping and the corresponding POJO.<br />
First that remove the ORM from the "hibernate is an ORM persistence framework".<br />
But besides that the very annoying part is that you cannot modify the generated POJOs. Let's say that you want to modify a field, or rename it. Since you would need to modify the create a DLL script, modify the dB, generate the classes, and refresh it in your IDE, more likely you will never evolve to do simple refactoring. You can't do it directly in your IDE. That case goes actually a bit beyond simple code generation and MDA, since it is also about database evolution. <a href="http://martinfowler.com/articles/evodb.html">Great article</a> and <a href="http://www.amazon.com/Refactoring-Databases-Evolutionary-Database-Design/dp/0321293533">author book</a> about it.<br />
<br />
But back to the subject, sometimes the generated classes are missing some behavior that you want to add ( maybe a specific logic for that object - remember that you are still doing OO, or a well defined equals method often missing)... can't do it.<br />
<br />
Conclusion:<br />
<br />
You must not modify generated code, but you want to since it is part of your compilation / IDE.<br />
<br />
So now, why someone would want to generate code?<br />
Because the code is dummy and is redundant with DataBase/UML Schemas/ Existing Code<br />
<br />
2 ways I see it : <br />
- those dummy classes should not exists or should act behind the scene. If the code is generated means there is no logic inside so why even the need of the code ? Use dynamic proxies, dymaic language, anything so that it is not part of your compilation environment / IDE..<br />
- <b>the code is the design</b>. Diagrams could be used for a sketch but the current design is the code.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-85948300058422272802010-03-02T07:43:00.000-08:002010-03-02T13:12:16.816-08:00Useless JavadocJavadoc, similarly to <a href="http://py-code.blogspot.com/2010/02/commenting-old-code-is-useless.html">comments </a>, is useless in a in-house project (with no public API), and would show that the class/method is not named properly, or do more stuff that it is supposed to do.<br />
Moreover when it is automatically generated by the IDE ( namely Eclipse), you might see horrors like that :<br />
<br />
<blockquote><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"> * @param </span><span style="font-size: x-small;">bookId</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"> * @param </span><span style="font-size: x-small;">bookType</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"> * @return </span><span style="font-size: x-small;">Book </span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"> * @throws Exception</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"> */</span></div><div style="font-family: "Courier New",Courier,monospace;"><span style="font-size: x-small;"> public Book geBook(String bookId, Long bookType) throws Exception</span></div></blockquote>Great. Very useful. In that particular case, I'd rather not have any Javadoc since the method is pretty straightforward, and I don't know what kind of exception I would get.<br />
Some argue that Javadoc could be useful for boundary cases.<br />
" What the method would do if there is no book type with a given type ID ?"<br />
Well return a typed exception BookTypeNotFoundException and I am sure that you would not need any Javadoc.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-19219517552753128242010-02-25T10:32:00.000-08:002010-02-25T10:32:00.199-08:00It's possible to change it ... Code ownershipAnother day, another story...<br />
I stumble upon one piece of code, that caused an NPE.<br />
It could have obviously been avoided doing a small refactoring so that any client of the code, no matter what, would not get an NPE. Doing so would have meant to delete one method, and possibly break the compilation of any client calling that code, but instead of a runtime NPE a compilation error is way better.<br />
<br />
So I asked around, why it was not refactored :<br />
"You can change it, but it will be your responsibility if it make fails other projects"<br />
<br />
Nice.<br />
If you are not too scared of being held responsible of another project delay, this would stay in the same state, and the NPE was <i>normally </i>fixed so why bother ?<br />
Or you can do it like in cowboy style ( also known as Rambo style) doing all the work by yourself.<br />
<br />
Both cases are not ideal, and the cause was :<br />
<ul><li>there were no true Continuous Integration and <a href="http://py-code.blogspot.com/2010/01/unit-tests-vs-integration-tests.html">appropriate testing strategy</a>. As a consequence every one fear the change.</li>
<li>There is a sense of <a href="http://martinfowler.com/bliki/CodeOwnership.html">code ownership</a> or I would even say worst : a disownership of the code :" <i>It's not my code</i>"</li>
</ul>Because the next step of the Strong Code Ownership , is the No OwnerShip at all.<br />
<br />
The only way to go is obviously the <a href="http://www.extremeprogramming.org/rules/collective.html">Collective Code Ownership</a>. Doing Pair Programming helps to get that sense, and Code Review, is another way if Pair Programming is not possible.<br />
<br />
And then the "Knowledge Transfer" when someone leave the team becomes obsolete and useless.<br />
<br />
Knowledge Transfer word is a Team Smell to see that they are not working in an "Agile" way.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-75951218500314910482010-02-24T11:24:00.000-08:002010-02-24T11:59:27.541-08:00Semantics of CollectionsWhat is up with the <span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">java.util.List</span></span>?<br />
I see it so frequently used, and most of the times to return collection of elements that are not ordered.<br />
<br />
The true <a href="http://java.sun.com/docs/books/tutorial/collections/interfaces/list.html">semantic of the List</a> is <i>an ordered <a class="APILink" href="http://java.sun.com/javase/7/docs/api/java/util/Collection.html" target="_blank"><code>Collection</code></a></i><br />
Most of the case the API returns unordered elements that are not duplicated. It is then the true semantic of a java.util.Set.<br />
<br />
<br />
If the API returns an unordered, collection of possibly duplicated elements, then the returned type should be a Bag (or<a href="http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Multiset.html"> Multiset from Google Collections</a>) , and the semantic would be correct.<br />
<br />
At least, in doubt I'd rather get a <span style="font-size: x-small;"><span style="font-family: "Courier New",Courier,monospace;">java.util.</span><span style="font-family: "Courier New",Courier,monospace;">Collection </span></span>than the wrong returned type.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-23309812896953049232010-02-22T11:13:00.000-08:002010-02-22T11:13:00.286-08:00Relection equals Matcher - Easy Mock made even easier<a href="http://easymock.org/">Easymock</a> is great tool to produce mock object and do true unit testing verifying the expected behavior of your class.<br />
<br />
One issue faced times to times is while verifying the behavior it uses equals to verify objects passed as arguments are same.<br />
<br />
It should work great in most of the cases, but living in the real world most of the times equals is not defined.<br />
Of course you should define a true equals function, but sometimes you can't even do it, since you might not be able to modify the parameter.<br />
Arguably you want to test the behavior of your class, no modifying the argument itself.<br />
<br />
So here is a simple Matcher using <a href="http://commons.apache.org/lang/api/org/apache/commons/lang/builder/EqualsBuilder.html">Apache commons EqualsBuilder</a>:<br />
<blockquote><span style="font-family: "Courier New",Courier,monospace; font-size: x-small;">public class ReflectionEqualsMatcher<t> implements IArgumentMatcher<br />
{<br />
private T expected;<br />
<br />
public ReflectionEqualsMatcher(T expected)<br />
{<br />
this.expected = expected;<br />
}<br />
<br />
public static <S> S eqReflect(S toCompare)<br />
{<br />
EasyMock.reportMatcher(new ReflectionEqualsMatcher<S>(toCompare));<br />
return toCompare;<br />
}<br />
<br />
<br />
public boolean matches(Object o)<br />
{<br />
return EqualsBuilder.reflectionEquals(expected, o);<br />
}<br />
<br />
public void appendTo(StringBuffer buffer) {<br />
buffer.append("eqReflect(");<br />
buffer.append(expected.toString());<br />
buffer.append(")");<br />
<br />
}</span><s><s><br />
</s></s></blockquote>PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-53931200371808382242010-02-19T10:12:00.000-08:002010-02-19T10:12:49.451-08:00Deprecated is bad in application codeDeprecated should be forbidden and never be used when coding an application.<br />
The sole purpose of the Deprecated tag <b>ON AN API</b> is<br />
<br />
<ul><li><i>It is insecure, buggy, or highly inefficient</i></li>
<li><i>It is going away in a future release</i></li>
<li><i>It encourages bad coding practices</i></li>
</ul>( from<a href="http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/deprecation/deprecation.html"> Java's Deprecation definition</a>)<br />
<br />
When developing in-house software, when you have no outside client of your code it does not make sense at all. <br />
Most of the time it is used when the developer is afraid to delete or modified the class/ method and therefore add a deprecated annotation instead of <b>refactoring</b>.<br />
<br />
<br />
It should be part of the code smells indicators along with <a href="http://py-code.blogspot.com/2010/02/commenting-old-code-is-useless.html">commented code</a>.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-62074054841814313152010-02-15T11:16:00.000-08:002010-02-15T16:23:37.181-08:00The multiplication of TODOsTimes to times, you must have seen in the existing code something like that<br />
<span style="font-family: courier new;"></span><br />
<blockquote><span style="font-family: courier new; font-size: 85%;">// TODO Auto-generated method stub</span><span style="font-size: 85%;"><br />
</span><span style="font-family: courier new; font-size: 85%;">return null;</span></blockquote><br />
Great. Without knowing, you might call a method that is not implemented, and get a wonderful NPE.<br />
<br />
I also like the<br />
<br />
<blockquote style="font-family: courier new;"><span style="font-size: 85%;">//TODO to fix later</span></blockquote><br />
Yeah right, it will be fixed.<br />
Now the funny part. Let's go to the TODO tab in your IDE, and count the number of TODOs in that existing project: 890 for 320 files. An average of 3 TODOs per file. Wouhou !<br />
<br />
Enough of ranting.<br />
<br />
To avoid that, change your default file template, to instead of adding a TODO and return a null, throw a runtime Exception like:<br />
<br />
<blockquote style="font-family: courier new;"><span style="font-size: 85%;">throw new UnsupportedOperationException("This method is not implemented");</span></blockquote><br />
or even better use an explicit <a href="http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/NotImplementedException.html">NotImplementedException</a>:<br />
<pre><blockquote style="font-family: courier new;">throw new
org.apache.commons.lang.NotImplementedException("TODO");</blockquote></pre>That is first step. Now the only way to enforce that the <span style="font-weight: bold;">TO DO</span> will<span style="font-weight: bold;"> BE DONE</span>, is to create the / modify the test calling that piece of code. It will fail and force you to act.<br />
<br />
Concerning the Fix Later example, I would recommand the use of a TODO to issue tracker converter, so that item would be part of the backlog, prioritized, and eventually done in some future iterations.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-29755268844133919392010-02-12T14:43:00.000-08:002010-02-17T10:48:38.648-08:00Commenting old code is uselessWhy do people comment out old code ?<br />
<br />
There is your favorite <span class="blsp-spelling-error" id="SPELLING_ERROR_0">SCM</span> for tracking the changes that happened in the particular piece of code.<br />
So why ?<br />
Because people are afraid of the change, afraid of breaking something.<br />
They comment out the old code, so that if something happened during the Big Testing Phase, they could revert.<br />
<br />
Commented code means no code coverage, <span class="blsp-spelling-error" id="SPELLING_ERROR_1">i.e.</span> no unit test.<br />
Bad.<br />
Commented code should be added as one of the code quality indicator (or technical debt management) like <a href="http://sonar.codehaus.org/">Sonar</a>, because it smells like something not right is going on.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-58515709532470478832010-02-11T12:34:00.000-08:002010-02-11T14:43:34.950-08:00Some quotes on Unit Testing<p><b><a href="http://java.sun.com/developer/technicalArticles/Interviews/community/kabutz_qa.html">From an old article of Heinz <span class="blsp-spelling-error" id="SPELLING_ERROR_0">Kabutz</span> </a><br /></b></p><p><b></b></p><blockquote><p><b><span class="blsp-spelling-error" id="SPELLING_ERROR_1">JSC</span>:</b> What are some of the big mistakes that even experienced Java developers make?</p><p><b><span class="blsp-spelling-error" id="SPELLING_ERROR_2">Kabutz</span>:</b> Not unit testing. At conferences, I ask, "How many of you have unit tests for your code?" Almost no one raises their hands -- and these are experienced professionals. While programmers start projects believing they should have unit tests, they often don't take the time to write them up front, and they end up spending time fixing bugs. We should always perform unit tests.</p> <p>A good unit test will not only flush out problems before you get close to production, but it will help regression test your system as well. I see it over and over -- very few companies have the discipline to enforce the use of unit tests.</p></blockquote><p></p><p><a style="font-weight: bold;" href="http://java.sun.com/developer/technicalArticles/Interviews/bloch_effective_08_qa.html">And a following interview of Joshua Bloch</a><br /></p><p><span style="font-weight: bold;"></span></p><blockquote><p><span style="font-weight: bold;"><span class="blsp-spelling-error" id="SPELLING_ERROR_3">JSC</span>: </span><a href="http://java.sun.com/developer/technicalArticles/Interviews/community/kabutz_qa.html">Java Champion Dr. Heinz <span class="blsp-spelling-error" id="SPELLING_ERROR_4">Kabutz</span></a> finds that failure to unit test is a big problem among Java developers. He reports, "At conferences, I ask, 'How many of you have unit tests for your code?' Almost no one raises their hands -- and these are experienced professionals." Your reaction?</p> <p><span style="font-weight: bold;">Bloch: </span>I'm really sorry to hear it. Unit tests are essential! If you don't have them, you don't know whether your code works. Having a good set of unit tests gives you much more confidence that your code works in the first place and that you don't introduce bugs as you maintain it. Inevitably, you will introduce bugs, but your unit tests will often let you find the bugs as soon as you introduce them, so you can fix them before they cause any damage.</p></blockquote><p></p><p><span class="blsp-spelling-error" id="SPELLING_ERROR_5">Arggh</span>, this was 2007.<br /></p><p>3 years later I still see project /organization that does not believe in unit tests, and where I hear " We don't have the bandwidth to do unit test".</p><p>Prehistoric software development. Upfront tests, TDD, anyone ?<br /></p>PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-71950844283233575442010-02-10T08:18:00.000-08:002010-02-10T11:28:35.200-08:00Sans maƮtrise, la puissance n'est rienPardon my French : "<em>Power</em> is <em>nothing without control</em>" was a famous commercial catch phrase from a tire company.<br /><br />It made me think of a project and agility methodologies.<br />How is that one translated in the IT world :<br />"<span style="font-style: italic;">Latest technologies is nothing without control of the technical debt.</span>"<br />Not very catchy but so true.<br /><br />One example:<br />On this new project, designed to replace legacy systems, you take the latest technology stack, add some very knowledgeable developers.<br />But without using any XP principle or any dogmatic approach: <a href="http://py-code.blogspot.com/2010/01/unit-tests-vs-integration-tests.html">no true unit tests</a>, no true continuous integration , no knowledge sharing but in big lengthy meetings ( of course no pair programming or code review , uh what is that?).<br /><br />Shake it and let it marinated for 2 years. Open it and you'll smell a very strong technical debt.<br /><br />Nothing can be changed, because of the fear of breaking something .<br />Not mentioning the lost knowledge of why it was designed like that.<br /><br />Forecast result : the developers play the job security becoming all Bob the developer's types, and your new top notch application is now really a mammoth application.<br /><br />Back to Square one. Same player play again.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-90656054014911866502010-01-28T15:49:00.000-08:002010-01-28T16:01:56.474-08:00Unit Tests vs Integration TestsLet's make it quick and clear :<br /><br />If a test is not executed on a regular basis, through the build process or continuous integration it is therefore not maintained and becomes a useless test. Maven users would recognize the over-used -DskipTests=true. You can delete it right away, because chances are that within no time it will fail.<br /><br />Why would you not want to execute the test all the time ? Simply because what was thought to be a unit test is clearly not.<br /><br />Then how to determine if a test is a Unit Test or an Integration Test ?<br /><br /><ul><li>If a test needs data in the Database , it is an integration test</li><li>If a test needs a Spring configuration, it is an integration test</li><li>If a test needs a server to be up (Jetty or application server) it is an integration test</li><li>If a test is slow it is probably not a unit test.</li><li>...<br /></li></ul>well you get the idea.<br /><br />A unit test is testing one and only one class.<br /><br />It does not mean integration test are bad, but they need to be executed in a different cycle from unit test: for example once the build is deployed on a server, etc...PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com1tag:blogger.com,1999:blog-8808377189232997165.post-87487360077230669772009-08-26T09:19:00.000-07:002009-08-26T10:23:07.837-07:00Reporting DatabaseSome thoughts about Domain driven Design, SOA and Reporting database.<br />From Martin Fowler:<br /><ul><li><a href="http://martinfowler.com/bliki/ReportingDatabase.html">Reporting Database</a></li><li><a href="http://www.martinfowler.com/bliki/EagerReadDerivation.html">Eager Read Derivation</a><br /></li></ul>And finally a really interesting one about the trade off between stale data and performance: <a href="http://www.allthingsdistributed.com/2008/12/eventually_consistent.html">Eventually Consistent</a>.<br /><br /><span style="font-size:100%;">Finally let the master talk (</span><span style="font-size:100%;">Martin Fowler on Domain driven Design Community site):</span><br /><blockquote><span style="font-size:85%;">I'm a growing fan of a separate reporting database. This can reduce the load of complex queries on the operational database, provide a denormalized schema that makes it easier to write queries, and acts as an encapsulation of the operational schema. The downside is that it will lag the operational database to some degree, but often people are quite happy with yesterday's data rather than todays and messaging systems can be used to keep in sync within minutes if you need to.</span></blockquote>It says it all !<a href="http://www.allthingsdistributed.com/2008/12/eventually_consistent.html"><br /></a>PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0tag:blogger.com,1999:blog-8808377189232997165.post-1217460412549378582007-12-12T08:07:00.000-08:002007-12-12T10:19:21.037-08:00Layout in CSSDoing my own design using div and float was really painfull - not even talking about the table time. You often need header, menu or tabs, content, footer,etc... and also have to take into consideration specific browser interpretation (box model and so on).<br /><br />Discovering in the <a href="http://developer.yahoo.com/yui/grids/">Yahoo! UI library a Grid CSS</a> component, I just decided to give it a try.<br />Great documentation, quite simple use, in half an hour I have done a simple layout (header, left menu, main content divided into 3 different blocks, right content, and footer ). Not to mention that it is same rendering for different browsers. Everything I needed!<br /><br />There are three main components:<br /><ul><li>the document : defines the width of the layout</li><li>templates: ready to use layouts</li><li>grids: to make more complicated and structured components.<br /></li></ul>Combining all three components should meet the requirements of most web pages layout.<br /><br />What is just missing is to have a really simple way to add custom grids (like 40% + 20% + 30%)<br /><br />If you want to play with it just test <a href="http://developer.yahoo.com/yui/grids/builder/">the builder</a>.PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com1tag:blogger.com,1999:blog-8808377189232997165.post-86398103266318977072007-11-28T11:14:00.000-08:002010-02-11T12:34:12.106-08:00Generating a thumbnail image of a PDF documentLike it exists for HTML pages, I wanted to created thumbnail (preview) image of a pdf document, same as I can get on a Wind*ws Explorer for example.<br />On the web, given the time it takes to open a PDF document in the Reader, better know before what it looks like, so I don't have to download wrong one.<br /><br />So I used the <a href="http://www.pdfbox.org/">PDF Box library</a>. It can convert easily a PDF document to an image.<br /><br />First need to load the document, get the first page of the document, and convert it to an image:<br /><br /><span style="font-size:85%;"><span style="font-family:courier new;"></span><span style="font-family:courier new;"></span></span><blockquote><span style="font-size:85%;"><span style="font-family:courier new;"> // Converting first Page to an image</span><br /><span style="font-family:courier new;"> url = new URL(documentPath);</span><br /><span style="font-family:courier new;"> document = PDDocument.load(url);</span><br /><span style="font-family:courier new;"> PDDocumentCatalog catalog = document.getDocumentCatalog();</span><br /><span style="font-family:courier new;"> List allPages = catalog.getAllPages();</span><br /><span style="font-family:courier new;"> if (null == allPages || (allPages.size() == 0)) {</span><br /><span style="font-family:courier new;"> throw new Exception("The document is Empty");</span><br /><span style="font-family:courier new;"> }</span><br /><span style="font-family:courier new;"> PDPage page = (PDPage) allPages.get(0);</span><br /><span style="font-family:courier new;"> BufferedImage image = page.convertToImage();<br /></span></span></blockquote>Then just write the image.<br /><br />All this can be done calling directly the PDFToImage Main class passing the right arguments (Start page and end page =1).<br /><br />I tried to reduce the size of the image on a second step (to make it small like a thumbnail) using the code from <a href="http://www.informit.com/guides/printerfriendly.aspx?g=java&seqNum=167&rl=1">here</a>, but it often gets to a really bad quality. On web page , better simply size the image.<br /><br />Also, the underlying code is <a href="http://www.pdfbox.org/commandlineutilities/PDFToImage.html">"beta quality</a>". So shouldn't expect too much from it. ( I tried random PDF from the net, and some of them didn't work. Basically if it standard text it should work.)<br /><br /><blockquote></blockquote>PYhttp://www.blogger.com/profile/12395669177471243564noreply@blogger.com0