Tuesday, May 25, 2010

I think this qualifies as a 'gotcha'

I was writing some Java code today. I'm writing a plug-in for Eclipse that will actually insert some Java annotations (e.g., @Override) into your code automatically.

Unfortunately, every time I ran my plug-in, the annotations were being inserted without the @ sign (e.g., Override). I couldn't figure out what was going on, looking at the code that generates the text:

String annotation_text = ...
StringBuilder sb = new StringBuilder('@');

Finally, I hovered over the StringBuilder constructor to figure out which constructor I was calling. Low and behold, I'm calling this one:
java.lang.StringBuilder.StringBuilder(int capacity)

In other words, by using single quotes, I am specifying the character '@' which is then implicitly cast to an int. Hmm... This doesn't seem so bad at first, but there's an asymmetry in the API. If I use this constructor:
new StringBuilder("@");
I get the behavior I expect, a string builder initialized to the at sign.

Moreover, there are append methods that take a single character:
Adds the single at sign character to the stream. So, knowing about this method, and the string constructor of the StringBuilder, I naturally assumed there was a character constructor as well... NOT SO FAST BECKMAN.

Tuesday, May 18, 2010

Trip to Agra

Classic Taj
Originally uploaded by DixiePistols
This past weekend I went to Agra! Agra is a city in India famous for the Taj Mahal, the landmark that Americans like me most identify with India. Since I'd never been, and this is my third trip to India (!!) I felt like I really should make the trip.

To cut to the chase, it was awesome. I was expecting a cool building that was kind of a tourist trap, but this was an amazing building that was kind of a tourist trap. Probably the most amazing piece of architecture I have ever seen. And as they say, pictures do not do it justice. It is much larger than I'd imagined, and thanks to its elevated location, it appears to be hovering in mid-air. The two hours that I spend at the Taj Mahal were more than worth the entire weekend trip.

And what a gnarly trip it was... It's not really that easy to get to from Bangalore. I flew to Delhi early Saturday morning, and then took a train to Agra. On Sunday, I hired a car from Agra to Delhi, and then flew back to Bangalore. It was stressful as hell. The train was hot because I wasn't in an A/C section because I didn't make reservations early enough. (Lesson: make train reservations early in India!) I took a car on the way back because the only trains still available were at like 6 in the morning. The trip, which was only 200km, took four hours. I spent almost the whole time alternating between worrying about dying (my driver was, um, aggressive) and worrying about missing my flight.

But some things went well. Even though my itinerary was crazy it all worked out. The hotel where I stayed (The Taj Plaza) was cheap, pretty nice, within walking distance of the Taj and full of helpful employees. Recommended. Also, on Sunday morning I went to the breakfast buffet at the Oberoi Amar Villas hotel. The hotel itself is unbelievably expensive, and the buffet was expensive by local standards, but the food was really good! Recommended.

Tuesday, May 11, 2010

Validating XML against a Schema

If you ever have to write XML, and you need that XML to validate against a schema (and by the way, if you ever had to do this, I'm so sorry...) it turns out that Visual Studio is a great environment for this. It will tell you where you're XML is wrong and more importantly WHY. So many of the online validators would just say you have a problem without giving you any suggestions on how to fix it.

For the record, I am using Visual Studio 2008 Professional.

Wednesday, May 5, 2010

Yes. I am in India.

I made it to Bangalore! The trip was extremely painful, mostly because it was long, but it did have a few highlights:
  1. In Charles de Gaulle airport there is a "resting" room that has lounge-style chairs that you can actually lie on and go to sleep, and it's free! What?! I took a lil' nap there in between my two nine hour flights.
  2. I saw five movies. Best one? Probably Crazy Heart. Worst one? Definitely Bride Wars.

At Microsoft things are about like I remember. TONS of paper work to go through on the first couple of days, but I actually managed to make some progress on my project. There are a few things about India that I forgot to remember:

  1. The mangoes are ridiccio! There's a snack area here at MSRI that has free stuff for us. They have mangoes, not the green kind but the yellow kind, and they are soooo good.
  2. The streets are unbelievably hectic. I'll spend the first week jumping at the sound of horns and fearful that I will be hit while walking on the edge of the street (because the sidewalks are not really navigable).
  3. People call you "boss." Really love that.