November, 2004

Posts
  • Eric Gunnerson's Compendium

    What's with those "break" statements?

    • 24 Comments

    One comment from my recent post was big enough to handle separately...

    Thomas wrote:

    I'll second the break statement. Why is it really necessary? Haven't you guys got enough feedback to acknowledge that wasn't the brightest move? You say it is there to please the C++ developers, because they are your main target.

    1. The C++ developers thought they were smart. You just stated they aren't, as you don't believe they can adjust to the new rules.
    2. You insult all the other programmers, as they are not the target. At least not more than a minor target.
    3. Finally, you insult everyone not on the C# team, as you think you are smarter than us. You could just have made the break statement optional.

    When we were designing the language, we decided we wanted to do something about the fall-through behavior of C++. In my years of writing C and C++ code, I had come across several cases where the behavior was troublesome. I believe that experience was widely shared among the language designers.

    So, we decided that any fallthrough would have to be explicit through a "goto" statement, which has the nice byproduct that cases can be re-ordered without a problem. We then had to decided whether "break" would be required, or whether it would be optional.

    We decided to make it explicit to make it easier for developers who write in more than one language - which our research data shows to be a significant percentage of developers. The question is not whether we think C# developers are smart enough to learn the new rules - the question is whether we wanted to force developers to remember two different kinds of switch statements so that they could save 7 characters of typing. Changing the syntax there would have been a gratuitious change. With this behavior, while there are different rules for *writing* switch statements, reading them is the same across languages.

    Having written code both in C# and C++ recently, I'm happy with the choice that we made. There are enough differences between the two languages that I'm happy not to have another to deal with.

    I admit that we haven't done the best job at explaining our language rationale. But now that you know the rationale behind this decision, do you think it was the right one?

  • Eric Gunnerson's Compendium

    C# - What's wrong with this code? - #1

    • 42 Comments

    Many months ago, I did a TechEd talk entitled "What's wrong with this code?". I've decided to re-target those snippets into blog posts. If you were at the talk, this may be boring, though I'll try to add a little anecdotal information in my answers.

    Here's the plan:

    1. I post the snippet
    2. You comment on what's wrong with it
    3. I post my answer, and any comments that I like
    4. Repeat until I run out of snippetts.

    Here's the snippet:

    switch (s) {
       case "a":
          try {
             HitA();
          }
          catch (Exception e) {
             throw e;
          }
          break;
       case "b":
          try {
             HitB();
          }
          catch (Exception e) {
             throw e;
          }
          break;
    }
     
    What's wrong with this code?
  • Eric Gunnerson's Compendium

    Halo2

    • 89 Comments

    Today I spent a few hours playing Halo2 - after waiting 90 minutes with 1000 of my closest friends outside the Microsoft company store.

    The campaign seems to be pretty good, but it has the usual problem with FPS campaigns, where it needs to strike a balance between giving you freedom of action and keeping you to a predefined path. Overall, it's been pretty good, but right now I'm stucking in a room with a floating guy (more would likely be a spoiler). If you know how to get out of that room, please drop me a line.

    I'll be on XBox live on and off. My gamertag is CeeEff.

  • Eric Gunnerson's Compendium

    What's wrong with this code? (#3)

    • 31 Comments

    No, you didn't miss #2 - it was about using "throw" rather than "throw e" to preserve the stack information, and I decided it wasn't worth a full post.

    This weeks snippet is also related to exception handling. Here's the code:

    void UpdateBalance()
    {

       try
       {
          balance = newBalance;
          db.UpdateBalance(accountID, newBalance);
       }
       catch (DatabaseException e)
       {
          throw new Exception(
       String.Format("Error updating balance on account {0} to {1}",
    accountID, newBalance), e);
       }
    }
     
    What's wrong with this code?
  • Eric Gunnerson's Compendium

    "Holiday Lights" or "Christmas Lights"

    • 46 Comments

    In response to my Holiday Lights post, "a guy" wrote:

    They're Christmas lights, dude. Jews don't string up lights. So while it's properly a "holiday party" at your office, and you wish people "happy holidays" (not knowing their religion), you just don't put up holiday lights. No such thing.

    I was going to just let this go, but I decided I'd comment on it.

    The celebration of Christmas as a Christian holiday is as an overlay over existing celebration that occured on December 25th. The Egyptians celebrated the birthday of Ra, the sun god, on that day, as it was just after the winter solstice. Many other societies have also had celebrations on the solstice, and December 25th only became a christian holiday by the declaration of pope Julias I in the 4th century.

    So, as somebody who isn't religious, I'm going to stick with the term "Holiday lights". I think there's a good reason to celebrate the days getting longer (*beyond* the fact that it's the start of the good skiing, which is a reason of its own) even if you don't believe there's a deity involved.

    I may switch to "Solstice lights", but I think that could be more bother than it's worth.

  • Eric Gunnerson's Compendium

    Red vs. Blue Season three

    • 6 Comments

    I was a big fan of the first season of Red vs. Blue. The second season was a bit uneven, but I'm happy to report that the third season has started well. In particular, episode 40 is wonderful.

    Whisper whisper whisper

    and

    Without the flag, who will lead us?
    Who will inspire us with their shiny pole?
    Who will flag directions to us in battle?
    We are lost, and the world as we knew it is gone forever from our eyes,
    only to live in our memories as the days of salad and glory.
    Truly, these are the end of times. Repent! Repent!

  • Eric Gunnerson's Compendium

    Ambient Orb Programming

    • 6 Comments

    A couple of months ago, C# Language Design Team Member Erik Meijer bought me an Ambient Weather Forecast Beacon from Ambient Devices.

    I think of these devices as the colorful, glowing analogs of the SPOT watches. They combine pager receivers along with a microcontroller and a bunch of colored LEDs to give a colorful display of some sort of data. You register at their website, enter your zip code, and then the device shows what the weather is going to be.

    I had it plugged in at home, but it's not very useful, as the temp doesn't fluctuate very much, and the "it's going to rain" forecast is really pretty common around these parts.

    You can subscribe to their premium service for $20 a quarter, which gets you more information feeds, such as the pollen count, the NASDAQ index level, or the even the Homeland Security level.

    But the cool part is that there are places where developers can plug in. There are two ways of doing this:

    1. You can send custom data through their network to specific orbs.
    2. You can talk to the device directly through a serial cable (which I have, but I don't know whether it's standard on this device, or whether you have to pay extra to get it).

    I spent an hour or so this morning wrapping their serial protocol in a C# object, and my beacon is now cycling through colors on my desk. I'm not sure what the final use will be, but I think it's more likely to be "ski related" than it is to be "inbox related".

    Michael Swanson has a cool article about how his team uses an orb to reflect the current status of their build.

    If you have any ideas for what to do with my orb, let me know...

  • Eric Gunnerson's Compendium

    What's wrong with this code? (#3) - Answer

    • 7 Comments

    Here's the discussion for the my last post.

    I liked Matthew's response:

    ...don't throw "Exception" since you are not supposed to catch "Exception." Anybody handling exceptions thrown by this code would have to catch Exception and ignore asynchronous exceptions (like OutOfMemoryException) at the same time, which is not easy.

    To expand a bit, if you wrap in a class like Exception, you force the user to write something like:

    try
    {
       account.UpdateBalance();
    }
    catch (Exception e)
    {
       if (e.InnerException.GetType() == typeof(DatabaseException))
       {
          // handle the exception here
       }
       else
       {
          throw;
       }
    }

    This is really ugly, and if the user forgets the final "throw", the exception gets swallowed.

    I also liked Steve's comment:

    I don't like the fact that the exception message exposes both my account number and the account balance. If this exception text made it all the way back to the client, the current message seems like a privacy/security hole.

    There are also likely things that need to be done to make the database part more robust, though that wasn't what I was intending to illustrate.

  • Eric Gunnerson's Compendium

    Holiday light time...

    • 12 Comments

    After hosting Thanksgiving at our cabin (and going up to Stevens Pass for fun, where there was a total of 3" of snow on the ground (9" now) - not quite enough to start skiing), we came back Saturday morning to put up our holiday lights.

    I wrote about the system last year, so I'm not going to repeat myself.

    I'd hoped to have time to get another electronic system added to the mix, but that's unlikely to happen given the amount of time left. I've added a few "globe balls" from last year, and I'm going to be adding about 350 LED lights to one of the trees, but that's about it.

    I really like the LED lights, but I'm amazed at how hard they are to find. Lowes had a few boxes for about a week, and I haven't found them anywhere else yet. They are pricey (more than $10 per string), but they are rugged, will last forever, and use less than 10% of the energy of the miniature bulbs. They also have a clearer color than standard bulbs, and when you compare them to commercial quality strings, they aren't that expensive.

    My current system uses two dedicated 15 amp circuits. On the left one, I have about 2200 lights (not all are on all the time because of the animation), and on the right one, about 1800 lights (also not on all the time). At 1/2 watt each, that means I'm pulling 1100 watts on the left and 900 on the right. While I'm not worried about tripping any breakers (yet), I do have to keep calculating how much power I'm using. LEDs use so little power that you really don't have to worry about power use - you could put over 35,000 LED lights on a single circuit.

    The microcontroller-controlled lights all have built-in clocks, so they repeat on a 24-hour cycle once you turn them on. The rest of the lights run off of common appliance timers, which are waterproofed in high-tech white plastic kitchen garbage bags. Those have worked well over the years, but I have a couple of box-mounted timers that will feed outdoor outlets for the future - that will make things a fair bit easier to set up.

  • Eric Gunnerson's Compendium

    C# Test Driven Development class at BCC

    • 3 Comments

    If you live in the Bellevue area, you might be interested in

    C# Advanced Test Driven Development   

    at Bellevue Community College

  • Eric Gunnerson's Compendium

    Podcasting...

    • 10 Comments

    One of the hot topics in the blog world these days is Podcasting

    Podcasting is a way to automatically get MP3 files from the internet down to your portable device (doesn't have to be an iPod, or even a portable - it works just as well on a desktop). It's built on the same RSS technology that weblogs use, but instead of just passing text, it also passes MP3 files as enclosures.

    In other words, with the proper application, you can subscribe to audio the same way you subscribe to blogs now. I hope you subscribe to blogs, as reading in an Aggregator is much nicer than going to the web page.

    iPodder is the only one application that I know of that supports podcasting right now. There's a windows version, though it uses an impressively bad amount of memory and tends to be a bit flakey (on my system inside the corporate firewall, at least), but the price is right.

    The iPodder folks also host a podcast directory, so you can find out what's available.

    I've been playing around with this for a few weeks, and have a few comments.

    First, the technological aspects are pretty cool. I like to listen to Car Talk, but I'm often busy on weekends when it's on. I can go to their website, navigate around to find the streaming content, and then listen, but it would be a lot cooler if an MP3 showed up on my system (or on my iRiver) automatically. This seems like a natural fit for NPR, and expect to see them move in this direction, though there could be some issues WRT local stations and revenue. NPR is, after all, still a business.

    The social aspects are more interesting, but not really clear (to me at least) at this point. There's definitely the potential to make an "end run" around the FCC and the RIAA and send content directly to the people - and I like the freedom of expression that that provides. There's also the chance for the "Indies" to provide edited new music directly to portable devices - to provide an "iPod channel" to the youth. Given that connectedness of today's teens, this could be pretty big.

    I've been listening to Adam Curry's "Daily Source Code" (yes, that Adam Curry), and he does a fairly entertaining show. Reality radio.

  • Eric Gunnerson's Compendium

    Lore's ratings of "SKATEBOARDING MOVES FROM THE TONY HAWK GAMES"

    • 3 Comments

    I know that I've linked to Lore, in the past, but I haven't looked at his ratings in a while. This one particularly got to me:

    Nose Manual

    This has something to do with balancing on two wheels, but it's better out of context. Frankly, I think we could all use a nose manual. As an exercise in whimsy, I am adapting the StarTrak Astronomy Program User Manual to our nose-based purposes. Chapter One: What is your nose? What does it do? Chapter Two: Setting up your nose for your timezone. Chapter Three: Selecting an object in your nose. A-

  • Eric Gunnerson's Compendium

    Transparency in Product Development

    • 1 Comments

    Soma (VP in charge of the developer division) writes about being more transparent.

    I, for one, think that we have a way to go in this area, but it's not my opinion that matters - it's your's.

    So go read the post and comment on where we've made progress, whether the plans makes sense, and what we're missing.

     

  • Eric Gunnerson's Compendium

    Hopkin Green Frog...

    • 4 Comments

    Hopkin Green Frog.

    Great photoshop expertise.

     

  • Eric Gunnerson's Compendium

    The Next Five Big NASA Failures

    • 1 Comments

    Jeffrey F. Bell writes in SpaceDaily:

    One of the most annoying things about NASA is that its dysfunctional management wastes a huge amount of effort on projects long after they are clearly doomed.

    You know, I can't agree with him more. I think the space program in general and manned space flight in particular is a noble pursuit for mankind, but I also think that the NASA approach (post - Apollo, of course) is pretty much guaranteed to waste truly monumental amounts of money.

    As Jeffrey notes, NASA has no plan to keep ISS in operation once it's built. No plan at all. You spend billions of dollars on a project, but because you didn't plan ahead, it takes 3 people to just keep the station running, leaving you only 5 hours a week to do research.

    Whether or not you think that ISS can do meaningful research, it's pretty clear that if your crew only has 5 hours a week of time, you're not going to get much done.

    No disrespect to the majority of people at NASA who work hard at their jobs, nor to the JPL folks (okay, some of them don't technically work for NASA). It's all about the missions that are being chosen.

    The price tag for ISS is around $10 billion for the US modules, plus the shuttle flights to lift and assemble the modules (running somewhere in excess of $500 million each flight).

    NASA needs to go back to their roots. They did not build Apollo right off the bat. They built Mercury, flew a little, then they build Gemini, flew a bunch more, and only then did they build Apollo. And when Apollo 1 happened, they made real changes and built a system that worked well for 9 manned flights (12 if you count ASTP and Skylab)

    What could Scaled do with $100 milllion?

  • Eric Gunnerson's Compendium

    The Incredibles

    • 7 Comments

    Tonight we went to the opening night for The Incredibles, the latest collaboration between Disney and Pixar.

    Monday, I'm going to buy some more Pixar stock.

    Pixar and Disney have hit a home run with this feature. Take one part superhero movie, three parts James Bond movie (the old ones from the 1960s), add one part family situation comedy, throw in some really good set design and state-of-the-art computer rendering, and shake well.

    While I'm used to makers of kids films throwing in a few token touches for the parents, this really isn't a kids movie - it's an all ages movie.

    Recommended.

     

  • Eric Gunnerson's Compendium

    I think because I run?

    • 12 Comments

    From ScienceBlog

    A new study assembles evidence that humans evolved and human anatomy looks the way it does because our ancestors were more likely to survive if they could run. Humans evolved from ape-like ancestors because they needed to run long distances -- perhaps to hunt animals or scavenge carcasses on Africa's vast savannah -- and the ability to run shaped our anatomy, making us look like we do today.

  • Eric Gunnerson's Compendium

    C# - What's wrong with this code? - #1 (Answer)

    • 3 Comments

    Thanks for all the responses. There were many correct ones, and a number that I want to at least comment on. Plus one that will get its own post...

    If you've written Win32 code, you've probably written code like:

    result = ::CallWin32Function();

    if (!result)
        return result;

    result = ::CallAnotherWin32Function();

    if (!result)
        return result;

    The code that I posted is the naive translation of that idiom into C#. Call a function - figure out whether it succeeded - if it didn't, return back to the caller.

    What many people pointed out correctly was that the try-catch in this code wasn't doing anything useful, and therefore the answer I was looking for was "the useless try-catch constructs". Several of you said that you should wrap that whole switch in a try-catch. That's certainly nicer than the code I showed, but still had the useless construct, so I won't award any points for that answer.

    There was also a comment about lack of comments. While I'm a big fan of algorithmic comments (ie explaning the approach that code takes), I think that code comments are mostly a crutch to explain code that isn't as clear as it could be. Code with well-chosen names and good OO design should require few comments.

    There was also a sub-thread on the efficiency of the switch on string. Not only is that not what I was looking for, but without measurement to determine whether it would *ever* matter what implementation you chose, it's wasted time to even talk about it. So knock it off.

    Interestingly, I was writing some code this morning where I needed to ensure that items there was only one item selected in a list and then pull the selection out. I already had a (written and well-tested) method that told me how many items were selected, but I had to work hard to not write a complex single loop to do what I needed when calling the method and then writing a simple loop got me there easier. It's definitely not as efficient, but I think it's unlikely I'll ever need it to be faster than it is.

    I should also probably have noted that "snippet" implies that the code is pulled out of a larger context, so it's not necessarily going to be fully understandable as a snippet. That narrows the search a fair bit - since you don't know what the code is really supposed to do, you can be assured that the problem has nothing wrong to do with that.

    As for the code, it came from some sample code in an early .NET programming book, and there were around 8 diffent cases in the switch.

    I'll post another one of these next week.

  • Eric Gunnerson's Compendium

    More on Halo 2

    • 8 Comments

    I finished the campaign yesterday afternoon. I'm not going to give any spoilers away, but while I like the new additions (new enemies, new weapons, better AI, and good backstory), I didn't feel like there was any big task at the end of the game. I just finished a level, and then the credits started rolling.

    Multiplayer - which is the real reason I wanted to play - seems to be working fairly well, though I have a few comments:

    1) The wait to find ranked game is really long at times, and there's no indication that the system isn't just hung. This is bad. I'm not planning on playing a ton of ranked games as I do it more for pleasure, but I do want to get a decent ranking so that I can match with my friends when we do want to rank. I think I'm at 6 multiplayer and 4 single-player right now.

    2) The maps are pretty good, with good variety in size and shape.

    3) The banshee is pretty much eviscerated as a dominant weapon. That may be a good thing - it's certainly true that Banshee whoring can get out of control on Halo PC, but I'm finding it much harder to do anything useful in the thing.

  • Eric Gunnerson's Compendium

    Halo2 Game Viewer

    • 4 Comments

    Ryan pointed me to this post by Scott Hanselman.

    Now, I'm not sure I really need an RSS feed of the Halo 2 games that I played (though I see why you'd want it for a clan), but I'm pretty impressed by the game viewer stuff.

    I looked at a rockets game on Ivory Tower that I won last night, and with Game Viewer, I can see all the places where shots were taken from, and where people were when they died. I'm not sure what I'd do with that information, but it's really cool.

    Oh, and I found that Bungie did include Blood Gulch in Halo 2. The terrain seems identical to me, but there are some additional rocks for cover (a good thing) and the bases have another level in them. The level is named:

    Coagulation

     

Page 1 of 1 (20 items)