TNBT – Object Teams

15. March, 2011

Object Teams, or OT/J for short, is a solution for the old Java problem “there is no I in ‘team'”: Most Java code is written as if the whole world was openly hostile. It’s riddled with final, private static, singletons, thousands of lines of code which almost do what you need except for this one line .. that you can’t change without copying the other 999.

Groovy’s solution: AST transformation. A topic for another post.

OT’s solution: create a Java-like programming language which allows you to extend code that isn’t meant to. A great example: Extending Eclipse’s Java compiler.

The Eclipse Java compiler is one of the most complex pieces of code in Eclipse (“5 Mbytes of source spread over 323 classes in 13 packages“). Unlike other compilers, it can compile broken code. The same technology is used to create byte code and error markers in the editor.

Stephan Herrmann wanted to add support for @NonNull and @Nullable. Usually, you’d create a branch, keep that branch in sync with the main branch, etc. Tedious. For every change that someone makes in the main branch, you must update your development branch. Even if the change is completely unrelated. CVS has a very limited concept of “related”. DVCS like Git or Mercurial are better at merging but they also don’t understand enough of Java to give the word “related” a useful meaning. “Same file” is the best you can get.

So instead of the tedious way, he used OT/J to create an OT/Equinox plug-in which patches the JDT compiler byte code. Sounds dangerous? Well, OT/J does all the ugly work. You just say “when this method is called, do this, too.” Sounds a bit like AOP? Yes.

Unlike AOP, it communicates intent more clearly. The code wasn’t designed to be the most compact way to define a “point cut” and then leave it to the reader to understand what this is supposed to mean. It better communicates the intent.

I’m not completely happy with the syntax, though. I don’t have specific points, only a general wariness. Maybe a careful application of Xtext would help.

Related Articles:

  • The Next Best Thing – Series in my blog where I dream about the future of software development

JaCoCo: Successor of EclEmma

15. March, 2011

If you’re using EclEmma to check the code coverage, you should have a look at JaCoCo. If you’re not using code coverage, yet, you really should.

JaCoCo (Java Code Coverage Library) is the successor of EclEmma where the developers applied all the lessons learned during the time with EclEmma.


Eclipse Workspace Mechanic

14. March, 2011

If you want to:

  • Create a consistent environment among groups
  • Save time setting up new workspaces
  • Make sure your favorite preferences are applied to all your current and future workspaces

then this is for you.

Related articles:


Declaring Relations Between Model Instances

14. March, 2011

I’ve been playing with Xtext 1.0 the last three weeks. The editor support is most impressive. It’s one of those well balanced technologies that work “right” out of the box, offer lots of places where to hook in to tweak things.

The last few days, I’ve been chewing on a hard problem: Relations. I could to this:

class A {
}

class B {
    A parent 1:*;
}

Read: Instances of B have a field “parent” that references instances of A. There is a list in A with all instances of B where the field “parent” is that exact instance. In simple words, it’s a parent-child relation between A and B. For each B, there is always one A. Each A can have several B’s attached.

Or like this:

class A {
}

class B {
}

relation A children 1:* B parent;

The first solution avoids repetition but when looking at A, you will miss the fact that it has fields. It looks empty but the declaration in B adds a field. I don’t like it. While it might work in this case, how do you map N:M? Where do you declare a many-to-many relation? In A or in B? My guts say: Don’t do it.

The second solution is also flawed if less so. Here, both classes are empty. I have to look up the relations to see what else is going on. And I have to repeat information. I don’t like it.

Time to take a step back and sleep over it.

Fast forward over the weekend.

How about this:

class A {
}
parent of
class B {
}

One word: Intent. A construct in a programming language should clearly communicate intent. Which is one of the weak points in Java: It’s hard to express what you intend with Java. It’s not impossible but it takes years of experience to avoid the luring shortcuts.

So this new syntax clearly states what I want: A’s are parents of B’s. No repetition. No odd “1:*” which every reader has to decode. Which you can get wrong.

But what if A is parent of more classes? Simple:

class A { }
parent of {
    class B { } parent of class X { }
    class C { }
    ...
}

See? It nests. Let’s add tree-like structures to the mix:

tree class A { }
parent of {
    class B { } parent of class X { }
    class C { }
    ...
}

So A gets a parent-child relation with itself. One word says everything: Ownership. Cardinality. Field names.

My gut likes it. Listen to your guts. Especially when a simple solution tries to lure you into a shortcut.


Why Sony Should Lose

12. March, 2011

Sony sued Hotz for being smarter than them. Georg didn’t steal, he didn’t break anything physical. No one got hurt in the process. No equipment was mishandled. He just satisfied his curiosity. Bad boy. Down.

Somehow, the world has been turned into a legal nightmare by us. So Georg is smarter than the Sony PS3 engineering team. Or the guy who did the encryption part. Or probably his manager – “I don’t care if it’s ready, we ship on Monday!”

LG sues Sony over some obscure abuse of ideas. “Patents” are they called, I hear. An essential weapon in the global economic wars of the 21st century. Laws are passed which turn curios pupils into bad-ass criminals. For the common good.

It’s traditional. No, really. In the 16th century, people got burned on stakes for examining the human body – things like blood system, bacteria, health, were all a big mystery then (at least in Europe). Instead of supporting the few smart people trying to help, they got killed. For violating the Laws of God. I’m sure that quite a few of the victims were aware that most of those Laws were written down and enacted by non-gods.

Today, companies pour billions into new, great products and are offended when a smart guy finds a flaw that topples their dreams of World Domination™. Losing billions due to someones own stupidity hurts a lot. Better share the hurt. Even better hurt someone else. Is that what we really want?

Inaction is a decision, too, and carries the same responsibility.


TNBT: JetBrains’ MPS

10. March, 2011

Disclaimer: I’m not a fan of IntelliJ IDEA.

In the past, I’ve always had an eye for people who replaced the ASCII text editor with something … better. Imagine you could use a table to define your constants in Java. And with table, I mean “Excel” not “align-with-space-until-it-you-go-insane.”

JetBrains is working on this: Table support in MPS 2.0

Let me make this clear: A DSL is nice. But there are so many things that you simply can’t express well with text. State machines. Repeated code. Sometimes, you don’t need the exact words to convey the idea.

I think I’ll waste some time with MPS 2.0 M3 next weekend. There are a couple of tutorials and demos.

Related Articles:

  • The Next Best Thing – Series in my blog where I dream about the future of software development

Sony About to Sue You

9. March, 2011

If you  have been visiting geohot’s blog or any other page of him, you should be aware that Sony now has you IP address for the purpose to sue you.

As we have seen in the past, Sony doesn’t need a good reason to sue, a whim is enough.

So if you live in the US, you should maybe think what this means for you. For the rest of us, make sure you can enjoy your next trip to the states (instead of spending it in, say, a prison because you violated some law that you didn’t know about – ignorance is no excuse).


Over 50K on stackoverflow.com

9. March, 2011

I made it: 50,019 points on stackoverflow.com.


Time Travel – At Least In Java

8. March, 2011

There is a new debugger which allows to travel in time: chronon.

Chronon will record every line of code executed in a Java program along with all the variable values and exceptions, etc. and allow to browse the timeline. You can see all the exceptions that were ever thrown, select them, go back in time to see how they happened.

No breakpoints – instead you jump directly to the point in time when your code passed a line.

The demo looked pretty promising. I’m just unsure how it fares with a big code base where even simple tasks can execute millions lines of code.


IE6: Time to Say Goodbye

7. March, 2011

The large group of people who want to get rid of IE6 just got another member: Microsoft. Good luck!