“Before you speak, listen. Before you write, think. Before you spend, earn. Before you invest, investigate. Before you criticize, wait. Before you pray, forgive. Before you quit, try. Before you retire, save. Before you die, give.”

Wednesday, January 5, 2011

Seam Framework or the JEE answer to Ruby on Rails

After playing with Ruby on Rails for almost a month (and coding my weight management application) I can honestly say I have found my love for coding again. Mostly because of the instant feedback effect.
As I kept reading various resources on RoR I found one issue with it. It does not support XA transactions. That is if you are using an application that has to synchronize 2 databases in a transaction RoR can't help you.
Of course RoR is just a framework and Ruby standards are not as good as Java ones so there is no JTA (Java Transaction Api) equivalent in Ruby/RoR hence you are on your own. So writing enterprise stuff in Ruby will just have to wait for a while.
That did not stop me from spending the New Year's eve and 2 days after just coding a RoR application between drinking ,eating and celebrating
Now recently I have decided to study Seam Framework as the JEE answer to Java. I have received Dan Allen's "Seam in Action" book and I am trying to make sense of it.
Seam's fantastic points
1)Conversations
2)Bijection
3)Handling JSF actions on initial Request (or get)
4) Using a conversation scoped persistence manager should prevent all the LazyInitializationExceptions I kept seeing in the past 2000 days of JEE programming (not that many but you understand ..)
5)Integration with Drools , jBPM-of course best to be used in a JEE container.
A lot more small stuff that makes your life easy.
Unfortunately I can't help thinking that 2 heavy weight containers (JSF and EJB3) are integrated in a bigger container. The problem is whether Seam provides a good abstraction or a leaky one.

