Google Wave Tips: catching robot exceptions

June 17, 2009

Almost trivial code, which I found very useful debugging my robots

public void processEvents(RobotMessageBundle bundle) {
   try {
      processEventsInternal(bundle);
   }
   catch (Throwable t) {
      final StringWriter stringWriter = new StringWriter();
      t.printStackTrace(new PrintWriter(stringWriter));
      bundle.getWavelet().getRootBlip().getDocument().append(stringWriter.getBuffer().toString());
   }
}

Groovy+Scala+Java

March 3, 2009

Almost to years ago I’ve invented and then wrote joint compiler for Groovy and Java. The idea was pretty simple – we do compilation in 3 steps
1) Generate Java stubs from Groovy sources
2) Compile all Java code with generated stubs
3) Compile Groovy code with already compiled Java classes

First implementation was done as part of IntelliJ and later another one was written to contribute in Groovy compiler infrastructure. Thanks a lot to Jochen and other guys who improved and incorporated it in to groovyc and ant tasks. It became probably last cornerstone for 100% interoperability between Groovy and Java and now understood by everybody as natural as if it was in Groovy from day one.

But now my arsenal includes Scala as well. Obviously I want to have Groovy and Scala and of course Java together. Isn’t it natural wish?

Fortunately scala compiler is smart as well and knows how to do joint compilation with Java. Scala does it a bit differently than Groovy – by parsing Java source during Java compilation. So the process looks like following
1) Compile Scala code using Java sources on the way
2) Compile Java sources using already compiled scala classes

Unfortunally (but not surprisingly) scala has no clue about Groovy.

Today I realized that the small modification of my original algorythm + scala compiler can create joint compiler for all three languages together. The complete algorithm is following
1) Generate Java stubs from Groovy sources
2) Compile Scala code using Java sources and generated stubs on the way
3) Compile all Java code with generated stubs and compiled Scala classes
4) Compile Groovy code with already compiled Java classes

I believe you will not be surprised that when I knew what I want to do it was pretty easy to implement. In fact it was mostly refactoring of what we did before. So now in my working copy I can compile Groovy+Java+Scala together. Of course all references in all three languages are resolved correctly in all possible direction.

I think it opens many amazing opportunities of Groovy becoming orchestration language for people who needs both static and dynamic typing plus functional programming. Of course I would like to see it as part of Groovy Core.

I would like to learn what other people think about it. Please let me know.


TeamCity saved my day

May 17, 2008

I had crazy problem this morning – Groovy Core build was failing with StackOverflowException on some Windows configurations but not on Linux or Mac. Unfortunately, it happen after my commit several days ago, so I was somehow responsible for that.

I have only Mac. No Linux. No Windows. So my first idea was to ask someelse to take care for the bug. But you know what… It is somehow not very professional.

Fortunately, I found very simple solution. TeamCity Remote Build. 45 minutes and 15 builds and problem was located. I even was able to create test case, which also failing on my Mac. Really cool.

Now I have more serious problem – to understand how to fix it. But it is kind of more regular work.


Loopy with Groovy

June 7, 2007

There’s been a lot of people asking for a Java loop syntax in groovy. A lot if not almost all usages however are cleaner without it, once you know some idiomatic Groovy.

Marc Palmer’s post blog post demonstrates it almost obviously.