Review: Working Effectively with Legacy Code

September 30, 2005 at 6:40 pm


I’ve read a number of books about Test-Driven Development. There are a number of new ones, but most of them start with a clean slate where you’re writing code from scratch.


Working Effectively with Legacy Code is different. It starts with the assumption that you already have a codebase that doesn’t have tests and need to figure out how to start adding tests as you work on the existing codebase.


The book is organized into two sections. “The Mechanics of Change” are an introduction to TDD, tools, why you would want to do it, etc. The real meat of the book is the second section, “Changing Software”. Each chapter in this section addresses a different question, such as:



  • I can’t get this class into a test harness

  • This class is too big and I don’t want it to get any bigger

  • We feel overwhelmed. It isn’t going to get any better

And each chapter has a detailed discussion of the problem, the strategy or strategies you might use, and the tradeoffs involved. That last point is pretty important – the Agile community has more than its share of zealots, so there’s a lot of dogmatic advice out there. This book is the opposite – the author has clearly spent a ton of time applying his techniques to real codebases, and there are lots of interesting discussions out there. Even if you aren’t sold on the whole Test-Driven approach, there’s a lot of content that will apply to general refactoring.


This is one of the best books I’ve read in the last few years. Highly recommended.

Heart Rates and Climbing

September 27, 2005 at 12:26 pm

A couple of blog comments sparked the following question from Chris:

As I rode the Zoo my heart-rate hovered between 180 and 184. 184 is the absolute highest I have ever seen for me on a bike. My resting heart rate is roughly 56. Out of curiosity…. can anyone explain what it means that I have a higher resting heart rate and apparently a higher max heartrate than Eric.

That’s simple. I have achieved the morally superior lower heartrate, and it doesn’t matter how much faster you are, I’m going to be the better cyclist.

Don’t buy that? Well, it’s a simply matter of physiology. We aren’t surprised that certain people have larger hands, or heads, or ears than others, so it’s probably not a surprise that people have different sized hearts. My heart is simply bigger than yours. In fact, the stroke volume (the amount of blood pumped per beat) can vary as much as 4x between people. That’s an impressive difference, though it would admittedly be more impressive if I hadn’t pulled that “4x” number out of thin air.

I used to work out with a woman whose heart rate at comparable level of exertion would be be something 1.6 times my heart rate. I’d be hanging out at around 120, she’d be up above 190. No problem for her, but a great indication that things like “heart rate ranges” and “220 minus your age” don’t work well with the whole population, and may be pretty bad for specific individuals.

As you may already know, increase in stroke volume is one of the primary adaptations from training.

The Physics of Bicycle Climbing (oh, and a few words about a stupid bicycle climb)

September 25, 2005 at 12:46 am

Last night, when I got home, my wife asked me if I’d read Eldon’s blog. A quick look showed that he was trash talking about today’s ride. Me, I don’t need to trash talk or work to psych anybody out, because I’m confident in my climbing skills. So confident, in fact, that I thought I was a virtual lock to make it to the top of the hill, and even pick up some time over my previous ascent.

Despite the fact that I run BicycleClimbs.com, and unlike Eldon, I’m not a particularly gifted climber. I’m learning how to suffer (more on that later), but my physique is not suited to be first up the hill.

The sport of bicycling has lot of variables. Wind and aerodynamics play a huge part, as does drafting. But when you get to the steep hills – unless you’re talented to ride up them at meaningful speeds – it’s mostly about power/weight ratio. I was thinking about this a few days ago, and dusted off some disused physics expertise.

First, we need to figure out my potential energy at the top of the hill. For that, we’ll use the following formula:

PE (Joules) = mgh

My bike and I weigh pretty close to 200 pounds (a few pounds less, but that doesn’t matter) = 200 / 2.204 kg = 91 kg. That’s the m.
Zoo hill is 1200 feet = 1200 * 12 inches = 1200 * 12 / 39.3 meters = 366 meters. That’s the h.
Finally, g stands for gravity, and for the earth, it’s 9.81 m/sec^2

So, that gives me:

PE = 91 * 9.81 * 366 = 330000 Joules (if I mess up on the significant digits, my wife will kill me.)

All that is left is to convert that to Watts. Conveniently, 1 Watt = 1 Joule / sec. I climb the zoo in 25:30, so

Climbing Power = 330000 / 1530 = 220 Watts

There’s some additional sources of resistance, but they probably aren’t that big for the Zoo, especially at the speeds I ride.

