Tuesday, June 30, 2009

Maturity of DSLs as a concept

angry_baby.jpgI like the following quote from Jay Field's screencast The 5 Ws of DSLs:
The DSL movement is in a stage that is similar to the stage of OO before Design Patterns were documented.

- Jay Fields, InfoQ

The concepts for DSLs are slowly being fleshed out. As experience is gained, best practices will evolve. But we are at the beginning of this process!

Along those lines:
Overuse of DSLs is one of the antipatterns in Groovy development.

- Dierk König, Gr8Conf

Do not create a DSL if a native solution would be as elegant.

- YADSL Rule

Some DSLs will live and some DSLs will die...

- Rocky Lothka, .NET Rocks Episode 417

Monday, June 29, 2009

Programming humor continued: Airlines

braindead-closeup.jpg Thanks Stefan for pointing me to this:

If Programming Languages ran the Airlines

and not as funny as the above:

If Operating Systems Ran The Airlines...

Thursday, June 25, 2009

Restarting the embedded OpenEJB container between each test

logo_openejb.gifIf you are looking for an embeddable EJB3 Container for your unit-tests/integration-tests, OpenEJB is currently the most mature solution (alternatives are embedded Glassfish and JBoss embedded).

The documentation and the samples of OpenEJB are really neat and enable an easy jump-start. All the examples are automated tests that run with a simple mvn clean install.

After a while however I came across the following problem: The embedded container is not restarted by default between tests. If you have two tests (even in several test classes), each starting the embedded container, then the second test gets passed the same instance of the embedded container as the first one.

This has the potential for shared state between the tests and strange side-effects as a consequence.
The first occurrence is when you are accessing an (sandboxed) database, that gets initialized (hibernate create-drop) when initializing the persistence-unit. Since the container is not restarted for the second test, the persistence-unit does not get initialized a second time. This means you have all the traces from your first test in the database...

An easy way to work around this, is the undocumented feature of OpenEJB to destroy the container when closing the initial context.
This is achieved by setting the property "openejb.embedded.initialcontext.close" to "destroy" on the InitialContext.

Now my test harness looks like this:
public void setUp() throws Exception{
	Properties p = new Properties();
	//Set some other properties like datasources ...       
	p.put("openejb.embedded.initialcontext.close", "destroy");
	context = new InitialContext(p);
public void tearDown() throws Exception{

It should be kept in mind, that restarting the embedded container can have implications on the performance.
In my first tests on my MacBook, the repeated startup of the container takes about 200 ms, which I find acceptable for integration tests... but probably the concrete deployment scenario has an influence on the startup time ...

Wednesday, June 24, 2009

Raising the Level of Abstraction

highjump.jpg Abstraction is a central concept in software development.
Abstraction is probably our only hope to conquer the ever rising complexity and requirements in current and future systems.

When designing a software system today often there are no physical constraints. The only constraints are intellectual: Is the design understandable, maintainable, what are the effects of future changes ...

Abstraction is supposed to be a tool to do the right choices when designing.
But what is abstraction really? How do you characterize it? How do you measure it?

There seem to be a lot of different notions about how to raise the abstraction level.

Some people talk about nonterminal symbols:
<integer> ::= ['-'] <digit> {<digit>}
<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'

Some people believe in pictures and visuals:

Some people see hope in reducing the signal-to-noise ratio of code:
[...] a lot of Java programs are the boiler plate of controlled structures with very little business logic. It's probably a four or five to one ratio between business logic and boiler plate control structures. So Ruby gives you that conciseness.
You are saying: "Here is the business logic, apply this business logic [...]

-- David Pollak, InfoQ

For me, the third approach is currently the most promising. That's where DDD tries to pull the lever. That's where concepts like the Ubiquitous Language and Domain Specific Languages try to provide value.

And finally remember Joel Spolsky's Law of Leaky Abstractions:
All non-trivial abstractions, to some degree, are leaky.

Tuesday, June 23, 2009

Grails: The other side of the coin

coin_2sides.jpgRecently I have become a big fan of Grails.

I think even if you are actually not using the bits of Grails, Grails can provide valuable insights and fresh perspectives in the turgid maze of Java EE development.

At the gr8conf it was stated, that Groovy and Grails are in the transition from the early adoption phase to mainstream technology.

Becoming a mainstream technology is a dangerous beast, which can brings dark secrets into the light.

Grails seems currently to be in a fight with this beast, as some critics has been voiced on the mailing lists. This is nicely summarized in the following post:
Are Bugs in Grails Hurting Adoption?

I think critics are essential for a product to become mature. It shows that there are actually people out there that care, and that the community is not just a bunch of zealots.
The crucial question is now how Grails will deal with the criticism.

Monday, June 22, 2009

Running Canoo WebTest 3.0 on OS X

I am running Mac OS X 10.5.7

I upgraded from Canoo WebTest 2.6 to 3.0.

2.6 was running ok, but 3.0 failed with the following exception:

BUILD FAILED /Applications/CanooWebTest_3_0/webtest.xml:234: The following error occurred while executing this line: /Users/jbandi/Documents/Testcode/bookstore/webtest/tests/allTests.xml:5: The following error occurred while executing this line: /Users/jbandi/Documents/Testcode/bookstore/webtest/tests/search.xml:9: java.lang.NoSuchMethodError: org.apache.xpath.compiler.FunctionTable.installFunction(Ljava/lang/String;Ljava/lang/Class;)I

After some time spent on Google, I found the following solution:

Copy the xalan-2.7.0.jar into /Library/Java/Extensions/

You can get this jar from the WebTest distribution or from here.

This worked for me, although it leaves a fishy smell... I don't like messing in the guts of the system ...

The reason is probably, that the new release of HtmlUnit now uses standard DOM tools for evaluating XPath. And the Java distribution of OS X does not ship with xalan. Or my classpath was somehow messed up ... If anybody knows the details, please enlighten me ...

Wednesday, June 17, 2009

IE vs. Firefox - Microsoft has to be desperate?

If this is not a joke, I don't know what is ...

Well, we all know how David versus Goliath ended ... though it is not bequeathed that Goliath went for a blow below the belt line ;-)

Tuesday, June 16, 2009

New Book by Adam Bien: Real World Java EE Patterns Rethinking Best Practices

Adam Bien has published his new book: Real World Java EE Patterns Rethinking Best Practices.

I am eager to get a copy of this book. Adam is a tireless advocate for pushing Java EE development further.

I hope this book is a big step in proving that Java EE development can be much easier and much more lightweight than we are experiencing it today in the trenches of enterprise IT.

Adams statement is: "Java EE 5 and 6 are a revolution and not just an evolution".
I think this insight has not yet found its way into the mindset of most Java EE architects. 250px-Neo.jpg Old-school heavyweight concepts from the ages of EJB2 still tantalize a lot of the Java enterprise projects.

To break free, radical steps are necessary. Best-practices have to be rethought, antiqued patterns have to be killed...

People are usually afraid of revolutions ... I hope Adam can be our saviour ;-)