Of couse while reading Dan Allen's book I found that at least in the 2 initial chapters he kept trying to offset Rails .. unfortunately hot deploy is not complete in JBoss/Seam .
There are several severe limitations
  • you need to be using a war project (no EJB's)
  • you need to have a tag specifying debug =true
  • you need to configure the ide to do the explode on edit thing(or type seam explode)
Even then you would not be allowed to do Entity classes changes and changes to Session Beans without redeploying.
So it is true that it helps but even Dan specified in a Seam Framework post that incremental hot deploy in Seam is a bit of a hack .
What I did enjoy was doing integration testing with Seam , TestNG and Embedded JBoss these shoud alleviate the pain of repeated build/deploy/test cycles I mentioned. Nevertheless integration tests are always slower than basic unit tests.
I can run 54 pure unit tests on my machine in 2 seconds but just 4 integration tests take 16 seconds.
For the record my machine is now upgraded : Core i7 860 , 8GB RAM (Corsair) ,1TB HDD so I guess we are talking top of the line performance.

As a side notes I found that doing RoR development using JRuby and Webrick makes testing in the browser faster then integration testing in controllers (yap JVM start times to the rescue) so doing TDD with JRuby is not easy either.Nevertheless they take 2.8 seconds to execute + 10 seconds JVM startup time (that's why Java will never be used for OS development :) ).


Anyway if you need to stick to the JEE world or need distributed transactions go for Seam , if you are confident you won't need distributed transactions you cand certainly go for Ruby/RoR.

My objectives for the year ? Just get to 100 kg and stay there.
What I need to have this :
  1. Diet and calorie counting
  2. fitness performed regularly.
I even wrote my own RoR code to track this (not yet business ready but functional)
Oh btw : Happy new Year.

Sunday, December 5, 2010

Ruby on Rails or the beauty of instant feedback

I was trying to write a GWT application that would help track the weight , calories and training for a person and make it run in the Google App Engine. Unfortunately I was always blocked by some configuration issues which made me delay it (being tired after work does not help).
So Saturday I thought maybe I should give this Ruby On Rails a try since I am into ruby a lot lately.
Using Netbeans I started with the sample "Depot application" and started to understand RoR a week ago.
After watching this video of DHH presenting Ruby on Rails and the concept of scaffolding I was able to get started in no time .
Today (less than 24 h since I started) I have a working weight tracking application which needs some improvements .. but it is working.
Being able to avoid the compile/deploy/test cycle and replacing it with just "test" was a huge benefit for me.
Instant feedback is really enlightening and reminds me of the reasons I actually loved PHP years ago. As a beginner programmer I wrote "working" PHP code that was horrible with no MVC separation .. or layering. It was a shame but it worked.
Right now when looking at Rails I see somehow what PHP should have been like ages ago .. the benefits of PHP and the engineering I used to see only in J2EE frameworks. And best of all I did not have to write one SQL line .. this is fantastic for me :).

Yes I know a Jedi JEE programmer must be able to just figure out things such that a single deploy will be enough for all fixes. Well it usually ain't the case and I find myself waiting for the machine to deploy only to find other things to fix .. which I thought were fixed and the human brain can only keep track of 7 things at a time .. add to this the typical open plan office space , personal concerns or other thoughts and you get minimal productivity ..
I realize running the projects inside Netbeans and/or Eclipse allows sometimes the automatic redeployment but even that takes time.
We have MVC , Active Record pattern for ORM , automatically generated unit-tests, integration-tests, functional tests , the famous convention over configuration rule , clean layers (except the service layer that for now I do not miss).
As I read in Bruce Eckel's "Thinking in Python" (for a while I wanted to choose between Ruby and Python) it's not the static type checking or compiling that brings so many benefits it's the use of unit-tests.
Hence I strongly believe well written Ruby on Rails applications can be equal or equivalent to J2EE applications for the same purpose it the test driven development technique is used. Moreover I wrote way too much Java to know that not using unit tests and a technology like EJB2.0 can lead to almost 0 productivity (unit tests seem to help as you do not have to start the container just for a small function you just wrote).
Yes the same can be said about PHP .. you can write horrible code in any language , but Ruby is the new high level language of the day and I tend to go with the flow.
Of course being an Java developer /architect wanna be I realize my 10 years experience in Java are going down the drain with this Ruby on Rails stuff but if I can get things done while having fun .. why not ?
Of course if I have to develop something that has to be distributed and integrate with other tools I will still go for Java but some smart guy invented JRuby meaning I could be running Ruby in a JEE container in order to do a slow migration.
Of course making a JEE application go through the build deploy cycle without issues would be nice , I just can't see how.
This link shows how much time we are loosing with deployment and 2.5 weeks a year looks like a lot considering just the salary of the average developer.

Sunday, October 24, 2010

GWT compiling performance

Just a reminder for myself of the required performance to compile a GWT -GAE Application.
This is on my Core i7 860 machine with only 2GB of RAM (for now).Some people might notice I am running on 1GB of swap so let's just say that this is the blocking issue for now. Still it's a core i7 running at full power for a while just to do this processing. I wonder if people developing with GWT do this kind of work on Core i7 980 processors (extreme hexa-cores processors).















I have created a Proof of Concept online for a Java application that I want to test but for now it is not quite ready to go public.
Google is number one for offering some things I could not find online
1) Affordable Java web hosting - this one is free for small loads
2) The GWT toolkit saving me from writing Javascript (I don't like Javascript very much).
3) The AI driven car which they are working on (but on this on a different article)-

Still the approach is causing me a lot of headache. You need to be able to write Java code which is then transformed into Javascript and then the whole package is transformed into a war and deployed on the server.
My other home hobby project is created as an ear and it only takes 40 seconds to compile , run unit tests and create an ear.
This one ( a very stupid GWT hello world) took me as much as 2 minutes to do the same thing in a normal non -blocking mode(no other consuming applications) 1 minute 30 seconds.
I need to look into it but I guess generating JavaScript is not quite instantaneous.
The benefit of writing Java code AND unit-tests is clear. You know exactly what goes wrong and why it goes wrong (if you are a decent Java programmer).


Nevertheless I think that adding another abstraction layer on top of JavaScript might cause some impossible to fix bugs ( without JavaScript knowledge).
It took me a lot to just compile classes and make GWT compile a different set of classes .. because GWT classes do not mix with backend classes such as Hibernate or JPA classes so you need to specify that accordingly.

Will it work ? Well I will let you know soon enough as I am preparing my application.

Later Edit : After a week fixing a RichFaces bug involving extending both RichFaces and Facelets frameworks (just to handle a ViewExpiredException and to make IE7 handle a redirect ) I have the feeling that GWT might be a better alternative then the JSF and Javascript combination at least in the short run.
Of course there is always Flex which is a bit safer but involves also learning anew language and buying the FlexBuilder.

Friday, September 17, 2010

The challenge