Eldon wrote that he did the Zoo last week in about 21 minutes (lets say 21:30). That’s a ratio of 0.84 to my time. To match that, I either need to up my power output to 220 / 0.84 = 262 watts, or I need to reduce my weight by the same factor to 180 * 0.84 = 151.2. I did weigh that much in high school, but I had less upper body muscle than I do now (hard to believe, I know).

So, class, what did I prove? Well, I proved that there was no way I was going to beat Eldon. But maybe there was another way. For the climb, I wrote up a few guidelines and printed them out, along with a map. Here’s what they said:

  • It’s tough to get lost. Just keep going up. When you get to the stop sign, turn left. When there’s a green gate on you’re right, you’re at the top, and it’s all downhill from there.
  • On the descent, turn left at the stop sign.
  • This is an unsupported ride, so if you stop, you will fall over.
  • Limit your speed on the first pitch. In fact, you should probably stay behind me the whole ride, just to be safe.
  • Those who reach the top may choose to coast back down to ride up with those who haven’t made it up yet. Those who haven’t made it up yet may choose to whack those who have made it with their pumps.
  • The organizers request that any riders who pass out attempt to do so that their bodies will roll onto the shoulder.
  • Those with something to prove should ride the inside of the hairpin. Those with a lick of sense should ride a more rational line.

I then handed Eldon a sheet and asked him to read them out loud, with the excuse that I didn’t want him to be the only guy who got to be funny.

What he didn’t know was that his sheet was special. All the other ones had an additional guideline which said:

  • (This guideline isn’t on Eldon’s sheet, so don’t ruin it). $20 to the top finishing rider who beats Eldon to the top. I’m not kidding on this one – I have the cash with me.

Yes, if I can’t beat Eldon myself, perhaps I can pay somebody to do it. Eldon claims that that is evil. Hmm. What did I read yesterday? Oh, yeah, “I will pay other people to interfere with my boss’s boss“. Yeah.

So, anyway, we did the ride, and I displayed my mad climbing skillz. I bumped my average heart rate up about 5 points, and got up in a time virtually indistinguishable from last time. And I wasn’t last to the top, though I should note that of the two guys arriving after me, one started 10 minutes behind me, and the second was about 5″ taller than I am.

But I am learning to suffer better.

 

The Double-E half-hour of Pain (You do Zoo, We do Too)

September 20, 2005 at 12:32 pm

One of my readers suggested a group ride of the Zoo, so I’m teaming up with the Phat Psyklist to put on the:

The Double-E half-hour of Pain (You do Zoo, We do Too)

September 24th, 2:30 PM at the base of the hill. Eldon said something about cake at the summit. If you want to participate, please send email or leave a comment so we have some idea how many people are showing up.

This is not a climb to be approached lightly. Proper preparation includes a well-maintained bike, good legs, a sufficient arsenal of excuses, and willingness to explore the outer limits of performance and whining.

Notes for first time zoo climbers:

  1. Start slow. Really slow. Lowest gear slow. Almost falling down slow.
  2. You’ll need to maintain your pace for somewhere in the neighborhood of half an hour.
  3. After about 0.8 miles, there is a hairpin turn to the right. Do not ride on the inside of the corner. The easiest way up is the outside of the turn, if traffic conditions permit (there is usually little traffic on the zoo)
  4. The first mile or so to the straight section is the worst. The straight section to the stop sign is harder. And the section after you turn left is harder still.
  5. The top is at the gate, and the road turns to gravel soon after that.
  6. Don’t descend the same direction – head west on 60th (ie left at the stop sign coming down from the summit)
  7. Ever climb Inglewood? The zoo is like riding Inglewood. In a higher gear. Four times in a row.

 

 

Cascade Spawning Cycle

September 19, 2005 at 7:53 pm

Sunday, I went on what will likely be my last organized ride for this year (regular readers are rejoicing right now).

Unlike some of the other rides I’ve done, this ride has a theme. As noted on the details page, this ride is based loosely on the salmon spawning cycle. You start next to Puget Sound in Myrtle Edwards Park (also hosting a “miles of fence and lots of big construction equipment” event at the same time), travel upstream to the Locks. That’s the “Chum run”, clocking in at 14 miles. Next up is the “Fit for a King” (as in “King Salmon”) loop at 33 miles, where you ride to Seward parks on Lake Washington, on to the locks, and then out to Puget sound, recreating the trip that a young salmon would take on its first journey to the sea.

