Wednesday, 19 October 2011

Grails doing unexpected Hibernate selects when checking if lazy properties are null

So this bug cost me several hours of my precious time. I had to check if a member of a GORM entity is null or not without lazy loading that same entity. Turns out it is not very simple, nor is it intuitive. Doing a simple
if ( == null) {..}
triggered a Hibernate load. A working solution is explained here: you have to do
if (object.propertyId == null) {..}

I cannot find this in the documentation but as the docs are huge, I may have very well missed it.

Tuesday, 18 October 2011

Thoughts on Dart

I have to say I disagree with the article on Dart that appeared on Quirksmode.

The author argues that Javascript has already 'won' and Dart has 'lost' because there are billions of Javascript-capable devices available today. I think it's the wrong comparison: in the short term, Dart isn't competing with Javascript, but rather with these guys! To name just a few famous ones: CofeeScript, ClojureScript, GWT. Dart is much less efficient than all of these guys right now, but it isn't like Google to fall into the premature optimization trap so I expect some serious improvements on this front.

The article also states that Dart is a result of "disdain that "real” programmers feel for JavaScript". Javascript is the ugly duckling that required plastic surgery to turn into a swan. Sure, it has a few nice tricks up its sleeve to alleviate the sucky parts, but many of those same tricks are preventing both its efficient optimization as well as its maintainability. That list of the 100+ languages that compile to Javascript should give us a hint that Javascript isn't Mr. Perfect. And don't get me started on its standard library: just thinking about Javascript's date handling or internationalization support (no, we're not all American) gives me a nervous twitch! If by "real" programmers QuirksMode means the guys and gals who have to write and maintain non-trivial applications that work well on several continents, who move to a different job and find that their new employer is using jQuery instead of Prototype, these non-rockstar developers _should_ hold a disdain for Javascript.

I think in time Dart's place in mobile will become better defined. Either the general public is not in the loop or maybe Google hasn't decided yet, but I can think of at least two scenarios and I'm sure there are more options:

  1. Google switches Java for Dart as the main Android development language: it's not such a far stretch given the Oracle lawsuit and Java's rigidness when it comes to fast prototyping (the thing projects like Groovy and Clojure are trying to alleviate) 
  2. Google creates either an Adobe Air-like container or a PhoneGap style compiler for Dart apps that runs on all the major mobile platforms

Nothing lasts forever. COBOL and Fortran aren't hot stuff anymore and Javascript is far from perfect. I don't know who or when will topple the king, but Google doesn't want to meet the same fate on the web that Microsoft did with tablets. It's seeing chinks in Javascript's armor and it's ready now with talent that has built V8, Dalvik and the like. If Dart fails Google will try again and again but I wouldn't count the new language a default loss just yet.