Blog

Open Letter to Geertjan Wielenga

26 Jun, 2009
Xebia Background Header Wave

Geertjan Wielenga has been trying to pull me back into the NetBeans community for a couple of years in a row now. I admire his perseverance; if this is typical for the whole NetBeans team, then Eclipse is going out of the window some day soon.

There is one thing – really, just one thing – that would make me drop Eclipse immediately in favor of NetBeans. That’s having better support for fluent interfaces in the way the IDE formats source code.
Now, I’ve been working on a couple of fluent interfaces over the last couple of years, and it’s just awesome. It will always result in code that is easier to read, and it doesn’t cost you a dime; you get the benefits of Java 5 type safety , without sacrificing readability.
Let’s take this Pecia example:
[java]
doc
.section("Introduction")
.para()
.text("This is a document. Make sure you also check out the ")
.emphasis("next").text(" section.")
.end()
.end()
.section("Conclusion")
.para("That’s all folks.")
.end()
.end();
[/java]
Now, IMHO, this is pretty easy to read and understand. The layout of your code clearly reflects the structure of the underlying document model. However, if you press Command-Shift-F to format your code, this is what you get:
[java]
doc.section("Introduction").para().text("This is a document. Make sure you also check out the ").emphasis("next").text(" section.").end().end().section("Conclusion").para("That’s all folks.").end().end();
[/java]
Not quite as good as what we had before.
Now, I would love to have a solution that basically prevented this. I was thinking about this for a while, and I could imagine introducing a couple of annotations for it. Annotations for fluent interfaces. Annotations that basically tell your IDE how to treat different components in your fluent interfaces for formatting.
Maybe annotations on the type of object produced by the section() operation, informing the compiler to treat this object as a "code block", in terms of the indentation. And perhaps an annotation on the .end() method telling the IDE to consider it the end of the "code block".

test1

So, this is to you Geertjan: I solemnly swear to erase Eclipse from my hard disk, as soon as something like this gets implemented in NetBeans. Maybe an annotation based approach is what is needed, maybe it isn’t; I don’t really care, as long as something gets done about this.
(If anyone else has some thoughts on this, I’d be happy to hear about it.)

Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts