the blog for developers

Qi4J the next Java? Forget Scala

Qi4J is the new kid on the block. Forget Scala (not although but because Bruce Eckel, the author who switches hypes faster than other people switch their underware, declares Scala to be the next big thing). Scala helps you solve CS problems nicely, but not business problems. Qi4j is about composite oriented programming. It’s designed to solve business problems. One of the brains behind Qi4J is Rickard Öberg, the brain behind JBoss. He is one of those geniuses who know that their cleverness hasn’t anything to do with the language they use. Other devlopers think that the tools they use make them into a genius (by association) and dismiss Java in favour of Ruby or Lisp or OCaml or Haskell or Lua. Some even think that Java spoils you for everything. What?

Another of those geniuses is Bob Lee, about whom I said in my Sourcekibitzer interview: “He wrote Dynaop, the best AOP for Java, Guice and now is part of the promising Web Beans project. A very friendly and extremly clever guy – swimming outside the mainstream with better ideas until all others get it too ;-) His style of coding looks aesthetically very pure to me and I like it very much.”[1] I guess the same thing could be said about Rickard.

Back to Qi4J. Why could Qi4J be the next Java? Qi4J tries to solve one of the holy grails of computer science: reuse. Their goal is to create applications by composing, not by writing code. Their solution is to decompose Java objects into fragments. This happens in two dimensions. Horizontally objects are decomposed into mixins. Vertically objects are decomposed into mixins, concerns, constraints and side effects. By splitting a Java class into much smaller fragments with specific roles they hope to increase the reuse of those fragments. So one does no longer write code but compose those fragments into bigger composites.

  • Mixins: Containing state, e.g. Name, Person, Adress
  • Concerns: Statelessm e.g. TransactionWrapper, Security
  • Constraints: Checking parameters, e.g. NotNullConstraint
  • SideEffects: Managing side effects, e.g. sending Mail

An example for a PersonComposite could look like this:

@Concerns({Security.class, Transaction.class})
@SideEffect({MailNotification.class})
public interface PersonComposite
    extends Person, Name, Adress, Composite
{
}

The PersonComposite is build from a Person (handling e.g. gender), a Name (handling firstName and lastName) and Adress (handling street). The extension of Composite doesn’t look that nice, perhaps they change this in the future. A developer can now use PersonComposite and call getFirstName() and getLastName() on the composite. If he creates an Employee class he can compose it the same way and reuse Name. For storing a House he can reuse Adress.

Qi4J provides standard fragments like a PropertyMixin. With this mixin your Name only needs to look like this:

public interface Name
{
    public void setName(@NoEmptyString String name);
    public String getName();

}

and Qi4J will fill in the actual state-handling code.

Why is Qi4j probably the next Java? Java is an enterprise language. It solves enterprise problems best (technical, deployment and organisational/ socialogical problems). Other languages solve time-to-market-VC-funded-startup problems best. Still other languages solve computer science problems best. The next language needs to solve my enterprise problems better than Java does, which means fixing Javas holes. One hole is reuse, one is tight coupling, one is dependencies. JavaNG needs to solve those. Does Qi4J help? I might think yes. It has nice ideas and adresses some of the Java problems I have in the enterprise. If DDD takes off, Qi4J or frameworks like Qi4J will take off too.

Qi4j has lots of other goodies I’ll explore in another post.

Thanks for listening.

[1] Beautiful code doesn’t depend on the language. I like modern art. I can see beauty in modern art. Not in all, but in some. I’ve argued with a lot of people who do not see beauty in modern art. Those people believe only using oil on canvas drawing people can create beauty. The same goes for the argument that you need a special language to write beautiful code. You do not. I believe there is beautiful Cobol code around. And I wrote such beautiful programms in 68k.

About the author

stephan Stephan Schmidt has been working with internet technologies for the last 20 years. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own. You can find him on Google +

You can leave a Reply here. Of course, you should follow me on twitter here.

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

Leave a reply.

Comments

Thanks for the kind words! The only thing I have to add really is that we are currently looking into explicit support for properties, which means that declaring the Name interface will look something like this instead:
public interface Name
{
Property name();
}

As you wrote, the implementation will be provided automatically, so this is all you have to do. This will allow you to work with properties much better, get meta-information about them easily (example: “person.name().getPropertyInfo(DisplayInfo.class).getLabel()”), do UI binding, etc.

It’s all work in progress, but I agree that I think this has good potential for solving a bunch of the problems with current software development in Java. Time will tell!

stephan

Thought about the property when reading on your blog and the examples.

Setting the property does look like this then?

person.name().set(“Stephan”)?

Not sure if that’s a good idea.

person.setName(“Stephan”) seems shorter, so I’d like to have that in the interface but my PersonBean could have a Property name() which is automatically mapped from the interface by Qi4j.

person.name!(“Stephan”) could be done too.

Attributes in interfaces are final, but could they be declared?

public interface Name {
public String name;
}

and Qi4j maps a person.name=”Stephan” call to a setName() in the bean?

Good look with solving the decade old Java property problem.

stephan

I wrote about a @Getter annotation

http://stephan.reposita.org/archives/2007/11/24/getter-annotation/

before. get/set should no longer be needed for Java. Wasn’t it just so that GUI builders could detect attributes by looking at the method name? Annotations should solve that.

What I especially like about the Qi4J examples is the @NoEmpyString annotation in the interface instead of the class definition. It’s more like a contract that way.

Robert

Just for completeness there is:

Naked Objects
JMaki

Those are both in the same category as Qi4j.

stephan

I think they go into a similar direction but differ form Qi4j.

Doug

You had me until “JBoss”

:)

stephan

@Doug: The brain you know, compared to say Marc. Before it went down. Well intellectually at least. The money went up. But isn’t that always the case? Brains out, money in? Or is it the other way round?

Viktor

Lots of opinions, less facts.
I spoke to several of the Qi4j-members at the announcement at ÖreDev, and unfortunately I think they’re trying to implement the idea in the wrong language.

stephan

Regarding “They implemented Qi4J in the wrong language”. Qi4J is an idea and can be implemented in any language. Qi4R? Qi4P? Qi4S? My only complaint is, they should try to implement this on top of Guice instead of doing their own DI. Sure that would mean compromises but increase adoption. Evolution instead of revolution will win the heart of the enterprise.

> I spoke to several of the Qi4j-members at the announcement at ÖreDev, and unfortunately I think they’re
> trying to implement the idea in the wrong language.

Similar argument we had in a JUG meeting with the presence of Rickard. Some people think that Qi4J is merely a hack and why Java at the first place?

Qi4J is just an implementation of COP and you can implement it with any language. Java is a stronger platform for enterprise development in comparison with other languages and it therefore worth investing. I’m sure a lot of the enterprise folks will welcome this.

- yc

mama keroro hentai mama hentai kazama

amazing stuff thanx :)

Good stuff, looking forward to sticking around.

[...] including evolved concepts from AOP, DI and DDD“. The man behind the project is Rickard Öberg, well known for development of JBoss, Webwork and XDoclet. It is 100% pure Java implementation of [...]

rod

Could you elaborate on your assertion that scala is rubish ?
I think scala provides many basic concepts that should highly ease the implementation of a DDD framework. There would probably be many benefits to write Qi4J in scala.

Mert Nuhoglu

Hi Stephan,

Inspiring article. Thanks for sharing with us. You told that you would write about other goodies in Qi4J. We are waiting for it :)

Leave a Reply

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?