October 27, 2008

Wind Shift

Filed under: Sailing, Uncategorized — dave @ 11:13 pm

Today wasn’t that cold, but there was a fair breeze blowing. Not a gale like there was last night, but definitely some movement in the air. It is a mixed blessing, because it seems like this type of weather makes for some of the best sailing, but at the same time makes normal people just not that interested.

Story: (I expect that I’m remembering parts wrong, Mac and Dylan: correct/embelish as necessary)

Last year, when I had finally been out to the boat enough that I was more than ballast, and I felt I could legitimately be called part of the crew, we needed to move the boat off the T-head and into a slip. If we were going to drive all the way out there, we wanted to make a day of it, but there was a storm coming in and it looked pretty hairy, so we waited to see if it would hit or not.

At some point we realized that we needed to move the boat whether the storm hit or not, so we mounted up and headed for the club. As we arrived, the storm was clearly visible and was definitely going to be fairly intense, but as we moved the boat a funny thing happened and we somehow talked each other into sailing into the face of it.

I feel I should pause for a moment and tell people that it is normally very safe to come out sailing with us. Travis is fairly calm and it’s basically impossible to roll a Capri 25 without a Spinnaker (a sail which we don’t have). HOWEVER: if there is a storm, all bets are off, the boat won’t roll, but lightning doesn’t care.

The wind that day was coming out of South by South-West (IIRC) and it was blowing hard. On the way out of the cove we passed a few sailboats making their way into dock, and as we got out into the lake a few motorboats were gunning it home. We got on a starboard tack and headed straight down the lake towards the dam, dipping a rail most of the way. For those who have never experienced it, the rail is the perimeter of the deck, when we dip a rail on Caprica, it means the wind is blowing so hard that the boat is tilted about 35-40 degrees and the edge of the deck is below the water line. You know you’re alive when the deck is below water.

About half a mile out of port, the last boat on the water, a Sheriff, motored past and just kinda stared at us as we sailed straight for the storm; no wave, just a stare. As we flew closer on that crazy wind, isolated drops portending the rain to come, we could see the water falling in sheets, obscuring the houses as the worst of the weather reached the shores of Lake Travis. And as we neared, we wondered when we would finally wise up and turn around. When we saw lightning to the East, our resolve finally broke and we turned around.

The process of turning the boat is characterized by a flurry of activity as the skipper yells out and the crew responds with rote calls of “READY”. The boom flies, the jib cracks and lines get released and reeled in with frantic tugs and are pounded home into their cleats. But that day was different.

Texas is a mercurial state when it comes to weather and I’ve yet to meet a woman as fickle as Lake Travis. And that day, whether it was a freak coincidence, divine providence or something earned by the extra swig of the boat whiskey that we knew would be needed for that afternoon but the wind did something that I haven’t seen since. As Dylan pulled the helm and we swung around, the wind decided to follow and we found ourselves pointing straight back at the club still close hauled and heeled over with the breath of a thunderstorm coming over our starboard bow. We held that course all the way back in and tied up the unchristened Caprica just before the worst of the rain came in.

Some of the best wind comes in these Fall and Winter days, but it is hardly cruising weather. Summer is great for hauling friends as cargo, but I’m looking forward to some of the days when the wise stay home, and only the crazy will chance the lake.

JSON: Way better than XML

Filed under: Programming, Technology — dave @ 5:11 pm

When we were architecting ElectionMap, one of the things that we had to decide on was how we were going to get data down from the server. This being 2008 and us being primarily web developers we were of course using HTTP/TCP/IP, but that left us with a stream of bytes, if anything the most dangerous thing you can give two software developers, witness UNIX.

During an early coding run, Dylan added some values to a plist file which is really just some Apple window dressing around XML, and were it not for my adamant hatred of XML, that probably would have been our data interchange format of choice. But luckily for my cause, the iPhone parses XML the same way your car burns vegetable oil, only after a lot of messy work and even then it probably runs slower (I have no specific knowledge on the performance characteristics of vegetable oil, but the metaphor sounded good in my head). However, after reading Jeff Atwood’s anti-XML screed and my experiences writing iPhone apps for redacted, I knew of a Better Way ™.

JSON (JavaScript Object Notation) is a pretty darn spiffy data interchange format that has 4 data types: dictionaries, arrays, strings and numbers. If you really care about the thing GIYF, but the reason I bring up it’s structure is that it allows it to be on a single pass looking only at the first character. { = dictionary, [ = array, " = string, \d = a number. The code to parse this on iPhone is hosted at Google Code under the TouchCode project and though its interface is a little clunky at times, it's fast and gets the job done.

Because of using JSON, our polls.json file consists of entries like the following:
"WA" : [
4,
"As of Oct 22\nMcCain: 43%\nObama: 54%\nPollster: Rasmussen"
]
which resulted in a 3775 byte file. (we could get it down to 3625 if Dylan removed the 3 extraneous spaces per state), but I think our xml would probably have looked something like:
<state>
<name>WA</name>
<vote>4</vote>
<text>As of Oct 22\nMcCain: 43%\nObama: 54%\nPollster: Rasmussen</text>
</state>
which at an average of 43 bytes more per state, would result in a 4775 byte file, or a little over a 30% increase in size. This 30% seems pretty silly to stress about, but the polls.json file has been downloaded over 40,000 times so far for a little over 150MB of traffic. On election day we’re hoping to get absolutely hammered on /elect/results.json, which means we want to be getting the files out the door quickly and get the connections torn down. 30% less file bandwidth, 42% more requests/second if setup/teardown was free (lies, damn lies and statistics).

Obviously, there are some things I could do to reduce the lead JSON has over XML like using attributes instead of full blown entities. You could point out that the JSON cheats by using an array instead of a dictionary, but I’m not even sure if you can use that cheat in XML. The point is that JSON is as expressive as XML, and is a lot more concise.

I considered YAML, since Dylan mentioned it. It definitely wins in the human readable category, but the reason is that it shares that same perverse faith in humanity’s ability to distinguish between tabs and spaces. It frequently seems more reasonable to me to end sentences with semi-colons than periods and I put curly braces around single line blocks in C/C++/Java. You can have my redundant structural markup when you can tell the difference between a tab and 4 spaces on a default vi installation.