August, 2004

  • Eric Gunnerson's Compendium

    Conditional Attributes


    There's an extension to the conditional concept that shows up in Whidbey. It's not in Beta1 (well, to be more correct, it doesn't really work in beta 1), but it will be functional in beta2.

    If you put a conditional attribute on an attribute definition, that instructs the compiler to only place that attribute in the assembly if the symbol is defined. This allows you to have "debug only" attributes that don't take up space in your release assemblies.


  • Eric Gunnerson's Compendium

    Conditional Methods


    I saw an internal post today about somebody who wanted to get rid of their #if DEBUG statements in their code, because they were ugly. That made me realize that there's a feature that not everybody knows about, known as conditional methods.

    Consider the following code:

    using System;
    using System.Diagnostics;

    class Program {
        static void Main(string[] args) {
            #if DEBUG

        static void DebugMethod1() {

        static void DebugMethod2() {

    In my call to DebugMethod1(), I've used the traditional #if approach to only compile the call if the DEBUG symbol is defined. But in the call to DebugMethod2(), I've used a conditional method that has the same effect - if the DEBUG symbol is not defined, it's as if the call isn't there. That includes any side effects from parameter evaluation - they don't happen.

    Note that the docs on the ConditionalAttribute class are a bit misleading.

  • Eric Gunnerson's Compendium

    Missing comments and blog problems...


    Our blog software got upgraded a few days ago, and that upgrade include comment moderation, as an attempt to deal with comment spam.

    The upgrade didn't fully work right, so sometimes things are broken. If you see errors, I apologize. The only thing I know that might help is trying again later - it seems to have something to do with the load balancing on the hosting servers, so if you get the right server, it works fine.

    I've turned off comment moderation. I love reading the comments on my blog, but when I have to click the "okay to post" link on *every* comment and then close a browser window for every comment, it's not worth it. It seems that most of the comment spam happens to older posts, and is therefore at the end of a conversation rather than in the middle, so for now I think the cure is worse than the disease. Let me know if you're finding the comment spam bad.

  • Eric Gunnerson's Compendium

    New Challenges


    From C# Builder to C# User...

    Dateline: Redmond, Building 41


    Eric Gunnerson called me early this morning, asking me to come by to talk with him. When pressed, he would only reveal that he had news to impart that would “Rock the very foundations of society... Or be a good filler piece. Definitely one of those”.


    So, I grabbed my notebook and headed over, wondering what the morning would yield. Eric is the noted author of “Bad Roomba!”, “Hangin’ with Generics”, and the critically acclaimed “Tantric Snacking”, so I expected something big.


    Me: So what’s this important news?

    Eric: Well, the news is that I’ve decided to leave the C# team to join the Windows Movie Maker team as a developer.


    Me: What does that mean?

    Eric: Developer? It’s someone who writes software. Are you new here?


    Me: No, what does your leaving mean?

    Eric: Well, first of all, it means that instead of showing up at building 41 every morning, I’m going to be showing up at building 50 instead. At least for the first month or so – I expect that after that, I’ll occaisionally find myself in the building 41 lobby, feeling very confused.


    Second, it means that instead of working to help further the C# language, I’ll be using the C# language to help build a really cool app on top of Avalon and Longhorn.


    Third, it means that some of the things you currently see me doing you’ll soon see other C# team members doing.


    Oh, and it probably means that those of you who meet directly with the C# team will be subjected to fewer bad puns, though I obviously can’t make any promises.


    Me: Why are you leaving?

    Eric: To put it simply, it was time to move on to new opportunities, explore new vistas, climb every mountain, ford every stream... Where was I? Oh, that’s right...


    Every year I spend some time looking at what I’m doing (both inside and outside of work), and evaluate what I want to do for the next year. This year, when I did that, I realized something.


    I wasn’t enjoying life enough. I was going to say, “I wasn’t having enough fun”, but that sounds too frivolous. I was doing too many things that I wasn’t excited about doing. And I wasn’t spending enough time with my family, and even when I was with them, I wasn’t engaged.


    So, I stepped back and looked at what was wrong, and what I realized was that I had lost passion for my job. I’ve always felt that you spend too much time at work to spend it doing something you don’t at least like, and preferably love.


    My attitude towards my job had bled over to other parts of my life. I hadn’t coded for fun in a couple of months, nor had I launched any rockets, played with microcontrollers, gotten any house projects done, or experimented much in the kitchen.


    So, what did I want to be when I grew up? That was the question.


    I considered a number of different options. Could I be a full-time author? What about a trainer? What about getting into the construction business? Or going back to the QA side at Microsoft?


    I mulled these over for a few days, but my thoughts always came back to code. In the years before Microsoft, I wrote a lot of code, and I miss that feeling of immersion when you realize that 4 hours have passed without you really noticing. It’s a state of being as much as a state of thinking.  There’s an interesting parallel to long-distance cycling, as I can reach a similar state there. Or, strangely, finish carpentry.


    In the Microsoft world, “code” == “dev”, so started to explore dev positions.


    Me: (starts) huh? Sorry, I think I dozed off for a second there. Umm... so why the Movie Maker team?

    Eric: I looked at a number of different openings. Unfortunately, the C# team and most of Visual Studio is still written in unmanaged code, so the positions there tend to be COM and C++ oriented. I’ve done a fair bit of C++, but if you’re going to move, why not find something you really want to do? No offense to COM programmers, but “ick”.


    I also looked at the teams that write frameworks, but decided it would be more interesting to work on an end-user application.


    I did several informational interviews, which are informal meetings between a manager and somebody who is interested in that team. It’s how both parties figure out whether it makes sense to spend the time on an interview loop. Why is it a “loop”, anyway? It’s not like you talk to the same person more than once...


    The Movie Maker team is doing some really cool stuff, and I’ve had a soft spot for graphics since doing so meant you wrote your own graphics library for a ReGIS terminal and then shot movies one frame at a time. By yourself. In a dark terminal room. On Saturday night. Plus, it’s C# code, working with all the cool Avalon stuff, and it’s a small team. Oh, and I used to work with one of the devs on the team, way back in my VC++ days.


    I’m really excited about the team and where they’re (we’re) going.


    Me: Coming at this juncture, how do you think your departure affects the C# team’s chances of winning the pennant?

     Eric: Well, it obviously makes it harder for them to contend for the Division Championships, but I believe in this team, and I’m confident that they’ll find a way to continue their winning ways. I don’t think it’s going too far to say that “one person does not make a team”.


    Me: Will you still be involved in the community? Will customers still see you at conferences?

    Eric: I’ll still be writing my blog, though over time I expect it to morph from a blog that has a small amount of useful content about C# language design to one that has a small amount of useful content about using the C# language and writing for Avalon and Longhorn. I’m certainly going to continue providing valuable information, such as useful gift giving tips (link).


    For conferences and other events, I don’t really know the answer to that. Perhaps. I hope so.


    Me: When will you update your more-than-a-little-out-of-date book on the C# language?

    Eric: You mean my C# book from Apress, still available for the ridiculously low price of $34.95? No comment.


    Me: Tell me a funny C# story

    Eric: Okay. Two stories.


    The first one is a language design story, and I’m not really sure I can do it justice, but I’ll try. When we were working on the numeric types, the question arose around naming the signed numeric types. What would name the signed and unsigned byte types? We had int/uint, long/ulong, etc. We were discussing sbyte, and not terribly happy about it, when I pointed out that we already had precedence for doing “s byte”, with the “s hort” type. Then Scott suggested we abandon the current system for a different one, using “short”, “tall”, “grande”, and “venti”.


    Things deteriorated rapidly after that.


    Second story. Way back when the compiler was first coming online, I got one of the early drops, typed in “Hello world” (or some suitable variant), and went to compile it, but there was something wrong with the compiler, because I just got the command prompt back.


    I went and asked Peter Golde for help, and he came into my office and said, “did you do a directory?”. And there is was, Hello.exe, just sitting there. I’d never run into a compiler that ran so fast that you couldn’t tell that it had actually done anything.


    Me: What exactly are you going to be doing in your new team?

    Eric: Initially, I’ll be working on the small “v” of “Movie”, but I hope to move up to the “i” after a few months, and perhaps, if things work out, someday I'll get to work on one of the Ms...


    Movie maker is a fairly small team, so I’ll be working on different things – UI, transitions between clips, and likely writing a few wrappers around some unmanaged code.


    Me: When are you leaving?

    Eric: Over the next few weeks, I’ll be transitioning and vacationing. My last day in the C# team is 9/3, and my first full day in the Movie Maker team is 9/13.

  • Eric Gunnerson's Compendium

    Arrays inside of structures


    Sometimes when doing interop, you want to have an array embedded inside of a struct. For example, something like:

    struct data
        int header;
        int values[10];

    that you either used in a call to interop, or with unsafe code to deal with an existing format - something like a network packet or a disk record.

    You can do this in current versions of C#, but it's ugly. The most obvious way is:

    struct Data
        int header;
        int value0;
        int value1;
        int value2;
        int value3;
        int value4;
        int value5;
        int value6;
        int value7;
        int value8;
        int value9;

    But that's a bit ungainly, though, you *can* take the address of value0 and then use pointer arithmetic to access the various "array elements". There's a somewhat shorter version:

    [StructLayout(LayoutKind.Sequential, Size=44)]
    struct data
        int header;
        int values;

    Setting the size to be 44. If you want to have more than one such array or have fields after the first one, you'll need to use LayoutKind.Explicit and put a FieldOffset attribute on every field.

    In either case, you access the "array" by getting a pointer to the values field, and using pointer arithmetic.

    To make this a little cleaner and less error-prone, in C# 2.0 we've added a fixed array syntax, allowing you to write:

    struct data
        int header;
        fixed int values[10];

    and getting the exact same behavior. You can then treat values as if it's a "c-style" array, using indexing, etc.

    Because the underlying implementation is still using pointers and there's the possibility of going outside the allocated space, code generated using this feature requires using "unsafe", and therefore requires elevated privilege to execute.

  • Eric Gunnerson's Compendium

    An answer, and a link.


    Rachel posted this excellent link that answered my question. Thanks.

    And Wim posted a site that is one of my favorite sites.

  • Eric Gunnerson's Compendium

    Wish you were here...


    “Wish you were here” has always been one of my favorite Pink Floyd songs, but as I listened to it this morning, I - as I often do - wonder what Waters was referring to.

    Or, to be more specific, which war was Waters referring to?

    Though Waters wrote at length about WWII in The Final Cut, I don't see how “Did you exchange a walk-on part in the war for a lead role in a cage?” can be anything other than Vietnam.

    What do you think?

  • Eric Gunnerson's Compendium

    "It's only a model"


    I mentioned that I bought my wife a trebuchet. Here's a picture of it.

    And where does one go to buy a trebuchet?

    Well, duh.

    Kim's is the tabletop version.

    Oh, and if you don't know what “It's only a model” refers to, I pity you...

  • Eric Gunnerson's Compendium

    Special birthday presents for her...


    (Kim, make sure you don't read this, as it will ruin the surprise)

    My wife's birthday is coming up in a couple of weeks. I generally do a decent job at presents (how many other guys do you know that got their wife a trebuchet?), but I decided I needed some help, and went on over to Let'ssee what they recommend, shall we?

    Body Fat Monitor

    Yes, there's nothing that makes a girl happier than a gift that says, “you're carrying around a few too may pounds”. While you're at it, why not get her a copy of this book:

    That will really finish off the evening right.

    I don't think I'm going to be buying any of these, though giving the home DNA profiling kit is sure to make her wonder about your intentions.

  • Eric Gunnerson's Compendium

    RSVP 2004



    From Wikipedia, the free encyclopedia.

    Groupthink is a term coined by psychologist Irving Janis in 1972 to describe one process by which a group can make bad or irrational decisions. In a groupthink situation, each member of the group attempts to conform his or her opinions to what they believe to be the consensus of the group. This results in a situation in which the group ultimately agrees on an action which each member might normally consider to be unwise.


    It hit me about mile 50 on Friday. There was really no other explanation. I was riding north along highway 9, in the rain, as I had for the past three and a half hoursm, and it hit me.

    There was something wrong with me, with us, with all the riders around me. As I've mentioned in the past, there has to be at least something wrong with you to willingly put yourself on bike for 7 hours of riding, but granting that that is normal behavior, it's certainly less normal to do it in the kind of weather we had.

    But the majority of the riders not only decided to continue, they decided it was a good idea to continue. And continue we did...


    It had initially looked like a great weekend to be riding - the 90 degree weather had departed, and we were in a nice mid-70s pattern. Thursday was perfect, but the forecast was for showers. I trolled around to different news sites (what is King 5 TV thinking? - do they actually believe that I'm going to register just to get a weather forecast?), looking for better news. I finally ended up on the NOAA site, which said, "Likely to be the rainiest day of the summer".


    It's not that I hadn't ridden a fair bit in the rain this spring - I had. The problem is that when you're exercising hard, there's really no such thing as "breathable" clothing. You either have clothes that breathe well, but get wet quickly, or you have clothes that don't breathe well, hold in your sweat, and you also get wet quickly. Cycling makes this especially bad because you don't only get the rain, you get the spray off your tires. I put on my SKS Race Blade mini fenders Thursday night, which will keep the spray from my back tire off of my back, but it's won't keep the rain off totally.

    Friday I woke up to dry streets. Cool. But as I drove across the 520 bridge a few drops started to spatter on the windshield of the truck. Bad news. I got there at around 5:30, hoping to meet up with a friend to leave by around 6:00. For various reasons, we didn't get around to leaving until right at 6:30AM, as it started to rain. The first big hill of the day was up out of Woodinville, and I rode in my smallest gear, standing up here and there. Most of the riders were in pretty good shape. Along the segment from Snohomish to Lake Stevens, one of our team flatted, another went back to help her, and we rode on to wait at the stop. By this time I was really wet and cold on the arms (didn't put on my arm warmers), but relatively dry on my torso, and my leg warmers and neopreme boot covers were fairly dry. We waited at Lake Stevens (mile 30) for about 25 minutes, and by that point I was starting to shiver in earnest, so I told Bill that I had to bail, and rode really hard to get warm again. The ride to Mount Vernon wasn't much fun - I was reasonably warm, but you could either ride by yourself, or you could draft, and get a stream of road water into your face. I did a bit of both, and with my rear fender, I was pretty popular as a group leader.

    The last couple of miles into Mt. Vernon (70 miles) were over ground down pavement, and I think I got a big of taste of what it might be like to ride on cobblestones. Not fun at all, especially uphill, so I ended riding down the center turn lane. Suffice it to say that it was not the only time that I bent the traffic rules over the two days.

    The rest stop was a challenge. I needed to grab some food to supplement what I had brought alone (I get tired of sports bars and fig newtons after a while), and take a "nature break", but every minute off the bike I was cooling off. I got back on the bike after a bagel, a banana, an oreo, and a refill of my two litre camelback (I sweat a lot when I have my shell on). I was *really* cold when I left, and rode hard for 15 minutes to get warm again.

    And then something miraculous happened. As we rode to the west, the rain stopped, the skies cleared a little, and as the roads slowly dried, we did as well. I arrived at the base of Chuckanut drive - the last series of big climbs - in a group of 3 in good spirits, and rode the whole section with a rider who was doing RSVP as a training ride for a tour around Oregon. There are some painful climbs there, but none were too steep, and I made it into the finish at Bellingham in good shape, grabbed my backpack, and rode the 4 miles to my hotel (109.4 miles).

    Saturday dawned with drying streets, and I rode back up the hills to drop off my backpack (note to self - book your hotel early), and headed off towards the border. I hooked up in two or three good pacelines and we flew across the flats to Lynden at around 20 MPH (which is quite a bit faster than I'd ride by myself). There are two interesting things about the border. The first is that there's a road named "boundary road" that we rode on the US side, across the ditch, another road, this time in Canada. The second was my exchange with the Canadian customs officer:

    Her: Where are you going?

    Me: Vancouver

    Her: Where are you staying?

    Me: At a hotel, downtown.

    Her: What hotel?

    Me: I don't remember

    Her: Who made the arrangements?

    Me: I did. I just don't remember the name - it's in my bag.

    Her (shaking her head): Thanks. Enjoy your stay.

    The problem was that I was in the zone, and when I'm in that mode, I'm not spending a lot of time on rational thought - I'm just riding.

    The ride to the next rest stop (35 miles) was uneventfull, except for one really painful climb. I tanked up on water, ate a banana, and a bagel with peanut butter. The sun was intermittent, and it was wonderful. After the ride comes a short ferry trip, and then a ride up north, all the way to the Burrard inlet, for a final short rest stop (60ish miles). After a quick gel, I got on the Barnet highway, and realized two things.

    First, I only had an hour or so left. That was nice.

    Second, my legs felt really good. That was nicer.

    So, I decided to hammer (or do my best approximation) for the last hour. The Barnet highways is mostly up, with only a few downhills, and bears a striking relationship to one of my training rides in gradient, so I rode it hard, uphill from 10 to 15 MPH, and passed a lot more people than I expected. The remainder of the ride was up and down on the crest of the hills, down into Chinatown, where a group of 10 of us got lost together, and then finally screaming along the waterfront and up a hill to the finish.

    Overall, the ride was great. I felt good most of the time (with the exception of the rain), and the organization was really good, with the exception of a few marks that washed off in Vancouver. Kudos to the folks at Cascade.

    My training was about right, though I would have like to have ridden a bit faster (I averaged about 14MPH the first day, and the mid 14s the second day (lots of stop and go)). I may do it next year, and I have this crazy idea that I might want to do STP in one day next year...

  • Eric Gunnerson's Compendium

    Nested Using Statements


    I got a comment on the language feature post, asking about an easier way to write:

      using (StreamWriter w1 = File.CreateText("W1"))
          using (StreamWriter w2 = File.CreateText("W2"))
              // code here

    You can do this by writing:

      using (StreamWriter w1 = File.CreateText("W1"))
      using (StreamWriter w2 = File.CreateText("W2"))
          // code here

  • Eric Gunnerson's Compendium

    3 days and counting...


    Friday morning at 6:00 AM (!) I leave on my ride to Vancouver, BC. I'll ride about 109 miles on Friday (105 plus 4 miles to my hotel), and then another 82 on Saturday. That will total somewhere around 190 miles total, assuming I don't get lost.

    I feel reasonable confident about completing in two days, though I'm unsure how I'm going to feel the second day, as the most that I've done in two days is a 50/70 that I did back in June. I did an “out and back” on the first 35 miles of the route on Saturday (Bellevue to Lake Stevens and back), and though I did it reasonably quickly, it was not a pleasant ride. I'm in the “tapering down” phase - a short ride on Monday, and then a really short ride (~10 miles) on Wednesday night just to loosen my legs up.


  • Eric Gunnerson's Compendium


    Whatever your political leanings, you have to love this application of technology...
  • Eric Gunnerson's Compendium

    Interview with Alfred's Mother...

Page 2 of 2 (39 items) 12