One week until Portland

Moving made running difficult during the past week, but tapering at this point is to be expected.

Weekly recap:

  • Saturday: 21 miles from the Dowd, all solo. I did my cross-Providence 13+ miler first, followed by the Freedom Park hill 7+ miler.
  • Monday: 2.5 miles (or whatever I do in 20 minutes) on a treadmill at the Siskey YMCA.
  • Wednesday: 10 miles from the Dowd in the morning, solo.
  • Thursday: 7.5 miles from the Dowd in the morning, solo.

A little over 40 miles for the week. Not bad considering my scheduling difficulties. Current forecast for Portland weather looks to be cool and clear. I’ll be happy enough just with cool.

This morning I ran 8+ from the Dowd at a reasonably brisk pace by myself, then met Udit for the Hit the Brixx 5k. With a little help from my “professional” pacing services, he was able to cut his personal best down from a 31+ minute 5k to under 29 minutes. Congratulations Udit! Susi and Jeri ran the 10k and finished well, and Jeri’s sister April joined them for a nice cool-down 5k. I hear Mark and Barb were also in the 10k, but I didn’t see them.

C# tip: Think of anonymous methods as static

Anonymous methods in C# can make your code more readable, and they are very convenient. They also have magic powers. For example, when first using them they appear to magically persist local variables! Magic, you say? To show this let’s create a delegate and assign a anonymous method to it, and within the anonymous method we access a local variable:

Magically, the value in local variable i is printed to the console! How does this happen? It’s not quite magic; a closure containing the variable is conveniently created on the heap for the anonymous method referenced by the delegate, giving our formerly stack-based value type a nice long life.

Warning: Prepare for disappointment if you expect to create multiple instances of an anonymous method, each with different version of local variables. Examine the following:

Contrary to what you might expect, the console does not print 0, 1, and 2. Rather, it prints 2 three times. Why? A single closure is created for an anonymous method in C# code, even if it is referenced multiple times. Therefore, think of an anonymous method (and the closure containing any formerly local variables it references) as static; any modification of the local variable is reflected anywhere it is referenced, even though it’s a value type and it’s modified after the anonymous method is referenced.

If you want different behavior, you must avoid using local variables and pass state into the method yourself. A struct containing the delegate and its data works nicely:

Laptop internets via Blackjack

Need access to internets on your laptop but you don’t have a cellular data card? If you have a bluetooth Windows Media smartphone (a Samsung Blackjack, for example) and an appropriate data plan, just run WindowsInternet Sharing from File Explorer on your phone, select “Bluetooth PAN” under “PC Connection”, then connect to the device with your laptop.

Two more weeks until Portland

On Monday I had another gym-inspired attack of the back pain. Have I finally learned my lesson? I tried out some light shoes (Gel-Speedstar) that I plan to use during the marathon, and got more Landreths for training.

Weekly recap:

  • Saturday: 23.5 miles from the Dowd. Starbucks 10 mile out-and-back with Dan, then my Sterling/Roswell/cross Providence 13ish miler. Brutal but I did fine.
  • Monday: Fast 1.5 miles on the treadmill after lifting weights.
  • Tuesday: 10.5 early-morning miles from the Dowd with Susi.
  • Wednesday: 10.5 just like Tuesday, but with more back pain.
  • Thursday: 10.5 just like Tuesday and Wednesday. Back pain mostly gone, but tired.

Not quite 60 miles for the week, but topping 50 tired me out this week. I’m feeling a lot more confident about my endurance base.

C# tip: Reading settings from a different App.config

If you’ve used a standard C# App.config, you’re familiar with the ConfigurationManager object in System.Configuration:

This reads, by default, from a file similar to your application’s executable; if your executable is “MyApplication.exe”, your config file is “MyApplication.exe.config”. If you want to read from a different file, or just name your config file differently, and still have the same convenience, you have a few options. First, you can use the exact code as before, but set a property in your app domain to reroute the static ConfigurationManager calls:

You can use a slightly different strategy that is almost as convenient, and may be more flexible in some situations. If your config file is named “SpecialConfig.config”, create an instance of Configuration from the ConfigurationManager as follows:

If the file does not end in “.config”, you need to create an ExeConfigurationFileMap and use a slightly different call:

You could get the value in a single line of code, but keep in mind you’re risking a null reference exception if the value isn’t present. To be safe, do something like the following:

Three weeks until Portland

This week I’ve finally acclimated to my new gym routine, and my running form has been strong. I’m still very weak when I lift my arms to almost any position, but it’s a pleasant, constructive feeling. My core is just fine.

Highlights:

  • A particularly tough outing at the Whitewater Center, where I ran every trail. I probably set new personal bests on Goat Hill and Toilet Bowl trails, and felt great at the end. Mike’s chase to the finish put it over the top.
  • Before dawn on Thursday I saw and heard a huge owl perched on a stop sign on Roswell St. His hoot and wingspan were very impressive as he took flight; I don’t think he is a very big fan of runners.

