How much weight should I lift?

Many people have asked me that question over the years; some have even asked when I was working out (that’s a no-no). The only appropriate answer to that question is another question: That depends, what are your goals?

Without setting goals, how do you know when your done? People often decide on a New Year’s Resolution of “lose weight,” or “get back in shape.” These goals aren’t good enough. Those people don’t last long. Working out for the majority of the last nine years, I’ve seen nine Januaries with tons of new faces at the gym; then, I’ve seen nine Februaries with all the same faces as those in nine Decembers.

Be specific with your goals; that’s the only way you’ll succeed. My last post said my resolution was to get back in shape. I lied to you, dear reader, I’m sorry. I’m tipping the scales at 270 right now and I haven’t squatted since I hurt my back last year. My goals are to lose 45 lbs without losing any muscle and squat my (smaller) bodyweight for three sets of 10 reps. That’s specific  as you need. For reasons I’ll get into, I won’t be hitting my goal for nine months. When setting your goal, don’t worry about timelines. If you want a 50-inch chest, you won’t get it within a year (well, unless you have a 49-inch chest). But once you achieve that goal, you’ll be so inspired; you’ll want to conquer the world next.

Setting a goal is good. But that goal is not going to do anything on its own. You also have to have a plan to achieve those goals. Making a plan is a topic for a later post. One more thing you’ll need to do is track your progress. If you’re trying to lose weight, weighing yourself every week won’t be good enough. You’ll have to track your calories and your progress in the gym.

The great thing about setting goals and tracking progress is that you can break it up, and set mini-goals on your way to the real goal. Doing this will re-enforce the need to track progress and will inspire you to keep going. So my first mini-goals are to go to the gym four times a week and to stop drinking sugary drinks.

So what are your goals?

Mens sana in corpore sano

A sound mind in a sound body.

When I was four, I wanted to be Superman when I grew up. My mother, being crafty (as in arts & crafty) and indulgent supportive, whipped up several S-on-the-chest-attached-to-a-cape-in-the-back things for the other kids, and a full Superman outfit for me, for my Superman birthday party. I remember nothing of this party, but the outfit still hangs in my office behind me.

Flash forward about 13 years, I was lonely, skinny; in my hormone-filled mind, I thought muscles would get me the chics. So I started going to the gym. My first real workout, if I recall, was disappointing: I couldn’t lift much. The next morning, I couldn’t lift my arms above my head because my back muscles hurt so much.

So I kept going.

I also started reading as much as I could about it. Every muscle magazine I could get my hands on was read cover to cover. I was stoked to get Arnold’s Encyclopedia of Bodybuilding for Christmas. Everything I read as gospel; I followed all the exercises to the letter; I weighed my food and timed my meals precisely; I made sure to never work out much longer than an hour; I ensured I was properly rested so I wouldn’t over train. All for the pursuit of a sound mind in a sound body. I was first introduced to that expression in a bodybuilding magazine editorial. The instant I read it, I wanted that.

Getting a sound body is simple – which I hope to explain to you in coming posts – but it isn’t easy. It requires patience, faith in yourself, and some discipline (although less than you think).

I had a sound body once. I’m going to get it back.

That’s my New Year’s Resolution.

“I was gonna blog tonight.”

I don’t know how many times I said that to myself over the past month. But after a while I could sense my readers were egging me on.

“Do it.”

“Do it,” they were saying, by not commenting and delete their subscriptions in their aggregators. I couldn’t let them down. I mustered my will and determination. I pressed on. There were times when I wavered, when I almost clicked that New Post link, but I resisted. All for you, dear reader. I didn’t want to bother you with my thoughts during the busiest time of the year.

I have no posts for the month of December 2005. That month does not exist on this blog. It might as well never have occurred.

This is not my resolution – it’s more of a tentative commitment – but I’m going to try to blog more. Not for me, but for you, dear reader.

Wait, don’t go, it’s for me, alright.

Writing about nerd-only topics like implementing your own UriParser is just too nerdy most of the time. I’ve decided to branch out and write about new things. I tend to read people’s blogs for the knowledge they can pass on; some are to make me laugh. That’s why I’m going to write about a couple things that my ego feels I know something about: the first, in support of this year’s resolution, is getting back in shape (I used to be a geek trapped in a hot guy’s body). Seriously, I’ve been feeling like an old man (who’s really fat)(and I’m only 27), and I don’t like it.

The second I’ll leave as a surprise (that’s called foreshadowing ;)) because I’m tired of typing.

Writing Your Own UriParser

I posted before about my displeasure using System.Uri for advanced scenarios. It won’t parse mailto-style URIs and extending it is just evil. Yet, I’d still recommend you use System.Uri for your URI needs, even if it won’t parse your URI.

 

Why? Well, with each version of the framework, Microsoft will work to make it better (at least that’s what they promise us). Your classes should version well across framework versions if you use their guidelines. Therefore, if you’re using FxCop to check your code against the guidelines, I’d recommend fixing violations of the “Use System.Uri instead of string” rule.

 

It just so happens that they kinda worked around my two earlier complaints: they deprecated those heinous protected methods; currently you only get a compiler warning, but it’s a start. They also provided a mechanism to parse URI schemes that the framework doesn’t know about: extend UriParser.

 