BTW: If you are living in or near Switzerland, Adam will hold a workshop at the Workshoptage of ch/open. See you there!

Monday, June 15, 2009

Update for Software Testing Workshop

My semi-annual testing workshop at SWS is approaching. In the theoretical part I want to incorporate some insights I picked up recently:

From Aslak Hellesøys presentation "Executable User Stories with RSpec and BDD" (slides):

Where errors are introduced (according to CHAOS report):

Sample chart

This should put developer testing in the big picture of software development.
  • Developer testing is traditionally focussing on code, maybe also design.
  • Techniques like BDD, FIT and Acceptance Testing can also help to takle errors in the requirements.
  • Validation (in contrast to verification) can also help to uncover problems in design and requirements. Validation can be accomplished prior to the creation of the software artifacts.

  • From Jay Fields talk "Developer Testing: Welcome to the Beta Test":

    Most important characteristics of good unit tests:
  • Readable
  • Reliable
  • Performant

  • Reasons to write tests:
  • Design
  • Protect against regression
  • Achieve sign-off
  • Increase customer interaction
  • Document the system
  • Refactor confidently
  • Ensure the system works correctly

  • Unit testing suggestions:
  • Setup methods are evil
  • Test one thing at a time
  • Maintainability > DRY
  • Test names are comments
  • Zero or one mock per test
  • Expect literals
  • Create test data builders

  • Wednesday, June 10, 2009

    Join the Groovy & Grails User Group Switzerland

    If you are interested in Groovy and Grails and you are living in Switzerland, you should join the Groovy Grails User Group Switzerland on Xing.

    Thanks Silvio for appointing me co-moderator of this group. I hope I can help the group to grow.

    Tuesday, June 9, 2009

    My pitch for Grails in Action

    http://manning.com/gsmith/gsmith_cover150.jpg Today my copy of Grails in Action arrived.

    I did a review for this book, so Manning was so kind to send me a free copy.
    Unfortunately the publisher decided not to include the quote I provided, so I will print it here:

    This book should be a must read for every Java enterprise developer! Grails shows a pragmatic lightweight approach to the Java EE platform which is eye-opening and will change your perspective on Java enterprise projects.

    I really believe that learning Grails can provide an interesting new perspective on Java EE development.
    But I think there are two common misconceptions about Grails:

  • Grails is not about code generation. Even though grails provides possibilities for generating skeleton artifacts, thats just a minor convenience feature. You can use the power of Grails without even using the code-generators even once (As a proof you can watch Graeme Rochers webinar "Bulding Twitter in 40 minutes").
  • Grails is not reinventing the wheel. Grails builds on top of proven Java frameworks (Spring, Hibernate and SiteMesh being the most prominent ones, but many more integrations are available). Grails is an abstraction layer over those frameworks and aims to provide a seamless integration of those frameworks to form a homogenous web application stack. By default Grails imposes proven best practices for web development. All this is wrapped with the elegance of the Groovy language.
    But Grails is not a one-way street. It is always possible to fall back to plain Java and therefore leverage the rich ecosystem which exists on the Java platform. JMS, REST, Spring Security, JCaptcha, RSS, OpenId, LADAP, jQuery, Axis2, Compass ... you name it, Grails provides it ...

  • Related Posts Plugin for WordPress, Blogger...