Just a heads up that, following what seems to become an established previous tradition, I'll be attending the JAOO conference this year as well. See ya in Aarhus next week!
Friday, September 21, 2007
Thursday, September 20, 2007
Laugh-Out-Loud Cats
I'll admit that I was mildly annoyed by the whole LOLCats meme. I don't say I didn't get it; I did, I just felt it overdone after a while and couldn't be bothered to pay attention to yet another photo with funnilz missspelt all-caps would-be-jokes superimposed on them.
Until Ape Lad created something wonderful out of it.
Ape Lad, or Adam Koford is an illustrator maybe best known for his graphical interpretation of various hobos from John Hodgman's book "Areas of My Expertise", but I think that soon he'll be referred to primarily as "the guy who created Laugh-Out-Loud Cats".
So, what is it he did with the LOLCats phenomenon? He created a 1920-style cartoon featuring two vagabond cats, as he himself says
"one Meowlin Q. Kitteh (a sort of cat hobo-raconteur) and his young hapless kitten friend, Pip"
. These cartoons are produced traditionally, pen-and-paper, and have an incredibly authentically-feeling atmosphere of the '20s, plus a fantastic chemistry resulting from mixture of innocence, mischief, and cuteness overload in the characters. Just click on the image to the left for the gallery -- it's all available for free viewing on his Flickr account, and I'm looking at its RSS feed with most anticipation every morning for updates (and I'm seldom disappointed, because the guy is really prolific)!
Of course, you might as well check out his other fine works, like his graphical interpretations of various HTTP error codes (to the left, you can see "415 Unsupported Media Type").
Tuesday, September 18, 2007
Liquids on planes in Europe will be allowed again!
Frequent air travelers rejoice!
Apparently, Norwegian Ministry of Transportation asked the European Parliament to move to lift the liquid ban on airplanes. They say it is "annoying for the travellers", and a "large cost for society".
And apparently, the European Parliament agrees!
Sorry if I'm sounding euphoric about this, but this mindless fake security measure did cause me lot of headache in the past. Sometimes literally - there are those situations when I need to catch a transfer and the itinerary is so tight I barely can run from one gate to the other and I don't have time to grab an (overpriced) bottle of water at the airport, so I get a headache of dehydration by the end of the trip. small glasses of water and orange juice served at the airplane are not the same thing. Actually, lately I switched to carrying apples with me for liquid replenishment.
In the meantime, I need to find an (a) aerosol deodorant not exceeding 100ml and (b) shaving foam container not exceeding 100ml for my next week's trip to JAOO in Aarhus (I'm flying with hand baggage only). I figure I can just use the hotel bathroom soap in dire need instead of the shaving foam though. Oh man, can't wait for this madness to end.
Sunday, September 16, 2007
Closures in Java NOW!
I remember Neal Gafter's talk about his idea of how to implement closures in Java that he gave at TSSJS in Las Vegas this March, and I have to say, if we had this feature today, it'd be none too soon.
Lack of closures does give Java a reeeally bad feel in 2007. It makes it very backwards looking in terms of modern programming language amenities, compared to languages that already have them.
Here, let me show you an example.
As we all know, in Java, objects can't control their own locking - they can't customize their behavior when used in a synchronized block. Now, that's one entertaining problem in its own right, and would deserve its very own discussion, as basically, it makes correctness of synchronization dependent on implementation. But that's not the point of this post. The point of this post is how one might try to work around this and similar lackings, and how one will inevitably fail...
Okay, the example: let's suppose I have a class A. I sometimes need to lock instances of it. This is a no-brainer in Java and usually has the form of
synchronized(a) {
... do something...
}Let's suppose I also have a subclass B of A. Instances of B have a reference to another object of some class S, and various instances of B share some of their state through shared instances of S for some reason:
public class B extends A {
private final S shared;
...
}Since the S instance is actually shared among several B instances, the correct locking semantics for B would be to always synchronize on the "shared" field of a B, when client code synchronizes on an instance of B. Unfortunately, there's no way in Java to declare to do a synchronized(b.shared) within every synchronized(b).
What's the next best thing I can do - provided I want to encapsulate the behavior and want to avoid some manual monster code1 at every synchronization site? A smart aleck like me would add a method to A:
public void runLocked(Runnable r) {
synchronized(this) {
r.run();
}
}
Then, I can override it in B:
@Override
public void runLocked(Runnable r) {
synchronized(this) {
synchronized(shared) {
r.run();
}
}
}
Finally, I can replace all occurrences of a synchronized(a) block with:
a.runLocked(new Runnable() {
public void run() {
... do something...
}
});Sounds okay? Well, it isn't. Aside from the very obvious "too much visual clutter" problem, there are further problems with this:
- What if "do something" throws a checked exception? (Answer: more monster code2)
- What if "do something" modifies a local variable? (Answer: yet more monster code3)
- What if "do something" contains a return, continue, or break statement? (Answer: you are seriously out of luck, but some really horrid monster code might help you out. It is so ugly though that it does question the ROI of the whole approach. No, I won't give an example.)
So, what happens is that you eliminate ugliness in one place, only to have it resurface because of these other problems in another place. It is not really possible to arrive at a win-win situation with current language constructs. (Alternatively, I'm not smart enough to figure it out. Either way, pity). Needless to say, if we had real closures in Java instead of the very weak imitation attempt in form of java.lang.Runnable, none of these would be a problem.
1 the monster code in question would look something like:
synchronized(a) {
if(a instanceof B) {
synchronized(((B)a).getShared()) {
... do something ...
}
} else {
... repeat do something ...
}
}
2 the monster code for working around checked exceptions would be:
try {
a.runLocked(new Runnable() {
public void run() {
try {
... do something ...
} catch(RuntimeException e) {
throw e;
} catch(Exception e) {
throw new UndeclareThrowableException(e);
}
}
});
} catch(UndeclaredThrowableException e) {
Throwable t = e.getCause();
if(t instanceof Exception) throw (Exception)e;
if(t instanceof Error) throw (Error)e;
throw e;
}And it can get even more fun if you're trying to only get a specific type of a checked exception (say, IOException) and not a generic Exception across the scope.
3 the monster code for working out local variable modifications would be:
final Object[] embeddedLocalVar = new Object[1];
embeddedLocalVar[0] = realLocalVar;
a.runLocked(new Runnable() {
public void run() {
... do something ...
embeddedLocalVar[0] = newValue;
}
});
realLocalVar = embeddedLocalVar[0];
Pure beauty, innit?
Friday, September 07, 2007
"How can a spinozan cast a dualism spell?"
If you enjoy reading works of Jostein Gaarder (come on, you must've read at least "Sophie's World", haven't you?), and if you likewise enjoy reading any or all of Greg Egan, Charles Stross, or Neil Gaiman, then you'd adore a hilarious webcomic about (in no particular order): philosophy (if you can actually get the joke in the post title), quantum physics, psychology (with regular appearances of "Tiny Carl Jung"!), all with a big dose of surrealism.
That's exactly what Dresden Codak is.
If I may recommend, start reading from this one, as it and the next few ones are extraordinarily brilliant (contrasted with the rest, which are just, well, ordinarily brilliant). Then revisit the older ones after you reached the end.
My only woe is that there aren't too many of them yet, and it's not updated too frequently. But hey, quality work needs time!
Sunday, August 19, 2007
The World's Toughest Programmer: "How I became a programmer"
I recently discovered the blog of The World's Toughest Programmer a.k.a Mike Lee, and I can't help already loving him. He hasn't written a lot in his blog for now, but what he did was very thought provoking so far. His newest writing "How I became a programmer" is a must read. Tagline:
I was born a programmer. The rest is just implementation detail.
:-)
Wednesday, August 01, 2007
Mac Mini colocation
www.macminicolo.net (Seen it referred from here, being mentioned for their superb consumer care).
As tongue-in-cheek as this sounds at first, yep, these guys do actually provide managed hosting of Mac Minis (you can send one to them, buy one from them at Apple's prices, or even rent it). The idea is a bit weird, but makes sense if you need a dedicated server on the net, you want Mac OS X on it because you are familiar with it, and you don't want to shell out for an XServe. Oh, and yes, you can run Mac OS X Server on Minis if you really need it.
Monday, July 30, 2007
Fun and woes with VNC
So, we are at a holiday in Palma de Mallorca momentarily. Unfortunately, we could only bring one of our Macs here - my MacBook Pro ' and had to left wifes 20" iMac at home for obvious reasons (it is not too portable, although I did lug it to UK and back once when it was my primary machine). Our hosts however have an oldie G4 eMac. Since both of us need a machine frequently, I tried to remedy the problem using VNC - Vine VNC server on the MacBook, Chicken of the VNC client on the eMac, so one of us can work logged on in their account from eMac while the other person sits at the MacBook proper.
It mostly works fine. But then, there are annoyances.
First annoyance - the system works on two desktops, except when the user of the remote desktop wants to use VMWare. In that case, using fast user switching hangs the remote VNC sesion. No big deal - we will just have the one of use not using it work remotely. (Surprisingly, that is me - Kriszti actually has some Windows-only software she runs).
Second, much bigger annoyance - keyboard incompatibility. I tried both an Apple keyboard plugged into the eMac as well as a Windows keyboard only to realize there's a deeper reason why I can't punch in many characters (curly brackets included - kills any attempt at coding). The reason is that the MacBook still maps keycodes accordingly to its builtin keyboard. I learned this after many futile attempts to press certain keys and evoke any kind of response, I finally brougt up the Keyboard Viewer, and it pretty much displayed the MacBook Pro uiltin keyboard layout... If I try to press keys on a full size keyboard that aren't present on the laptop's built in keyboard, theyre simply ignored. Quite a lot other keys aren't in the expected place. I guess it's partially to blame that all external keyboards in the house are Spanish and the laptop's is Hungarian... But even switching the keyboard layout in the remote machine to "Spanish ISO" doesn't help anything... I tried to plug in one of the USB keyboards in the laptop, to solve the keyboard mapping mismatch issue, as the OS would then try to map according to that. Didn't work.
So, it's far from being a perfect remote GUI solution, unfortunately. It's okay for casual checking of e-mail (mailbox being on the other machine) but really not much else. Sigh.
Thursday, July 26, 2007
First cut at the JVM dynamic languages metaobject protocol
You might remember I was musing about coming up with a framework library for extensible metaobject protocol to be used for dynamic language runtimes on JVM a while ago. The main thing it would give all those language runtimes is interoperability: you could write your program in mixture of JavaScript, Ruby, Python, etc. - using the best language for a particular subtask (or better yet, cherry-picking existing components regardless of their language), and still pass objects created from code in one language to code in another language, and have them all see those objects as being no different than their native objects.
Well, since talk is cheap compared to working code (and also because if I can express a concept as clearly as to have a computer execute it then I can probably make people understand it better too), I have a first version of the implementation, not yet fully complete, and first and foremost for the purposes of soliciting feedback from the community, available now.
(For the record, I blew several days of my vacation in Palma de Mallorca on getting this code into publishable state and suffered numerous scorns from my wife so far for doing so. Goes with the territory, both ways... ;-) )
The initial announcement was made on the JVM Languages group, go read the details (including where to find the code and documentation) there if you're interested.
Thursday, July 05, 2007
Brief report from a Neil Gaiman signing event
I'm officially crazy in lots of ways. A particular kind of crazy I am is the one I demonstrated yesterday, when I went to a Neil Gaiman signing event in Budapest.
What's crazy about it? Well, probably nothing if you actually live in Budapest. I don't, so for one thing, it's crazy driving 2 hours to Budapest in pouring rain with near zero visibility. Then it's mildly crazy standing in a queue for two hours (part of it in rain outside the bookshop that was the signing venue. No umbrella). The final crazy (although strictly necessary after the first one) is driving home after the event in pouring rain with near zero visibility after dark. Of course, I'm really crazy because I still feel that spending six hours and about forty litres of fuel is a good investment in return for getting seven of my Gaiman books dedicated, and am totally happy about it.
Y'know, in my environment, barely anyone knows who this guy is (now that I think of it, this says something about people surrounding me. I also cannot lend my copies of his books to many folks around here to spread the culture 'cause they're all in English - I don't need no Hungarian translations, most of my friends however can't read the English originals). So I was fairly surprised when I arrived at the bookstore to find a queue extending into the street. The event itself wasn't even too formal - Neil announced it on his blog few days earlier citing as the reason lots of e-mails from local fans (yours truly included) who asked if he could please arrange a signing during his two-week stay in Hungary, seeing how he's otherwise not really often present in this corner of the world.
As for the venue itself, it was the Sárkánytűz ("Dragon Fire"), a bookstore specializing in fantasy books, card games, etc. I really couldn't help feeling that the signing was organized in a wrong location. I look with disdain at most of the contemporary fantasy literature. Most of it is just bad pulp fiction, its authors unable to free themselves from the cliché dominated by elves, trolls, halflings, dragons and knights. Ironically, a genre called "fantasy" really lacks authors that would have any real imagination. Neil Gaiman, on the other hand creates completely original stories, with completely original creatures, and the worlds he paints in his books intersect with our reality. Nothing could be further from the Tolkien-imitating cliché of elves and dragons permeating most of what the bookstore had to offer.
There's apparently a funny phenomenon associated with people queueing in the street in Budapest. Namely, it raises curiosity in strangers. While I was still standing in the part of the queue that extended out in the street, I was approached twice - once by a nicely dressed lady in her fifties, once by a guy resembling a hobo who tries to disguise it. They both inquired about the nature of the event, the wording of their questions implying they were hoping for some sort of a sale. When I told them it was a signing, the guy who looked like a hobo in disguise quickly lost interest. The lady asked who is signing, and when she didn't recognize the name, she asked (seeing how it's a fantasy bookstore) if it is "some sort of fantasy" to which I replied that it definitely isn't. "Then it is sci-fi, right?". This instantly reminded me of "we have both kinds of music" line. I replied patiently that no, it isn't sci-fi either. Then what it is? Well, how do you summarize Neil Gaiman in a single sentence? You don't. I tried to explain to her that she could think of him as maybe a modern day equivalent to Edgar Alan Poe (which I know you might disagree with, as it's both oversimplification and also plain incorrect, but that was the best I could come up with quickly at the spot :-) ) Anyway, she did leave after this...
So, after two hours of queueing I finally got in front of the man himself, got to shake the hand that wrote all those stories and look into the eyes behind them all those same stories were born. Yes, why, I was impressed, even though Neil is really a very friendly and approachable guy (well, approachable through standing in a long queue, but that's barely his fault. I mean, it's really my fault for not reading more obscure authors). Driving up on the highway I had plenty of time to imagine all kinds of witty dialogue I might get into with him, but the cruel reality was that there were still lots of fans waiting for their turn, so it would've been rude to hold them up for inappropriately long time, so we only did a bit of a politeness chat, and I handed over all the seven books I brought for dedication. It'd really be foolish to expect anything more from a signing event, really. I got a drawing of a cracked heart in my copy of Fragile Things - very appropriate. Also, the original printed dedication for Anansi Boys is actually made for easy personalization, which he totally exploited. I can almost see how Neil came up with it after signing his books for years, and felt very smart about it when he wrote it. (If you don't know what I'm talking about, don't worry, just buy a copy of Anansi Boys and read the dedication. Of course, you can also read the rest of the book if you're so inclined, but that won't help you in better understanding what I just said. But it might be worth your time for unrelated reasons, though.)
I also asked whether he has (or at least has a promise to get) a book of Hungarian folklore tales, to which he replied that he actually got one last week and is halfway through it already. If he didn't, I'd have offered to send him one, which was an idea I got while reading The Monarch of the Glen novella from Fragile Things, seeing how it incorporated a motive from Norwegian folklore (namely, a huldra), and Hungarian folk tales definitely have their share of marvels waiting to be incorporated into contemporary literature (I certainly know, I read lots of those to my kids). Anyway, getting Neil to read some of those tales is already been taken care of, hooray. We'll be waiting for the results :-)
A very nice touch at the signing was Neil's daughter Maddy, who was handing out cookies to people standing in the line and later also offering sandwiches at the signing desk. I really needed a bit of refreshments before hitting the road home, so I was really grateful for those as well. I asked Maddy when will she give back her Dad's blog to him, and she said it was her last day as his guest blogger, but she lamented that she can not write the entry because she's here at the signing. I remarked that she could use an exotic technique known as "pen and paper" and later type it up in front of a computer; I have no idea if she took the suggestion, however her goodbye entry was up at 10:01 PM, which I don't actually understand as I can't imagine the signing was over by then and even less that they could reach their hotel room by then - I left at about 9:15, and the queue of waiting fans still extended through the bookstore to the door (nobody waiting on the street anymore though).
Barcelona
So, Kriszti and me have been to Barcelona last week. Nominally, I went to speak at the TSSJS Europe, realistically I attended the conference just long enough to deliver my talk. That's what you get for taking your wife with you, who insists you spend the time going around the city and seeing places, instead of attending, say, Gregor Hohpe's talk about event driven programming (that one I really would've wanted to hear, but alas, I was stuck sightseeing Sagrada Familia instead; woe is me).
Barcelona must be one of the most joyful places I've ever been. The atmosphere of the whole city is amazing, the buildings, the people, everything is vibrant and alive. Architecturally, they have wide main streets with a very wide pedestrian area (usually with greens, benches, and fountains) in the middle, and lanes for cars surrounding it. Drivers are very mindful of the pedestrians and will wait for them to cross the street even when they (the cars) have the green light. Patiently.
Then there's Sagrada Familia. I don't think I've ever been as impressed by a cathedral as I was by it, especially since this is the first one that I can't view purely as a historical monument, main reason being it's still being built. You step into it, and it's full of construction workers. Cathedrals are always monuments to ages in which they were built, and this one is a monument to our age instead of some long gone one, making it even more easier to feel like it you have a personal connection to it. Y'know, like when you visit a cathedral and they tell you "... the XY cathedral has been built for 300 years..."; well, this one is still in its first 100 or so years :-)
Architecturally, it is also quite amazing, and departs from "traditional" cathedrals in quite a lot of places. Pillar structure is such that pillars branch at the top, giving the illusion of trees, further emphasized by the ceiling that also tries (quite successfully) to look like foliage.
Then there are various other Gaudi projects in the city: Casa_Milà, Parc Güell, and so on, all definitely worth several hours of one's time.
We also went to see an evening flamenco show with a dinner (courtesy Klaasjan) which turned out really great, both the flamenco performers and the dinner were terrific. And on the previous evening, we hung out at the hotel's "bierstube" (which is to say, a spanish attempt at emulating a german beer place). A funny moment was when the staff kicked out Kirk and Cliff because they attempted to come in with two boxes of externally acquired pizza. The attitude of the staff was especially rude considering we were otherwise on a table with few hundreds of euros on the tab anyway, so what does it matter if two pizzas are eaten without generating a profit for the venue? Anyway, the guys ended up eating their pizzas from their boxes on the street. Kriszti and myself joined in for a bite (no photos of this overly casual event, regretfully :-) ).
On saturday, wife and me also had the pleasure of meeting with Jon Revusky and his wife Nuria (they're long time Barcelona residents) for lunch. (We were treated to really copious amounts of really great tapas in Cervezeria Catalana.) Jon and me are collaborating on FreeMarker for about five, six, or even more years now, and this was the first time we actually met personally.
The only dark side of the trip was airline luggage handling. Needless to say, they (Lufthansa + Newco, their ground services provider in Barcelona) lost our luggage between our connecting flights. That in itself isn't that bad, but they didn't deliver it until the day of our flight back! So we went out to the airport on sunday, got our boarding passes (from a really helpful lady at the Lufthansa ticketing desk), then went through security into the transit area, found the baggage room, stood in the line at the Lost+Found office, finally got to the front of the queue, been taken to a back room with hundreds of suitcases, found our own, went out from baggage room, back to departures to drop off the suitcase for the trip home, then again through security into the transit area. Simple, huh?
When we arrived home to Budapest, we went to the Lufthansa office at the airport to file a claim for luggage delay. The ladies working there said they don't deal with it as they don't have sufficient capacity to handle all such claims (I can believe that. They certainly gave the impression they have no capacity for anything whatsoever) and they told us to contact their office in the city, for which they can only give us e-mail address and fax number. The lady at the desk then proceeded to jot down the e-mail address on a piece of paper: fly@lufthansa.de. I respectfully noted that it seems unlikely that this'd be the e-mail address of the city office in Budapest, but she was insistent that it indeed is. I was too tired to argue. I spoke to Kirk on the phone today, and he said Lufthansa office at the Budapest airport is the "most useless place on the planet". I tend to agree.
All in all, the Barcelona trip was great. Got to see a marvelous city, met some new folks and met again some already known ones, eaten lots of good local food, drank some sangria and local wine, did one talk, watched flamenco dancers, seen a great sunset by the sea. What more to expect? (Well, on-time baggage delivery, maybe.)
Thursday, May 31, 2007
ROTFL
OMG!!11 ITZ AWSUM!!
(No, the blog hasn't been hacked. Yes, click the link. See for yourself.)
IM OUTTA YR LOOP
Friday, May 18, 2007
No online Ant API?!
(Warning: disgruntled rant below.)
Ok, so I'm writing an Ant task. I'd need the Ant API. Google "Ant API". First link is http://ant.apache.org/manual/api/index.html. Yeah, sounds about right; click. To my surprise, instead of the familiar JavaDoc page, I get this:
Apache Ant API has not been generated
If you see this page online at ant.apache.org, it is not a bug, but on purpose. We do not provide an online version of the API docs, they are included with all our distributions.
Now, just how arrogant is that? "On purpose"? Just exactly what purpose is that? Are you guys really this much bandwidth starved?
Just for the record, the JavaDoc is not included in all distributions. Y'know dear Ant team, since the Apache license pretty much takes away the power from you to dictate what's in a distribution, some distributions won't come with JavaDoc.
Like that obscure one that ships with XCode for Mac OS X, installed in /Developer/Java/Ant directory. I guess no one uses that anyway, right? I mean, what Java developer would be as insane to use Mac OS X, let alone the development tools that ship with it, right? I'm probably the only such loser on the planet, I can't imagine anything else can explain why noone has noticed this yet and told you about it, so you removed that silly claim from the page where the API docs should have been, and replaced it with, well, with the API docs. Give me a break.
You could say how that's Apple's fault, and I'd agree with you. But that you aren't helping at all is ridiculous, with as little as to keep an online accessible API docs for one of your highest-profile Java projects. In 2007, what Java open source project aspiring to claims of professionalism would purposefully refrains from hosting its JavaDocs on its site? If for nothing else, then all other factors being equal, people want to use their computers with least effort. With a computer connected to the Internet, the easiest way to get to an API is punch "$projectName API" into the browser's built-in Google search box and then hit the first link. Compare this to trying to find the relevant index.html on one's hard drive. Yeah, we're that spoiled.
Anyway, the first site on Google's search results list that can afford the horrid bandwidth and storage burden of hosting the Ant API is http://www.jajakarta.org/ant/ant-1.6.1/docs/ja/manual/api/help-doc.html. Kudos to them, and shame on whoever is responsible for this lameness in the Apache Ant team.
Wednesday, May 16, 2007
XStream
Whenever I'm faced with a programming problem to solve, the logical first thing I do is to rummage around the 'Net, trying to find an open-source library (preferrably non-GPL, i.e CPL or BSD licensed) that already solves it. Because reinventing the wheel is costly, and most of the time the problems are such that I can't imagine to be the first to have came across them.
Few months ago, I had a requirements for passing objects between JVMs. "Doh, serialization", you'd say. Right. Except that the other people on the project felt it'd be very helpful from the diagnostics perspective if we could inspect the objects. So the logical idea - serialize using XML instead of Sun's binary serialization format. Turns out that the JavaBeans API actually provides support for something similar in the java.beans.XMLEncoder and XMLDecoder classes. It will serialize/deserialize JavaBeans using their public property getters and setters. But we really wanted something that operates on the ObjectInputStream/ObjectOutputStream idiom and serializes fields.
Eventually, I found the XStream project at CodeHaus.
The logical second thing I do when I found an open-source library is examine it. Unfortunately, lots of stuff floating out there isn't of particularly high quality, and branding also doesn't guarantee quality, be it "Apache" or "Codehaus" or anything else.
Now, after using XStream for quite a while now, I must say: well done! It delivers on its promises, the code is architecturally sound, and is insanely customizable. The generated XML is rather compact - i.e. if a value of the serialized field is exactly the same type as the declared type of the field, the type is not written out in the XML. Only if a subclass is used as the actual value. What's more, types can be aliased both on serialization and deserialization. This allowed us to ship objects from a GUI frontend JVM to a DB backend JVM, and have them being serialized/deserialized as different subclasses of a common abstract superclass hierarchy. In the GUI frontend, they were deserialized as classes with GUI operations, on the DB backend, they were deserialized as Hibernate enabled classes. Just brilliant.
I know you can do it with Sun's default serialization as well, but you must override resolveClass or replaceObject in the object input stream. Whereas with XStream, you could just configure the aliases in a factory once, and be done with it. Very elegant.
It is also possible to plug in custom serializers for certain types - i.e. we had to make sure Hibernate-specific collection classes were serialized as plain Java collection classes. It probably took me all of a 20 minutes to implement it, relying on documentation and the XStream (quite clear) source code.
Then there's a rather ingenious default mechanism for backreferencing objects. You can configure XStream to slap an "id" attribute on each element representing a serialized object, and when you need to reference it from a later written object, refer it by the ID. Anyone could come up with that, it's rather trivial. But XStream doesn't do that by default. Instead, by default it doesn't write any ID, but if a later written object needs to backreference an earlier written one, it'll use an XPath expression that selects the earlier object's element! (You even have a choice between absolute XPath or XPath relative to the referencing element.) Again, very elegant.
And to top it all, XStream is not for XML only any longer. Since the serializers are pluggable, they currently also have a JSON serializer, which sure can come in handy if you're AJAXing. (I'm not, so can't give an account of experience in this regard.)
All in all, I'm currently very happy with XStream; if you need to serialize/deserialize your Java objects to/from XML or JSON, I recommend you give it a try.
Tuesday, May 15, 2007
My current open-source TODOs
I'll admit that I feel a bit thin-spread lately regarding my open source activities. There's just too much stuff going on that I'd need to attend to one way or the other. Of course, this is all competing for whatever leftover bits of my time after paid work ("urgent/important"), family, an attempt to reinstantiate a regular workout habit (both "not urgent/important") and the also inevitable everyday interruptions ("urgent/not important"). Just to make it clear, OSS work is to me in the same "not urgent/important" quadrant where family and workout take place.
In no particular order my current OSS activity goals are:
Implement support for invoking Java vararg methods from FreeMarker(this actually goes off the list, as I completed it on the quiet sunday afternoon while kids were at a birthday party)- Implement support for JSP 2.0 SimpleTag interface in FreeMarker's JSP taglib runtime
- Fix the JSP taglib lookup mechanism in FreeMarker's JSP taglib runtime
- Make the overloaded method invocation + varargs into a reusable library so I can support vararg methods in Rhino and also have other open-source dynalang communities leverage it
- Support vararg methods in Rhino
- Cleanup the LiveConnect implementation in Rhino (primitive booleans not coerced automatically, and in general overloaded method resolution could be better, and it doesn't use JavaBeans bean info, and...)
- Just generally try to attend to bug reports in Rhino
- Attempt to refactor Rhino-in-Spring to reuse Spring WebFlow as much as possible, 'cause having two webflow implementations on the same base code would really help it emerge into a flexible foundation worth submitting as a "Java Web Flow" JSR
Friday, May 11, 2007
Fish Tank
I'm an avid reader of about a dozen different webcomics. Today, I just discovered another one, and it's just incredible in its originality. It's the Fish Tank, about adventures of three fish living in an aquarium (and quite often venturing outside of it). What's original about it? Well, these fishes occasionally get rid of piranhas (on an occasional visit to Brazil) by deorbiting a communication satelite on top of them using a satelite telephone, or get rid of a cat using explosives. Or are (in the current storyline) kidnapped by, of all things, telepath moths. Rooms, houses, or city blocks sometimes get demolished, or Alaskan wild forests set to fire. In general, there's lots of "Mission impossible" action going on, with fish improvising all sorts of devices from stuff found in their tanks and household items (not necessarily plausibly, but that's really not the point of it; they actually have laptops too!). The drawing is loveably sketchy (but consistent), and the characters are incredibly well built, complete with their love/hate relationships and plenty of ingenious throwaway jokes and inspired dialogue. Totally love it.
Thursday, May 10, 2007
Dynamic language interop plans in .Net world too
I've recently explored the topic of in-process cross-language interoperability (think Python program using Ruby created objects etc.) in my "Adapters or Navigators" article.
Interestingly, I stumbled across posts in Jim Hugunin's (Jython and IronPython founder) blog recently about the exact same topic in the context of .Net - they seem to already have some implementation ready as part of their Silverlight initiative. Here are the posts:
A Dynamic Language Runtime
The new Dynamic Language Runtime (DLR) adds a small set of key features to the CLR to make it dramatically better. It adds to the platform a set of services designed explicitly for the needs of dynamic languages. These include a shared dynamic type system, standard hosting model and support to make it easy to generate fast dynamic code. With these additional features it becomes dramatically easier to build high-quality dynamic language implementations on .NET. More importantly, these features enable all of the dynamic languages which use the DLR to freely share code with other dynamic languages as well as with the existing powerful static languages on the platform such as VB.NET and C#.
Next two posts deal with a sort of "universal adapter", a common object model required for cross-language interop:
One True Object (Part 1)
One True Object (Part 2)
In the part 2, he illustrates how a dynamic language runtime queries an object "Do you have member X?", and the object thinks "I'm a Python object, so I'll look it up by Python rules". He envisions the IDynamicObject interface that all object implementations of all languages must implement for interoperability.
This is exactly what I claim to not necessarily be the best approach in my "Adapters or navigators" article, but that having pluggable metaobject protocols instead of an expected interface might be a more flexible solution.
It's nice to see though that other people also have this problem in their crosshairs :-)
Wednesday, May 09, 2007
Parents of kids with Down syndrome campaign against prenatal testing for it
The New York Times carries an article today titled "Prenatal Test Puts Down Syndrome in Hard Focus".
It reports how in US, families rising kids with Down syndrome are campaigning against a new, widely usable prenatal test that can be used to screen for it. 90% percent of pregnancies where the fetus is diagnosed with Down get aborted. Some parents are worried that as population of people affected with Down syndrome dwindles, the care programs for them will also disappear.
But they are also worried about a much more serious problem than that. The practice is well within the area of eugenics, trying to draw a line between eliminating a genetic condition undesired by the would-be parents versus lessening the diversity of the human race. The genetic condition can be viewed as undesired since Down syndrome results in having somewhat weaker physical features, being slightly mentally challenged, and having shorter life expectancy (49 years average), but most of these individuals are still able to live fully enjoyable lives in a loving family, even if they're placing a bigger burden on their parents, and parents who actually raise such kids and therefore have first-hand experience believe how Down is not a sufficient reason to deny those kids existence. I tend to sympathise with this point of view. From the article:
Sarah Itoh, a self-described “almost-eleven-and-a-half,” betrayed no trace of nervousness as she told a roomful of genetic counselors and obstetricians about herself one recent afternoon. She likes to read, she said. Math used to be hard, but it is getting easier. She plays clarinet in her school band. She is a junior girl scout and an aunt, and she likes to organize, so her room is very clean. Last year, she won three medals in the Special Olympics.
“I am so lucky I get to do so many things,” she concluded. “I just want you to know, even though I have Down syndrome, it is O.K.”
Friday, May 04, 2007
In-process cross-language object interaction: adapters or navigators?
There's a new article on my website titled "In-process cross-language object interaction: adapters or navigators?".
I'm discussing two typical approaches for object interaction between a "higher level runtime" (HLR - i.e. a scripting language runtime) and "lower level runtime" (LLR - runtime for whatever language the high-level runtime is implemented in, i.e. JVM or CLR, or even straight C).
The two approaches discussed are the somewhat more common "adapter" pattern, and the somewhat less common "navigator" pattern.
HLR implementations usually go for the adapter approach, but I argue that the navigator approach is superior to it, especially when you want to extend the object interaction from the HLR-LLR dimension (i.e. representing native Java objects in a JavaScript runtime written in Java) to an orthogonal dimension, namely have interoperability between two distinct HLRs running on the same LLR in a decently intuitive manner, without knowing of one another in advance (i.e. use objects created in JRuby from within Jython, without Jython knowing about JRuby at all).
This level of interoperability opens up new possibilities for people implementing software systems, as they become free to implement different subsystems in languages that fit the job most.
Discussion welcome in comments.
Monday, April 09, 2007
Calling Java vararg methods from dynamic languages
I'm adding code to support calling variable-argument methods (introduced in Java 5) from FreeMarker Template Language. What's the big deal, you might ask. A lot, I might answer.
As a matter of fact, it'd be a rather straightforward task if it weren't for a minor detail: overloaded methods.
When a method isn't overloaded, and you need to invoke it from a dynamic language such is FreeMarker, all is dandy and Bob is your uncle - you have to adhere to a single target formal argument list, easy as a breeze.
When a method is overloaded?
Ouch.
The thing is, with dynamic languages it's not as simple as finding the method that satisfies the mathematically precisely defined technical criteria known as "the most specific applicable method for given actual argument types". That's what Java compiler has to do, and believe me, Java compiler has it the easy way. With dynamic languages, we start from one step behind. We operate in another language, y'see, and we first must figure out how to marshal the actual arguments to Java types. Of course, the optimal way to marshal them might depend on the actual method we chose to invoke among all overloads. Which in turn depends on the Java types of arguments we use for invocation.
Chicken and egg. Catch 22. Strange loop. I wrote logic in FreeMarker to handle this years before, and it was quite involved even back then, and we didn't have variable arguments back then.
I had quite a few false starts on it, I'll admit that. Lot of code written and then rolled back. Lots of hours spent thinking about the issue. I have something that works now, written mostly while sitting on the porch of my parents' house where I retreated with wife and kids for Easter. But I'm not committing it to SVN repo just yet - need to test it a bit further before I unleash it on the crowd of lab animals, er, early adopters of FreeMarker 2.4.
There are some downright sinister corner cases, i.e. invoking
foo(a, b)
when you have:
public void foo(SomeClass a, SomeOtherClass b);
public void foo(YetAnotherClass a, SomeBozo b...);
Do you prepare the array of arguments for reflective invocation as [a,b], or [a,[b]] if your algorithm can not know at preparation time whether the fixed arg or the vararg method is going to be invoked? (Under the hood, varargs must always be passed as arrays). My decision was to prepare [a,b], and on the fly convert the last argument to one-element array if it happens that the vararg method was chosen (the ambiguity only arises if the vararg method would receive exactly one argument in its variable part, and would not arise if it would receive zero or more than one - you see what sort of arcane corner cases crop up in dynamic setting).
My ultimate hope is that I can create a sufficiently generic implementation for this that I can share it with other projects as well - Rhino and JRuby, for starters. All dynamic languages on JVM could benefit from a soundly implemented library for this functionality, at least until the bright future arrives where the whole world has already transitioned to JVMs that implement the hypothetical invokedynamic bytecode instruction. Although even if we had it, I actually doubt that the "strange loop" coordination required between marshaling arguments from another language to Java and selection of the most specific method would be handled by it - such marshaling is language specific, and while it can be abstracted behind an interface, extending with interfaces is a mechanism used by libraries in Java, not by the JVM itself, so it looks to me this'll remain a job for the library.