December, 2004

Posts
  • Eric Gunnerson's Compendium

    What's Wrong with this code - #4

    • 37 Comments

    Here's another one for you. This segment of code gets the list of all responses to be sent and sends them.

    public void TransmitResponse(ArrayList responses, 
                                 StreamWriter streamWriter)
    {
       foreach (DataResponse response in responses)
       {
          NetworkResponse networkResponse = response.GetNetwork();
          networkResponse.Send(streamWriter);
       }
       GC.Collect();      // clean up temporary objects
    }

    Three questions:

    1) What's wrong with this code?
    B) Why?
    III) What should you do instead?

  • Eric Gunnerson's Compendium

    Jimmy Eat World - Futures

    • 25 Comments

    I finally got around to buying the new album by Jimmy Eat World.

    Overall, it's a good effort for a sophomore album. It doesn't approach the quality of their first album, but since so many second albums are really bad, it's hard to fault one that's good.

    After I got it, I put it on in the morning - we often listen to music while we eat breakfast - and asked my daughter who it was. She said, "Well, it sound like Jimmy Eat World to me..."

    It makes a father proud.

  • Eric Gunnerson's Compendium

    Design up-front vs. along-the-way

    • 29 Comments

    I had a discussion at lunch yesterday about the right way to do design.

    Waaaaaay back when I was in school - when Van Halen's "Jump" was at the top of the charts - we were introduced to the Waterfall Model of software development. (aside - it Royce's model was iterative, but it was rarely discussed that way - the typical discussion broke the whole project down into phases).

    Anyway, the waterfall model (and some other models as well) have distinct phases. In waterfall, you first collect requirements, then you design, then you implement, etc.

    I've never found that to be very workable. As Field Marshal Helmuth von Moltke said, "No plan survives contact with the enemy" (actually, what he said was, "No operation plan extends with any certainty beyond the first encounter with the main body of the enemy" (though he likely said something like "Kein Betrieb Plan verlängert mit jeder möglicher Sicherheit über dem ersten Treffen mit dem Hauptkörper des Feindes hinaus" (or at least that's what he would have said if he spoke English and used Babelfish...)))

    That doesn't mean that you should have a design, it just means that you should expect your design to change along the way as you learn more. But without spending time on design, you are likely to make some errors of architecture that will be difficult or costly to fix.

    And just going off and starting coding would not have been tolerated by Tony Jongejan, my high school programming teacher.

    At least that's what I used to think. These days, I'm not so sure, for most applications (see caveats later).

    The problem is that, unless you've already built such a program (some of which is codified in the prototyping and "build one to throw away" schools of thought), you rarely have enough information to make informed choices, and you won't have that data until you actually write the code.

    I think that you're far better off if you focus on building clean and well-architected (at the class level) code that has good unit tests, so that you'll have the ability to adapt as you learn more. It's all about the resiliency of the source to the change that is going to come, and letting the code evolve to do what it needs to do.

    Caveats? Well, there are a few.

    If you're in the library business, you will at some point have to put a stake in the ground and ship the thing, which will severely constrain further modifications. Your library may also be used in ways you didn't imagine.

    I think the right way to solve that is with a little design up front, a lot of prototype use, and then a good review process before you ship it.

    So what do you think? What amount of design is right before coding?

  • Eric Gunnerson's Compendium

    Life simplification redux...

    • 37 Comments

    Back in June, I wrote a post about wanting to simplify my life, and to enjoy life more.

    I've made progress in some areas, not so much in other areas. Last summer I ended up pretty burned out, and I feel like I'm just starting to get caught up on a lot of things. So, here's a quick report on how I did, and what I'm planning on doing next.

    Jay has also been on a similar quest.

    So, one the plus side:

    • Get a job that's exciting and places fewer demands on my family time. Done.
    • Get the final inspection done on our ski place, and stop paying King County $500 each year to renew the permit.
    • Sell the motorcycles. Done.
    • Cancel some magazines. Done.

    Work in progress:

    • Get my investments in order. We have a mismash of different accounts - multiple IRAs, CDs, and various investment accounts. I've opened a Scottrade account that has most of my stock investments, but I still have too much money in underperforming accounts. I also own some MS ESPP stock that I need to sell. On the other hand, I've done fairly well in the stocks that I've purchased.
    • Be more "there" for my family. I've been better here - I spend much less time on email, but my Halo2 time has been a little too much. I need to limit this to times when I really want to play, rather than just doing it because I can't find anything else to do. Of course, I do have a level 10 small team ranking to show for it.
    • Cook more. Not "heat up", but "cook". I really haven't done much of this, and have settled for making more pedestrian meals. I need to find a cuisine to work on, or a new type of dish. Suggestions welcome.
    • Remodelling. Well, this is probably going to be an ongoing project for a long time. I've gotten a few things done and a few others planned, but I just need to get off my butt and get them started.

    Another project is "add storage to the house". It's somewhat paradoxical, but I've found that having good storage is a good forcing function to get you to go through things and get rid of stuff that you don't need any more. If a room is always cluttered even if you cleaned things up, it's easy for things to get out of shape.

    I now have four 36 x 24 x 80" Ikea pantry cabinets in the garage, and three more that will go in our laundry room as soon as we get a floor down. They hold a considerable amount of stuff, and my garage is moving towards clean and organized.

    What have you done to make your life simpler and more organized?

  • Eric Gunnerson's Compendium

    Visual Studio support for your language...

    • 16 Comments

    Cyrus is going to do a series of posts on how to add support for your own language within VS.

    Hopefully those of you who have a language they love (python, ruby, perl, OCaml, whatever) and woudl like to see that language fully supported in the VS IDE will now have a series of steps they can take to move toward that goal.

  • Eric Gunnerson's Compendium

    Tracking down managed memory leaks (how to find a GC leak)

    • 17 Comments

    From Rico:

    Tracking down managed memory leaks (how to find a GC leak)

     

  • Eric Gunnerson's Compendium

    Embedded development with .NET and C#

    • 24 Comments

    .netcpu has announced a tiny embedded system that uses allows the user to write .NET code. Here's an Eweek article.

    I like C# and all, but at the current price point, I don't think it's very interesting. $500 for the development kit, $199 for the module. If you need the 32-bit performance (it uses an ARM chip), then it might be more interesting.

    I should also note that the Javelin stamp (which runs a Java subset) is about $80 in quantity.

    None of these are cheap enough for my next holiday lighting project.

  • Eric Gunnerson's Compendium

    Coping with Burnout...

    • 16 Comments

    In a comment, Todd wrote:

    http://blogs.msdn.com/ericgu/archive/2004/12/09/278797.aspx#278985

    I have a few thoughts.

    First, it takes a while to get burnt out, so you can't expect to get un-burnt-out in a week.

    For me, there have been a few things that have worked well:

    1. Change the situation that led to your burn out. In my case, it was mostly job-created. If you can't address the root cause, it's hard to get better.
    2. Make a list of the things that you haven't been getting done that you'd like to get done.
    3. Work at the list, slowly.

    So what other advice can you give?

  • Eric Gunnerson's Compendium

    Continue "What's wrong with this code?"

    • 49 Comments

    I'd like an opinion on whether you are find the "what's wrong with this code?" items useful at all, and whether you think I should continue to do them.

    Also, if you have any ideas for how to make them better - ideas that wouldn't take a lot of time - please let me know.

  • Eric Gunnerson's Compendium

    Monday Night Football

    • 26 Comments

    I'm not a rabid football fan, so I usually just watch the Seahawks play, and they're rarely on Monday Night Football, so I haven't seen it much recently.

    But last night, they were on, and I got to watch their patented "fold it up and go home" defense.

    That is hardly surprising, and not really worth a post. What I'm writing about is the quality of the commentary. It's really gone downhill since I watched it last. There were three things that stuck in my mind.

    1. Seattle makes in interception, and all they can mention is that it was caught by a safety. I can see the number clearly (but not the name), so it would have been nice to tell me who did it. Nope, two replays, and then to commercial with no mention of the player's name.
    2. A touchdown throw from Testaverde (to Johnson, I believe) looked like it was questionable. Then, ABC nicely showed a reverse angle replay that made is really really clear that the official (who had the same angle) made the right call - it was a touchdown. But they only showed that angle once, and Michaels and Madden went over and over a replay from another angle claiming that it wasn't a touchdown.
    3. Cowboys punt. It's a short punt, and it bounces up and off of the chest of Cowboy in coverage. The official thows his beanbag at the spot. At that point, it's a "free ball" for the Seahawks - they can try to grab it, but if they fumble, they get the ball at the point it was first touched. Michaels and Madden totally miss this and call the ball for the Cowboys, and it takes them about 45 seconds to figure out what has happened.

    That's pretty poor. Production isn't great either - the graphics are overblown, and there were at least a couple of times when the montage of previous plays made you miss the start of the next play.

  • Eric Gunnerson's Compendium

    "You unlock this door with the key of imagination"

    • 22 Comments

    I got an early present today.

    I drove down to Fife (a indistinguishable suburb of Tacoma, and picked up a new pinball machine. Well, not a new machine, as there are no new machines, what with the demise of Williams in October of 1999, but thoroughly-reconditioned machine. In some respects, it's better than new, as there are some improvements designed by enthusiasts.

    Which machine? Well, if you're an addict, the title probably gave it away. I got my first machine - a Williams "Bad Cats" (it has to be a Williams or Bally machine, as they make the best stuff) - around 6 or 7 years ago. It's an okay machine, but it's pretty retro - it doesn't even have multi-ball - and it doesn't have a ton of challenge. So, I wanted a different machine, and after a lot of thought, decided that if I was going to get a new machine, I'd get best.

    So, after a lot of searching and a bit of manual labor, I now have a Twilight Zone pin sitting next to the XBox in the basement. Twilight zone is one of the most popular pins around, and has a couple of distinctive features.

    First, it has a small upper playfield where you battle "the Power". When the ball is in that playfield, you control it by energizing a couple of magnets that are under it. Time it just right, and you can bounce it out the top of the playfield.

    Second, it has a "Powerball", which is a small ceramic ball that is used instead of one of the pinballs. It's a little bit lighter, and therefore a lot faster than the normal pinball.

    Seems like I'm going to be playing a little less Halo 2...

     

  • Eric Gunnerson's Compendium

    Programming contest at EggHeadCafe...

    • 12 Comments

    EggHeadCafe is running a programming contest.

    The Swedish Chef is a character from the old Muppet Show that was broadcast in the 1970s. The Chef speaks his own language (an amalgam of Swedish, English, and who knows what else), and your task is to design and implement a class library  to translate English text into the Chef's language.

    Looks interesting, and fairly straighforward to solve. But can you do it elegantly?

    Oh, and there's a cash prize to the winner...

  • Eric Gunnerson's Compendium

    What's wrong with this code #4 - discussion...

    • 14 Comments

    I've decided to use "discussion" rather than "answer" on these.

    So, in reference to the last question:

    First, thanks to all who posted. The discussions in the comments are always interesting to read, and I usually learn something from them.

    I was going for the call to GC.Collect(). The intention of the user was to clean up the NetworkResponse objects that came back from the call to GetNetwork().

    This is almost always the wrong thing to do. Rico does a far better job discussing it here than I could.

    So, that's what I was going for, but it looks like I'll need to take a bit more care in creating my examples, to limit the possibilities a bit.

    To expand a bit on some of the comments:

    There was a fair amount of discussion about resource leaks. Given what I wrote, there probably isn't enough information to determine whether a resource leak is an issue.

    There was also a lot about data validation. Data validation is important when you're writing API routines and/or if you have security concerns, but my personal choice would be not to add data validation to this routine, because the runtime does a pretty good job in most cases. If, for example, the ArrayList is null, then the foreach loop is going to throw an exception without me checking.

    The disadvantage of that approach is that the exception may not be quite as informative as a hand-coded one.

    Hope that makes sense. 

     

  • Eric Gunnerson's Compendium

    More on pinball and TZ

    • 22 Comments

    I started playing pinball when I was about 12 years old. That was way back in... Well, suffice it to say that I was 12.

    I started on pins rather than video games because video games didn't really exist. Well, technically, this isn't true - the first video games had be in bars for a couple of years, and you could buy Pong for your TV for $150, but there weren't any vids in the 7-11 where I played pins.

    I've always had a soft spot for pinball. There's something about the physicality of the game - to play well you need to know how to treat the game. If you don't shake it the right amount, you won't get a good score. If you shake it too much, you'll tilt it. But shake it the right amount...

    It's hard to find good games to buy. Ideally, there would be a local place you could go to look at - and play - a pin before you buy it. There used to be place in Seattle (but it seems to no longer have a valid website, at least) called Music Vend, but their games were a) expensive and b) not always in great shape. Not to mention that they might not have the game that you wanted.

    So, if you're going to buy a pin, you're probably going to be buying it over Ebay. And that likely means that you're going to be having it shipped, which will probably cost $150 - $300. Pins are big and heavy, and a pain to move around. So it pays to buy one that is close, if possible.

    My pin came, from all places, Alaska, from a company the refurbishes and sells old games. A game that has been rebuilt is known as "shopped" in the trade, and that can mean anything from new rubber parts to pulling all the parts of the playfield and replacing everything that needs to be, and making any necessary mods. My game is the latter.

    I didn't quite meet the reserve on the first game I bid on, and then got an email from somebody telling me that the first seller didn't pay, and the game was mine for what I bid. This is a common EBay scam, so beware - you can reach a seller through Ebay's system and know that you have the right person, but an email could be from anybody.

    In this case, I spoke with the seller about this, didn't buy the first game, but did buy another TZ that he had (the better of the two, in fact). Shipping to Seattle was already factored into his price, so I likely saved about $500 over buying a machine somewhere else.

  • Eric Gunnerson's Compendium

    Communicativity and openness

    • 13 Comments

    As you've probably noticed from my blog, I'm a little less open and communicative than I was in the past, and I've decided to write about it, since I've been deliberately not answering some of the questions I've gotten in comments.

    It's mostly because I'm no longer in a position where it's my job to decide what's okay and what isn't, so I'm trying to tread lightly. It's also true that the Windows division isn't quite as open as devdiv was - or perhaps I just feel that way because I'm not as plugged in as I was.

    I've recently gotten some clarification on what I can and cannot talk about, which will allow me to talk about things a bit more, so look for some posts coming up - but perhaps not until after the holidays. And when we reach a point where I *can* talk more, be assured that I will.

  • Eric Gunnerson's Compendium

    Word for the day - "Plastination"

    • 11 Comments

    Plastination is a process of preserving animals in which water and lipids (fats) are replaced with a polymer. It yields anatomical specimens of eerie realism.

    You can probably identify this animal:

    Dissection can also be done - here's an interesting exhibit:

     

    I find it fascinating, but as this article notes, there are some who think it crosses the line.

     

  • Eric Gunnerson's Compendium

    Three months of developing

    • 12 Comments

    Pretty close to three months ago, I left the C# group and started as a developer in the Windows Movie Maker team. It was a fair change, and while I've usually considered myself a pretty fair programmer (a trait I notice is not uncommeon among developers), having not written code full-time, I was somewhat apprehensive.

    Now, three months later, I'm quite happy with the change. Part of it is the fact that it was good for me to get into a different environment and work on something different, but programming is as rewarding as I remember, though there are times when I get pretty frustrated trying to figure things out.

    The team has been everything that I hoped to find, so no qualms there. And I'm starting to get to try out things like Test-driven development in the wild, instead of being a fairly knowledgeable person who'd never actually tried it out.

     

Page 1 of 1 (17 items)