Stuff about software development, agile and testing

Thursday, November 29, 2007

jruby closure decompiled

Its quite interesting to look into the compiled class file generated by JRuby. Following is the sample java code generated for a closure (1.times { puts 'in closure' }) .

private static ByteList __18 = ByteList.create("in closure");
.....
.....
public IRubyObject closure0(ThreadContext threadcontext, IRubyObject irubyobject, IRubyObject airubyobject[])
{
Ruby ruby;
IRubyObject irubyobject1 = (ruby = threadcontext.getRuntime()).getNil();
DynamicScope dynamicscope = threadcontext.getCurrentScope();
IRubyObject _tmp = irubyobject1;
do
{
try
{
threadcontext.setPosition(__15);
return _17.call(threadcontext, irubyobject, RuntimeHelpers.constructObjectArray(ruby.newStringShared(__18)));
}
catch(org.jruby.exceptions.JumpException.RedoJump _ex) { }
} while(true);
}

RedoJump exception is used to simulate ruby redo

Tuesday, November 27, 2007

inpsect gem file

Playing around with RubyGems source code. So first thing I wanted to know is the gemspec.

Here is a small script to inspect any gem file

require 'yaml'
require 'rubygems/source_info_cache'

Gem::SourceInfoCache.cache
spec = Gem::SourceInfoCache.search('#{gem}')
p spec.to_yaml

You could also use Gem::SourceIndex to spec out locally installed gems

Sunday, November 11, 2007

My new X


Finally I got Leopard installed in my Mac..... :)

Tuesday, October 23, 2007

hudson rules

Gone those days when we were promised that copying a war file to web server will bring your application. I thought that's a myth in Java world(what happened to webstart anayway?). But when I looked into Hudson today my eyes were wide open, its possible..all j2ee developers out there close your xml editors and take a pick.

We use Anthill Pro for our continuous integration build and it has all the bells and whistles you expect from big CI tool these days. But Hudson has only those basic things that you need to setup a continuous build environment. I was able to setup within 15 mins using my existing ant build file. Now when I compare with other tools they seemed to be over-engineered and difficult to setup and use(Let me know if I am wrong). Did I mention it has some cool plugins.

Wednesday, September 12, 2007

ejb 3

After ranting about Xml and j2ee development pain, I have to agree that ejb3 is really awesome. I was able to develop an entity and session bean without any deployment descriptor apart from persistence.xml file. Its really cool to see power of annotations in practice. Having a reflection of field experience really helps any framework to be more developer friendly.

Friday, September 7, 2007

xml bites again

Have you seen anybody who actually like doing j2ee/xml work?

I haven't and just because 90% of java work is j2ee stuff they are tied to it in spite of the dislike. If you have noko niko calendar of your team all you will see is :( . Apparently it took 1 day for me to integrate one external ejb with our module. I don't consider myself a j2ee expert but honestly how good are collection of xml configurations when every time you change something you have to redeploy. All I want is to compile and run my tests, is it too much to ask? . If you have a big project like us then you are screwed because every XML change requires jaring, redeploy and restart of your application. Its quite a big cycle when you have no compiler watching for your deployment descriptor errors. I am not sure whether Websphere application developer or Weblogic workshop have any sophisticated logic to validate your DD's before even deploying it.
Anyways do we really need all these descriptors to deploy some manage beans? Introspection and clever defaults could solve all the problem and it doesn't need a CS degree to figure that out, maybe some practical experience.
Honestly have anyone used any 3rd party ejb components or followed all the j2ee roles? If Java at all wants to make a component market a reality make it easy for developers.

Thursday, September 6, 2007

Fluent Interface

Like most other projects out there we are using fit/fitnesse to write our acceptance tests. But to be honest I am not very big fan of fitnesse. It doesn't scale very well with project size and having fixture tables through out fitnesse pages doesn't help readability and maintainability.

Especially if you are building web application you leave the UI part out of the test unless you integrate your UI test tool like selenium with fitnesse but you still miss the readability for tabular test structures. When we get story in BDD(Behaviour driven development) format and acceptance criteria in Given-Then-When style I expect to see my test in following pattern.

"Given products exists when I search product by name then user expect to see all matching products" do

test "goto product page and search for product code '100'
now number of matching products found is '10' "

end

Doing something like this Ruby is possible and in fact Dust is doing something very similar. But achieving something like this in Java is a challenge. Fluent Interface is one of the easiest way to do achieve DSL like look in Java and its quite easy to implement too. Lets consider the following selenium unit test

public void testGivenProductsExistsWhenISearchProductByNameThenUserExpectToSeeAllMatchingProducts() {

goToProductPage().andSearchForProductCode("100);
assertThat(now().numberOfMatchingProductsFoundIs("10"));
}


Its not cool as ruby DSL's but its close and quite readable. Some of our test now looks like this and rest of the team loves it.

Labels