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!


One Reason Politics Fail Today

6. March, 2011

I just watched “Herfried Münkler: Wie sieht die Zukunft der Demokratie aus?” (German). The show raised some good questions: What is the future of democracy? Why did we fail in Iraq and Afghanistan?

Why doesn’t anything move in the world of politics today?

Books and politics strive on conflict. Churchill wasn’t so efficient because he was a nice, tolerant guy. Hitler moved the world (not in a positive way but he did).

In the old days, there were three groups: The nobility, the bourgeoisie (or middle class) and the poor workers. They defined themselves with money. The nobility just had it, work was optional. The middle class had it because they had worked or were working hard for it. The poor didn’t have it and never would.

When money became widely available, the nobility vanished or it was absorbed in the middle class. Suddenly, the only real difference between nobility and the rich was pedigree  — and sometimes manners. After that, social societies formed which started to absorb the poor. There are many people in Germany who are relatively poor but no one has to be absolutely poor (i.e. can spend a dollar/day or less).

In politics, being a mirror of society, something similar happened. The awe for nobility was replaced with elected representatives. Parties formed to represent different parts of society: The middle class, the poor, the environment.

Only, the poor were absorbed and the environment is getting better every day. There still is a difference on paper but not enough to spark real conflict. All the parties have become more or less interchangeable. People start to notice how strained the “conflict” has become, the discrimination of the other parties for the sake of being different enough to be elected.

No conflict means no drive. Everyone is relatively rich and safe, so the attention is on preservation instead of change. Hence we see endless discussions over 5€ more or less each month for people living on social welfare. The discussion was probably already more expensive than the result.

Since there is a wide middle ground on which everyone can agree, topics like getting the international financial system under control are … awkward. Everyone knows that something has to be done, but there is no pressure. We’re so rich, we can simply spent a couple of hundred billion euros/dollars/whatever by simple signature on a piece of paper. Why bother.

The crisis failed to be big enough. We’ll have to wait for the next round.

Why we failed in Iraq and Afghanistan

We went there to help the poor population against their oppressors (following the honorable motive of the Second World War). Oh, and there was oil. But oil doesn’t sell well on the “Mother-lost-Son” market. So the decision makers needed a better coin: They sold democracy.

Only you can’t sell democracy. It’s a state of mind, a deep wish that people have to make true for themselves. Look at EgyptTunisia, the history of your own country. Democracy happens when people fight for it for themselves. The only way a dictatorship can help to make a country democratic is by making the denizens mad enough to struggle for the change.

One of the problems we face in the Arabic world: We, too, are responsible for their harsh situation. The people living there won’t forget how we made various dictators insanely rich and humored them, even when they slaughtered their own subjects. The insurgents in Libya are wary of “Western intervention,” even if we try to help as good as we can. Maybe that’s more wise than we’d like.


Fail Compilations

4. March, 2011

Need a good, hysteric laugh? Watch TwisterNederland7’s monthly Fail Compilations. Ten minutes of good, political incorrect fun.


Bonus is Bad For Motivation

3. March, 2011

Dan Ariely published a book last year that every manager in the world should read, especially the ones with huge salaries:  “Predictably Irrational

When we make decisions we think we’re in control, making rational choices. But are we? Entertaining and surprising, Ariely unmasks the subtle but powerful tricks that our minds play on us.

In that book, he explains why people perform better or worse when there is a huge bonus in their pay. If the work is mostly mechanical, a huge bonus makes you perform better. But if your work is cognitive, the performance is worse than without a bonus.

One reason is that you can handle the additional stress (higher expectations, greed for the money, etc.) of a huge bonus better when you don’t need your brain for something important at the same time. Imagine that the stress of the huge bonus occupies just 5% of your brain power. Without the bonus, you’d perform at 100% instead of at 95%.

Most companies pay bonuses because of the huge workload and risk. Say the bonus is linked to achieving some goal. Imagine manager A would get a bonus but unfortunately, he won’t because person X made a mistake. This is a likely situation: High risk, remember?

What happens now?

Manager A might be angry that he doesn’t get the bonus because of X. That time is wasted. Not only didn’t he achieve the goals, he’s wasting time moping about an incentive he won’t get. Not what we want.

Or he might be tempted to cover up X’s blunder. This time, the incentive corrupts him. Definitely not what we want.

Or manager B might get a bigger bonus which A finds unfair. He might be tempted to sabotage B or at least spend some time moping why the world is so unjust.

Even when he gets the incentive, every minute he spends thinking about it is a minute lost to the company.

Incentives work perfectly for brain-dead work like repetitive, manual labor where your brain is idle and easily distracted. Here, the incentive gives you an extra reason to concentrate on the job.

But if your job includes making complex decisions, the incentive reduces the amount of mental work that you can do because it distracts you!