Before I start with the nitty-gritty details of building your own UriParser, I’d like to point out something amusing (well, amusing to total nerds who’d rather write about parsing URIs than play video games or watch Arrested Development). Go to the documentation on MSDN2 for UriParser, you’ll read this:

 

The UriParser class enables you to create parsers for new URI schemes. You can write these parsers in their entirety, or the parsers can be derived from well-known schemes (HTTP, FTP, and other schemes based on network protocols). If you want to create a completely new parser, inherit from GenericUriParser. If you want to create a parser that extends a well-known URI scheme, inherit from FtpStyleUriParser, HttpStyleUriParser, FileStyleUriParser, GopherStyleUriParser, or LdapStyleUriParser.

Notice something missing? That’s right, there is no fucking MailtoStyleUriParser!

 

Although I’m glad gopher is finally getting its due.

 

When the product feedback center came out, I figured I’d give it a shot so I entered a new feature request to get Uri to parse sip, sips and tel URIs. Read the comment at the bottom by Mr. Daniel Roth; you’ll see that writing your own mailto-style URI parser is easy because mailto is a “so rudimentary” scheme. That kinda begs the question: if it’s so rudimentary, then WHY ISN’T THERE ONE IN THE FRAMEWORK?

 

To add further to the fire, here’s the second paragraph from the UriParser class description:

 

Microsoft strongly recommends that you use a parser shipped with the .NET Framework. Building your own parser increases the complexity of your application, and will not perform as well as the shipped parsers.

Hmph.

I’m not going to go into detail about inheriting from GenericUriParser in this post. Instead, let’s suppose I’ve already done that. I think I should show you how to let the framework know about your parser so that it will load it and use it. I feel obligated to tell you about it because the documentation for these methods is really fucking terrible. Suppose I have two types called PresUriParser and SipUriParser both of which inherit from GenericUriParser. To tell the framework about these parsers, I call the UriParser.Register(uriParser, schemeName, defaultPort) method:

 

      UriParser.Register(new PresUriParser(), “pres”, 1);

       UriParser.Register(new SipUriParser(), “sip”, 5060);

 

That browser of yours isn’t playing tricks: the first call has a port of -1; that means no default port. The terrible, terrible documentation doesn’t show that. Nor does it show that every argument passed is validated and an exception is thrown if validation fails. The exception table should be the following for argument validation:

 

Type of Exception

Reason

ArgumentNullException

if uriParser, schemeName is null

ArgumentOutOfRangeException

if schemeName has length 1 or violates the rules for scheme names through myriad different ways.

ArgumentOutOfRangeException

if defaultPort >= 65535 or (defaultPort < 0 and defaultPort != -1)

 

But wait, there’s more! Suppose you get passed the argument validation, you’re not yet through the exception danger zone. Suppose you had code like this:

 

      PresUriParser p = new PresUriParser();

       UriParser.Register(p, “pres”, 1);

       UriParser.Register(p, “presence”, 5060);

 

This will throw an InvalidOperationException; apparently, you can only have one instance parse one scheme, even if your parser can parse multiple schemes. This makes sense, especially in multi-threaded scenarios, but does the documentation say this? Hell, no!

 

So you get the argument validation and now a potentially invalid operation. All undocumented. But I have more for you: a free set of knives!

 

Suppose you wanted to parse http on your own, with code like this:

 

  public class HttpUriParser : HttpStyleUriParser

  {

    public HttpUriParser() { }

  }

 

And then I register my parser, like so:

 

  UriParser.Register(new HttpUriParser(), “http”, 80);

 

Guess what? InvalidOperationException! That scheme is already registered.

Makes me wonder why there are all those parsers for known schemes if you can’t use them on the schemes that they parse.

 

There was a way to do it through the config file, but that content has been retired according to MSDN2. There appear to be some issues with Uri and security, outlined here in the breaking changes list. Perhaps Microsoft didn’t want others screwing up the perfectly good parsing for the known schemes, like they can by overriding the methods I mentioned last time.

 

Whatever the case, hopefully this quick article helps with the documentation for System.UriParser. Next time, we’ll get our hands dirty overriding methods and abusing Console.WriteLine().

Shipping with Bugs.

There have been a number of items on the ol’ information superhighway over the past week dealing with software quality.

First, once Visual Studio 2005 officially shipped on Monday, a number of high-profile .NET bloggers (WesnerFrans, Roy) posted about bugs that they experienced with the RTM version. Mini-Microsoft summed it up in a couple of posts (here and here).  There was this hint of outrage on a number of blogs that Microsoft would ship software with bugs; many claimed that VS 2005 was a piece of crap: There were some great counter-arguments from Paul Vick and Wesner. They’re right: it’s not crap, but it ain’t perfect.

Then Wired posted an article of the top ten worst software bugs in history. Scott Berkun had a great point on his blog about that: they’re the worst, not because of the errors, but because of the field for which the software was written (i.e. nuclear power plants versus your mp3 player.

I don’t know if Mr Sink wrote his latest article with all of the above in mind, but it’s certainly relevant. He talks about shipping with bugs. Eric, like Joel Spolsky, is a great writer who is able to say exactly what you’re thinking but in a way you’d never be able to. You can only exclaim “Yes! That’s totally it,” then get everyone you know to read it. So that’s what I’m doing.

Go read it: My Life as a Code Economist.