New this year is the “Copper River Special” (named after seafood company in Alaska). This loop takes you around to West Seattle to Alki point, which is important to the salmon because it’s 11 miles in length (fun history fact – the Denny party landed at Alki Point in West Seattle in 1851. Arthur Denny, in a move to make his mark on the city, later named one of Seattle’s most prominent hills after himself. Disgruntled townfolk had it removed, and Arthur went on to found a hugely successfully 24-hour dining chain).

The copper river loop started at 44 miles on the website, morphed to 50 miles on the maps, and turned out to be 53 miles covering some of the worst pavement to be found in Seattle.

After winding along the picturesque Seattle waterfront parallel to the picturesque Alaskan Way viaduct (*that’s* why it’s “Copper river”!) (acting as a semi-permanent eyesore along Seattle’s waterfront), we headed across the bridge to West Seattle. I hooked up with a racer and his ex-racer friend (both wearing local team colors) for the trip around Alki, which was fast, bumpy, and a bit wimpy. We then headed back to downtown, up the hill, through the I-90 bike tunnel , and then down to Seward Park, the first food stop.

Following the “spawning cycle” theme, I had worked really hard getting from Puget Sound to Lake Washington, and then died after getting there. Unsure whether salmon get dehydrated, I decided to cover that front “just in case”.

In a rare nod to non-motorized transportation, the city of Seattle closes portions of Lake Washington Blvd for Bicycle Saturday and Sundays. Flat road, great scenery, no cars.

After skirting around Capital Hill (known for… well, you can search yourself if you want to know what it’s known for), the ride joined the Burke-Gilman trail, and led to Gas Works Parks, which has peerless views of downtown Seattle (over Lake Union), and some big ole’ rusty industrial equipment left over from when it’s use as a coal gassification plant.

At this point, things get a little hazy, but I managed to make it to the next food stop at the aforementioned Locks. I had reached the “just get this done” phase, and after a short rest, I headed out and up the steepest hills of the ride into Discovery park. There used to be a Navy base there, and it’s very eerie to ride through overgrown roads and tall fields of grass, with the occaisional perfectly painted and maintained structure in the middle of a field. Weird.

After finding our way out (markings were a bit vague), we headed on Magnolia Blvd, and then back along the trail to the starting point.

And therein lies the rub. To avoid the killer climb, the 14 mile loop goes the other direction on that same route, which means you have a mix of fast and slow riders going one direction and slow to very slow riders going the other direction. At one point there’s a small curved bridge. There were people walking their bikes, so I followed a slow group on the left, which ran into a group of walkers coming the other way and walkers trying to remount at the top. I decided to add to the confusion by getting off balance and falling off my bike, which sort of punctuated the experience. In my mind, it’s unacceptable for Cascade to let that sort of thing happen – if you’re going to use that route, you have to have people on both side make sure everybody dismounts for that bridge.

After my horizontal excursion, I headed back to the park for the end of the ride.

Rant #2 – why is finish line food so bad for you? I mean, I don’t mind a little indulgence, but when the only thing you can get is a burger on a white bread bun or some suspicious salmon (ah, the salmon theme again), it’s not the best of all worlds.

Recommended? Well, I don’t know. It’s bumpy, could be windy, and you have lots of inexperienced cyclists to watch out for (worse than Flying Wheels).

 

Classic Programming Resources

September 14, 2005 at 3:30 pm

 

The year was 1979. Or maybe it was 1980. I’d been programming for a couple of years, but didn’t have my own computer. *Nobody* had their own computer. But I did have enough for a magazine subscription.


There were only a few serious choices. BYTE was one choice, but it was – even in those years – not terribly exciting. Another option would have been Dr Dobbs (Full Name – “Dr Dobbs Journal of Computer Calisthenics and Orthodontia“), if I’d know that it existed.


The third option was a publication known as “Creative Computing”. IIRC, I forked out the princely sum of $15.98 for a two year subscription, and never regretted it. Creative had a unique mix of information, entertainment, and irreverence. I kept a few articles over the years, but the majority were tossed out.


Today I came across an archive of computer books of the late 70’s and early 80’s at AtariArchives.org, and among those are 3 “Best of” volumes from Creative Computing.


If you’ve been waiting for a good ASCII art version of Snoopy and Charlie Brown, you can find one. Or, if you need a review of Wumpus 2, you’re in luck.  


Now, help grandad back to his rocking chair, will you?