dreadedmonkeygod . net

Welcome to the Grot

Nothing wrong with me that two good nights of sleep couldn't fix. Slept a solid 9 hours on Wednesday night, and another 8 hours last night. This moring I woke up a little after 7am, dozed until 8, then got up and headed in to work. I feel great, and can't wait to do a little trail biking this weekend.

On Monday, I got paid to write Perl. I feel dirty.

It parsed check-in logs from CVS and cross-posted them to Bugzilla. I started out with this script, which was, as advertised, grotty. Not that Perl is ever ungrotty, but it was just too much for me. I still would've looked the other way if the script had worked with little or no tweaking, but it didn't. And I couldn't read it easily enough to bring it to life, so I rolled my own in no time. It's readable, liberally commented, and works exactly as I need it to.

And I spent much of today with XSL. Turns out that this recursive-by-nature "language" chokes hard on overly deep recursive template calls. Solution: put enough structure in the source data so that XSL can just use the natural recursion, which works fine even for large trees.

I can see that a sample problem might be helpful in illustrating what's going on. I needed to take XML that looks like this:

<board>
  <coord x="A" y="1" value="X"/>
  <coord x="A" y="2" value="X"/>
  <coord x="A" y="3" value=" "/>
  <coord x="B" y="1" value=" "/>
  <coord x="B" y="2" value=" "/>
  <coord x="B" y="3" value=" "/>
  <coord x="C" y="1" value=" "/>
  <coord x="C" y="2" value=" "/>
  <coord x="C" y="3" value="X"/>
</board>

...and output this:

  1 2 3
A X X    
B X 
C     X    

It's harder than you think. And I couldn't find a good solution that scales. (The data I was working with had about 65,000 coordinates.) But it turns out to be trivial to write an XSL template to do this if your source data has a little more structure:

<board>
  <row>
    <coord x="A" y="1" value="X"/>
    <coord x="A" y="2" value="X"/>
    <coord x="A" y="3" value=" "/>
  </row>
  <row>
    <coord x="B" y="1" value="X"/>
    <coord x="B" y="2" value=" "/>
    <coord x="B" y="3" value=" "/>
  </row>
  <row>
    <coord x="C" y="1" value=" "/>
    <coord x="C" y="2" value=" "/>
    <coord x="C" y="3" value="X"/>
  </row>
</board>

So I backed up a step, added more flexibility to the code that was creating the output, and I'm home free.

The moral to the story: When formatting with XSL, your source data must contain all necessary information. Trying to compute implied information (boundaries, totals, etc.) with XSL doesn't scale.

Anyway, the rest of my time has been spent monkeying around with Ant, shell scripts, and SQL. Not a lot of Java work this week.

It's been a nice break. I burned out on coding there for a couple of months, but the solution, as always, is to invest more energy, scratch a few itches, and rediscover why I love doing this for a living.

Post a Comment

Name:
Email (Never, ever displayed.)
URL:
Remember me next time.
Comments (Sorry, no HTML allowed. Space paragraphs with a blank line.):