Here I am facing a new challenge : Getting admitted into the masters program at the university.
It's a Master in Artificial Intelligence which is a field I am interested in but it is not very easy to get in.
You have to pass an exam containing subjects from
1) Algorithms analysis and design -using the famous CLRS book ("Introduction to Algorithms")
2) Databases
3) Object oriented programming - mainly SCJP like questions
4) Subject of choice from 4 other fields - I chose AI here and the AIMA book.

I started reading the AIMA book and the CLRS book but it looks like the mathemathics involved is overwhelming ... I never was a math genius.

This situation raised a lot of mental blocks for me and considering that Monday I have to take the exam it looks like I am heading for a complete disaster.
But it never hurts to try. I need to get admitted on a 1 1/2 candidates/position situation , all things considered it is a lot better then some interviews I attended .

Also I realize that although I have a B.Sc. in Computer Science and Electrjcal Engineering I never used a lot of the knowledge from the university .. maybe this is a industry problem , maybe I am trying to learn astronomy when I am they guy that fixes telescopes.
Writing good programs involves knowing things like complexity , knowing if a problem is NP-complete and stuff like that .. but most of the times you can just call an external library that already figured this stuff for you .. so you don't have to.
Just for fun I wrote some Java code that performs a merge sort and another performing insertion sort and tried to enter 10.000.000 long array.
The difference was amazing. Even on my core I7 860 processor using it's 8 cores (4 physical and HT) it took 1252 seconds to do the insertion sort and about 159 seconds for the merge sort.
On the other hand most algorithms offered by programming languages are fast enough so I rarely was in a position where I needed to evaluate the algorithms.
So a part of me is wondering : shouldn't I worry about more important stuff then about this albeit important ,pretty much useless in real world enterprise development , but the part of me willling to learn new stuff supports this idea.
Now I need to get back to work and hopefully not be the last on the exam.
LE : If I fail I have the "excuse" that I studied for my SCEA certification and had not time for this exam , and I did not study algorithms design at the university .. and I am lazy :).
LLE : As expected I got a bad mark (6.91) qualifying me for the "tax" part of Artificial Intelligence. Since I am not eager to pay 1100 Euro to study AI I guess I can wait another year in which I can sort other issues in my life.
Anyway my view is that the exam was totally doable and thinking positive would have helped. No harm done anyway.

Thursday, September 2, 2010

Automating functional testing

So here is the drill : You need to wear the testing hat and verify the bugs .
You need to test a huge application and see if some bugs are reproduced.
Typically each bug requires about 3 page navigation and 20 clicks and you need to be able to reproduce it without issues and show it to a co-worker.
My attention span in the open plan office is not that big .. I always click some button I shouldn't have clicked and then have to start all over. Anyway bugs need to be fixed and issues need to be found. You also need to find new bugs and regressions.
Here is the solution: Automate functional testing.
What I used so far and can fully recommend:
1)Selenium IDE - first step is to record the tests and generate the required Java/Ruby Code
2) Use Selenium Java (or Ruby) driver and write the tests in the IDE
3) Start Selenium Server.
4) Run Selenium code from the IDE ( or a C.I. machine like Hudson,CruiseControl)

Here is how I test a simple login , search and logout(Ruby version) :

require "test/unit"
require "rubygems"
gem "selenium-client"
require "selenium/client"

class WorldFredomTest < verification_errors =" []" selenium =" Selenium::Client::Driver.new" host =""> "localhost",
:port => 4444,
:browser => "*chrome",
:url => "http://localhost:8080/",
:timeout_in_second => 60

@selenium.start_new_browser_session
end

def teardown
@selenium.close_current_browser_session
assert_equal [], @verification_errors
end

def test_login
@selenium.set_speed"2000"
@selenium.open "/WorldFreedom-war/mainPanel.htm"
@selenium.type "j_username","mihai"
@selenium.type "j_password","freewilly"

@selenium.click "login_button"
@selenium.wait_for_page_to_load "5000"


@selenium.click "searchFreedomsTab_lbl"
@selenium.click "j_id102:searchButton"
@selenium.wait_for_page_to_load "5000"
@selenium.click "logout"

end
end

Of course no warranty is provided for the code above. It just works on my PC.
Coding the functional tests should be done by a functional testing team (no connection to the actual development team) and bugs should be reproduced by means of running these tests.
Of course in an agile environment these tests are also used as acceptance tests.
Setting the speed of the tests is also good since making them run too fast will reveal performance problems with the application.