Weekly recap:

  • Saturday: 20 miles, as stated earlier. Very strong.
  • Sunday: 6.5 miles from the Dowd with J & S, nice and easy.
  • Monday: 1.5 miles (10 minutes) on treadmill, fast.
  • Tuesday: 11 trail miles at Whitewater Center with Mike. Felt great, pushed very hard.
  • Wednesday: 1.5 miles (10 minutes) on treadmill, very fast.
  • Thursday: 10 miles from Dowd, easy pace.

Total is about 50 miles, with plenty of energy for my 22 miler tomorrow morning. I plan to go the first ten at a easy (8:30?) pace, then run the last twelve at around a 7:30 pace. I’ll likely be solo for the second part, which will be good mentally.

Dead server; writing about programming

Our server died this afternoon, and through no fault of ours we lost about two weeks of data. I mean, why not wait until all the disks in your RAID array are dead before trying to replace them? Were we not paying for disk redundancy and back-up, this would really be no big deal. As it stands, I favor trying to host our domains elsewhere.

In brighter news, I’ve noticed most of the hits to this site are to anything involving C#. This being the case, I’m going to make a conscious effort to write more about “programming stuff” I find useful, like this sort of thing.

C# tip: Checking for empty strings

A common task for any C# programmer is to check the contents of strings. Is a given string initialized, and if so, is it empty? Consider a common check:

This technically works fine, assuming the string was initialized. The following check is theoretically a little more memory-efficient, but is equivalent due to JIT optimization:

I personally think string.Empty is a tiny bit more readable than “”, but that’s subjective. Technically, checking the length of the string is the shortest code path:

Keep in mind that, while strings are special objects with an intern pool, they are objects nonetheless, and will be null references until they are initialized. Your code must take this into account, or you will be faced with sloppy null reference exceptions. One also could argue that code flow based on differences in null vs. empty strings is bad practice in the first place.

I believe using the string.IsNullOrEmpty() method is the best habit to form when checking strings:

Check explicitly for null or string.Empty only in special cases. Remember, good code habits are contagious.

New iMacs, iPods nice in person

While at the mall tonight shopping for glasses, I slipped into the Apple store for another of my three-minute visits to check out the new hardware.

  • The new iMac is a gorgeous kitchen computer, even with the horrendous glare of its glossy screen¹. Unfortunately I’ll never buy an all-in-one.
  • As I expected, the new iPod Nano is very nice in person. It looks fat in pictures, but it’s a slick little wafer in the hand. If the market is still there for music players, I suspect this one will charm anyone who touches it.
  • The new aluminum face on all the iPods, including the “Classics”, is a nice smoothly beveled surface. Nicer on the Nano than the heavier Classic 160GB, but a nice departure from the plastic lacquer look.
  • The user interface on the Classic is much slicker than the old UI, with plenty of smooth motion and fades. I’m not very fond of the split-screen strategy, and it’s a bit slow moving back in its menus, but they’re doing a lot of cool with not much processor.
  • I typed about twenty seconds on the new thin Mac keyboards, and I wasn’t disgusted. It’s no M, but the feel is tolerable, and the look is undeniably slick.

¹Was I the only person who hated the glare of CRT screens in 1998, even on a gorgeous 19″ Wega? Overly saturated colors are not worth the glare, people!

Four weeks until Portland

Training went as anticipated this week, with a slight scare due to extreme post-gym soreness. Ironically, my resumed gym efforts to head off back problems actually caused pretty major pain on Thursday and Friday, to the point that I was afraid I had pulled a muscle. Today I’m significantly improved, and am just as sore in my arms as I am in my lower back. The lesson to be learned is to not let a strength training regime lapse, and, if I do, to not do to much on the first time back. Duh.

Recap of the week:

  • Saturday: 20 miles from the Dowd with Dan (two out-and-backs on the Providence Starbucks route), 8 minute pace.
  • Sunday: Crowders Mountain solo (staircase + over-top trails in about 55 minutes, followed by fire road). Approximately one and a half hours, equivalent to at least 10 miles.
  • Monday: Matthews Labor Day 5k. Approximately five miles counting the run there and back.
  • Tuesday: Whitewater Center trails with Mike. Approximately 12 miles, moderately strong pace.
  • Wednesday: One reasonably quick post-weights mile on treadmill.
  • Thursday: Early morning run from the Dowd with the ladies. 13+ miles, moderate pace (hard effort, considering back discomfort).

Total is over 60 miles. Judging from this morning’s McMullen run with Dan, I should be peaking just in time. Starting at 5:30 (very, very dark at McMullen), I did 20 miles at approximately 7:40 pace. First 16 with Dan in the 7:30s, two more moderate effort, strong finish with mile 19 at 7:10. I’m very pleased with the speed when considering the extreme muscle soreness everywhere other than my legs. Shoulders and back aching for hours at a time is no fun.