February, 2005

Posts
  • Eric Gunnerson's Compendium

    Workout headphones?

    • 25 Comments

    I've been having problems with my earbuds coming out when I'm working out, so I'd like to switch to some more conventional headphones, and I'm looking for some suggestions.

  • Eric Gunnerson's Compendium

    References to value types...

    • 23 Comments

    Ian wrote a comment about being about to return references to value types.

    Basically, he's asking for a way to build a collection of value types so that they can easily be modified, and to do this, he'd like the indexer to be able to return a reference rather than a value.

    This restriction shows up from time to time, usually when somebody wants to write code like (example from Ian):

    List<MyStruct> vec = new List<MyStruct>();
    vec.Add(new MyStruct(10, 20));
    vec[0].X += 1; // Error!

    Because

    vec[0]

    gets a copy of the value stored at vec[0] and puts it in a temporary local, being able to modify the X property on that temporary copy is a useless thing to do, so the language prohibits it.

    So why won't C# let you get the reference to a value? Well, it's all because of the presence of the garbage collector. If you had a reference (aka internal pointer) somewhere into the middle of an array, any movement of the array as part of a GC would mean that the reference would be invalid.

    It might be possible to add a construct to a system that would say "this is an internal pointer, and if you move the outer object, you need to update the inner pointer as well, but that would mean that the reference to the value would not be a simple pointer, but a reference to another object which encapsulated the inner pointer (so the GC could find it), which pretty much defeats the purpose of being able to do this.

    In C++, the programmer owns the memory, and gets to choose how things get created, deleted, and moved around. In C#, the GC owns the memory, and the programmer just gets to borrow it for a short period of time. Working in the C# world requires a different mindset, and until you internalize it, things are likely to seem a bit weird.

    The meta message is around using structs in C#. In a word, don't use structs unless you're forced to use them - and by forced I mean that you need to do interop, or you've looked at your profiling data and realized that you really need to reduce the number of objects that you have around. In other words, they shouldn't be the default choice - there are a lot of disadvantages and gotchas with structs, though a few of those will go away when Whidbey shows up.

    And if you do use structs, see if you can make them immutable. That hides most of the ugly cases.

    Hope that makes sense

  • Eric Gunnerson's Compendium

    Public but not public

    • 20 Comments

    Last week, I was talking with one of my friends at the club, and he said that he had written something that was somewhat personal on his blog, and that it bothered him that his manager was bringing it up at meetings as an example of how blogs can show personality (or something like that).

    I also have things on my blog that I'd prefer people don't mention in a large group, and I started thinking about why that was the case. I have two reasons:

    First, when I'm writing my blog I'm writing it for people who already know something about me from what I've already written, so the effect that a single post that I write on - I don't know, the fact that I like to read Jane Austen novels from time to time - is going to have much less overall effect on what people think of me than if that's one of the only things the know about me.

    Second, there's a considerable difference between me relating something, and somebody else providing a quick summary of what I said. If they're doing it online, they can easily provide a link to my original words, and then people can decided for themselves what I really mean, but if it's done in person, I don't get that opportunity.

    So what do you think? 

  • Eric Gunnerson's Compendium

    Code metric tools

    • 16 Comments

    From an internal question on tools for generating code metrics...

    If you know of any others, please add them to the comments. If you have experience with any of these and want to share, please feel free to do that as well.

  • Eric Gunnerson's Compendium

    Cracking up...

    • 14 Comments

    About 15 years ago, I was skiing at Snoqualmie. Coming fast downhill, I caught an edge, popped both skis, and slammed face first into the ground. I couldn't breathe for about two minutes, and came away with a cracked rib.

    Sunday, I was skiing at Stevens Pass, and repeated the maneuver, with the exception of the "unable to breathe" part, but including the cracked rib part. It's not as bad as last time, but it does mean that I can't do much bike riding or lifting for a month or so. Luckily, it's pretty early in the bike season, so I'm not going to miss much.

    Last time I did this, I went on a 4-day ski vacation after the injury, so I'm pretty sure I can still ski.

     

  • Eric Gunnerson's Compendium

    Why does "using" only import types, not namespaces?

    • 11 Comments

    Given a type named:

    System.Data.SqlClient.SqlConnection

    The following works:

    using System.Data.SqlClient;

    ...

             SqlConnection connection;

    But this is an error:

    using System.Data;

    ...

             SqlClient.SqlConnection connection;

    Why?

    Well, the rule is that C# only imports the types in the namespace mentioned in the "using" statement.

    Back in the early days of C#, we had a slightly different rule, which I *think* also imported namespaces as well as types, but with that behavior, users were getting into situations where they had name collisions and were having difficulty figuring out what was going on (and, perhaps, coming up with workarounds - we obviously didn't have the global namespace operator coming in Whidbey), so we decided to limit the number of things that go into the global namespace.

  • Eric Gunnerson's Compendium

    New Headphones

    • 10 Comments

    In search of new headphones and armed with the suggestions that I got in comments to my last post, I spent some time on the exercise page at Headphones.com. After reading that page, and doing a bit more research, I decided to learn more about what Koss and Sennheiser had to offer.

    I spent a little time on the Koss site first. Or, to be more precise, I tried to spend time on the Koss site, but they decided that their main page should just launch a popup. Which my software blocked. I worked around that, and finally got their non-resizable popup with all-white scroll bars to come up, drawing from their painfully-slow web server. After a little browsing and reading, I moved over to the Sennheiser site.

    What a relief. It's reasonably fast, and they display their headphones in product lines, so you can see (for example) that the PX line has the PX100, PX200, and PX250. If you go to the detail page, you get all the information you want.

    So, I ended up buying the Sennheiser PX100 merely because they had a website that was better than their competitor. And I don't think I'm alone in making that sort of choice - online experience matters.

    Anyway, I got the PX100's through the always-excellent NewEgg for $43.99 including shipping. They come with an interesting hard-shell case that I will likely never use because it takes at least a minute to get the headphones in it, and I'm a bit too lazy for that. The sound is really nice - the response is flat, and extends a bunch farther into the bass range than my earbuds did. They also pass my quality test for audio equipment, which is whether, after listening for a few minutes, I find myself wanting to turn up the volume.

    Nice phones, and they certainly stayed in place better than the earbuds...

  • Eric Gunnerson's Compendium

    Pacman for the nearsighted

    • 9 Comments
    Pacman for the nearsighted
  • Eric Gunnerson's Compendium

    Lost in the Zone...

    • 6 Comments

    Last night, I finally beat my Twilight Zone, and got into "Lost in the Zone" multiball. I made good progress the first couple of weeks, but recently I'd been hampered by the current location of the machine (due to remodelling), which leaves it slightly off-level and with a light reflection right above the flippers. But, I'm lazy, so I didn't try to fix it.

    To get to "Lost in the Zone", you have to collect a whole bunch of door panels. You are rewarded with a 6-ball timed multiball in which all the high-score jackpots are enabled. The hard part is actually making any shots (you really can't aim) without hitting the other balls on the table. So, you get about a minute of this frenzy (which is plenty), then the machine goes dead, all the balls get reset, and you start trying to do it again. My score ended up being about 1.4B points.

    Next up are some mods for the machine. There are enough enthusiasts that there are lots of options. Here's what I'm thinking of:

    • Plastic gumballs to improve the look of the gumball machine
    • A backboard decal (strange that there isn't one on the machine)
    • Door flasher lights (cut to keep costs down from the original design)
    • Speakers. The stock speakers aren't very good, but this mod is fairly pricey, so I'm not sure if I'll do it. I may just homebrew it with some car speakers.
    • Bridge diverter magnets. One of the ramps has a diverter, and balls bounce off of it pretty badly. This prevents it.
    • Battery clip replacement. Pins have AA batteries on the CPU board to keep their settings when they're turned off. If the batteries leak, however, **bad** things happen to the board. The puts the batteries in a remote location.
    • Trough ball proximity sensor. One of the key features of the Twilight Zone is the "powerball", a ceramic ball that is lighter than a pinball and therefore faster. One game mode depends on the powerball, and for it to work, the game has to sense that it has the powerball. One sensor works well, but the trough one (where the balls are stored at the bottom) is known for getting bumped and going out. Mine worked fine when I got the machine, but has already gone out of adjustment. I'll try to fix it, but this replacement is a permanent fix.

    I've considered getting a "topper", which is something that goes on the top of the machine and is hooked into the lights, but that seems hard to justify right now.

  • Eric Gunnerson's Compendium

    New agricultural news

    • 4 Comments

    (Washington, DC) The USDA today announced the completion of a research program targetted at raising crop yields for lettuce growers, with the identification of a new technique. Paradoxically, it involves trimming off the growth of juvenile plants, in the hopes that the plant will respond to this injury by growing faster. For reasons that are not yet clearly understood, the technique isn't always successful, but when it does work, it's a tremendous re-leaf.

    (sorry...)

    (not really...)

  • Eric Gunnerson's Compendium

    Microsoft Win32 to Microsoft .NET Framework API Map

    • 3 Comments
    I don't think I've linked to this before. Along with pinvoke.net, this is a great resource for learning how to do specific things in the .NET world.
  • Eric Gunnerson's Compendium

    Wednesday ride

    • 3 Comments

    I took advantage of the nice April weather that we're having in Seattle to go on a lunchtime ride. There's a traditional Wednesday ride at Microsoft that the faster riders go on, where "faster riders" == "riders who also race", which means they're anywhere from pretty fast to really fast. But, with rain expected tommorrow, I decided to bring my bike in today and have a go.

    The first 4 or 5 miles was fairly calm as we wound through Marymoor park and east on highway 202, and it was easy to stay on the back of the pack (drafting can save up to around 30% of your effort, though I don't generally ride close enough to see that much benefit). But as we turned south and started climbing, the pack broke apart a bit more. I blew up a bit (ie exceeded my aerobic threshold) on the climb up 244th Avenue, but rode with another rider who was waiting for me. Turns out, however, that I was faster up the hill than he was, so after a weave through some repaving, I crested the hill and joined the rest of the group. We rode down to NE 8th, turned right, rode a bit more, and then descended down the 12% grade of Inglewood hill, ending up back on East Lake Sammamish going north. At that point, I latched on the rear wheel of another rider and held on for 7 or 8 minutes until I got dropped off the back. A regroup at the end of Eastlake, back through Marymoor, and then up 40th to the campus.

    Overall, a pretty good ride. I did have to draft to stay with the group, but could do so with a little trouble. It helped a bunch that this is early season and these guys aren't close to how fast they'll be in 3 months or so, but my aerobic fitness is better than I expected, though I'm down quite a bit on strength.

    The new bike worked pretty well, and I've gotten the seat adjusted to where I like it. My back and right wrist hurt a bit, which either means that I'll need to raise the bars (or perhaps shorten the stem), or merely that my overuse injuries are showing up. The difference between the new bike and the old bike is pretty drastic - I did 28 miles on Sunday morning on the old bike, and averaged about 13.5 MPH. Today, with a bit of drafting help, I did 19 miles in around 68 minutes, which is pretty darn fast for considering there were a couple of steep hills, and I didn't quite spin out on the downhills. So, the verdict on the bike is "great" so far. Oh, and I may have finally found a seat that my butt can tolerate well.

    Two of the guys on the ride showed up of fixies - bikes that are fixed-gear. Not only do they only have a single speed, they have no freewheel, so you can't coast - you pedal all the time, both up and down the hills. That they can ride both up and down the hills in a single gear is pretty impressive, and on the steep downhills they'll be spinning their cranks at something like 150RPM, or even a bit faster.

    I should also mention that all the other riders are really nice guys and quite tolerant at having less experienced guys along for the ride.

  • Eric Gunnerson's Compendium

    Apollo 11 panorama

    • 3 Comments

    From our Northwest rocketry mailing list:

    Apollo 11 Panorama

  • Eric Gunnerson's Compendium

    Interesting review with James Gosling

    • 3 Comments

    This interview came to my attention because of his comments about C++ and .NET, but that's really a pretty small part of what he says.

    I had the opportunity to listen to Gosling talk at Java One last year, and I was struck by how close his perspective is to a certain C# designer's perspective.

  • Eric Gunnerson's Compendium

    Qualitative Code Differences in Managed Code

    • 2 Comments

    I've been asked countless times about the differences in speed between managed and unmanaged code, and here's another good resource in that area.

    From Rico, Qualitative Code Differences in Managed Code

  • Eric Gunnerson's Compendium

    Suzanne Cook on the Loader...

    • 1 Comments

    Suzanne Cook, a great blogger (and developer) on the CLR team, spends some time talking with the Channel 9 folks.

Page 1 of 1 (16 items)