There is a catch here : No test will ever catch a cosmetic bug , a colour which is wrongly used or a table that is creating a horizontal scrollbar. You need a human for that .. and that human tester will be required for the foreseeable future.

Wednesday, August 18, 2010

Sun Certified Enterprise Architect

Today I received a mail from Sun (well Oracle) stating that I have passed the architect certification .. one of my objectives for the year.
What does this mean ? It means I have passed the highest Sun Java certification enabling me to actually design and implement a solution for an actual business problem. It is an external confirmation of my worth as a professional and it makes me confident I can use my UML and design skills at my job.
It has been a lengthy process starting from I could say December 2006 (officially in October 2007 with part 1) and really ending in July 2010 (on 23rd) with the submission of the assignment.
How I took the parts
In October 2007 while working in France I took part I - easiest of all
May 2010 I received the assignment and started working on it.
Two months and a lot of work latter I submitted the assignment .
August 18th - received email from Sun confirming I have passed.

I was really busy and tried to stay committed to the goal while maintaining a busy work schedule and other social obligations. I think SCEA is a worthy goal for people with less than 10 years experience.

As I posted on the blog I was really motivated to do it as I had invested some money into it.
Now I am working on a GWT and Java application which will be running in the Google App Engine and which will be available to plenty of users (me especially). But that is for another post.

My Ruby love -affair is still on and on weekends using my wife's laptop I do some coding in Ruby also but for now I can't find anything relevant in the job market - not even project-based.
I had to cancel the master program (did not want to get into debt to finance it) but otherwise I am doing pretty good.

Tuesday, August 10, 2010

The failure

Ever had the feeling you know precisely what needs to be done and yet for an unknown reason you fail to do it ?
This is not about the failure of my SCEA certification .. I am still waiting for the results from Sun after having submitted it on July 23rd(although I might fail the cert too) , it's about failure to keep things over control.
The last months where a continuous and accelerated degradation of my life .. in more ways then I am willing to admit.
Although I am quite confident that a GTD style needs to be used and applied at work and in personal life, that diet food is better for me,that TV time is useless time e and that concentration on work things is mandatory I cannot do the right stuff.
I found myself procrastinating and browsing car forums despite my commitment to being car-lite or even car free.
I know debt is bad but I just applied for a credit card .. it is really unbelievable.
Here I am at 2.00 AM writing on the blog after not being able to sleep for 3h.
I blame the high daily temperatures for this (35-37 Celsius ) behaviour.
My mind is obsessed with 2 idiotic things : buying a laptop (and making the purchase look necessary) and controlling expenses ( I have been an avid reader of GRS)
Since working for one employer is a risky endeavours I am trying to find other income sources which can finance say a laptop purchase a month at least.So far not very successful with this issue.
I am looking at
1) Freelancing - slim chances in J2EE field
2) Google Android development - requires a 500 Euro investment in Android phone and offers
little profit guarantees
3) Doing something completely unrelated (driving a taxi maybe ? ).


In other news :
My Decathlon Triban Trail 7(trekking bike) is officially 3 years old .. and has only 3000 km on it .. I need to increase the mileage on it.
Today after 3 months I managed to see my weight going under 100 kg again - 99.9 kg.
My wife agreed to let me buy a road bike when I reach 90 kg so I must not give up.
Last but not least after spending a lot of money in our short holiday in Amsterdam we got to see that fascinating city. I got to walk and bike and .. yes smoke pot in Amsterdam :). I wish I could write more but all I can say after 4 days is that Amsterdam really is the city of freedom and it is fantastic for tourists a great place to spend some of your holiday.
On the other hand I realised that although it is a bike paradise ( you are king of the road with your bike there) it was not designed to be a bike paradise (neither was most of Holland) , the bike simply imposed as the best solution for the city transportation (the lands is very flat).
I have met another Romanian guy which as hired to work there this month. By checking the prices and the salary he quoted I know that it is better then what I make .. and many of my colleagues. Unfortunately for the moment such a thing is not possible for us.
Oh .. did I mention my English looks pathetic when compared to the English of people in Netherlands ? I should have... because I felt embarrassed there (this does not happen very often) for not spelling words right in English.

Well I wrote here for 30 minutes .. it's time to get some sleep and re-organize in the morning.