Rants, rambles, news and notes from another geek

Geek Notes 2004-12-08

Recently I got the Dell D/View Notebook Stand and D/Port Advanced Port Replicator for my desk at work. I love it. I considered getting a Sherpaq Oyster, but there were a few things that made the Dell version stand out. The D/View gets my screen up nice and high, just like with the Oyster, but the D/Port gets me DVI, Ethernet, video, another power adapter and more. Recommended.

UPDATE 2004-12-21: Brian Button pointed out to me that the link for “Abstract Test Classes in VSTS 2005” was broken. Thanks, it has been fixed.

Geek Notes 2004-12-07

I am just not satisfied with the state of RSS readers. I started with an old web based one, then SharpReader, then NewsGator, then RSSBandit, then BlogLines, back to NewsGator and now I’ve switched to JetBrains Omea. So far so good, but it is still missing a few things that I would like. (Until Jan 1 2005, you can get a free perpetual license for Omea, so go get one now. Even if you aren’t going to switch, you may want to someday. )

RAII and IDisposable and Thoughts About OO

The other day, while pair-programming on some nasty P/Invoke code with Brian Button I mentioned to him that I saw an extract class refactoring in my code after writing something like this:

IntPtr handle;
&nbsp_place_holder; &nbsp_place_holder; handle = SomeNastyWin32PInvokeCall();
&nbsp_place_holder;&nbsp_place_holder;&nbsp_place_holder; // Do something with the handle
&nbsp_place_holder;&nbsp_place_holder;&nbsp_place_holder; //&nbsp_place_holder;Release the handle
&nbsp_place_holder;&nbsp_place_holder;&nbsp_place_holder; SomeOtherNastyPInvokeCall(handle)

Brian, being the C++ guru that he is, said, “Of course. That is the RAII pattern from C++.”

Duh! I knew that. RAII, which stands for Resource Acquisition&nbsp_place_holder;Is Initialization,&nbsp_place_holder;is a pattern that says:

This C++ idiom relies on the life-cycle of objects: constructors called to initialize the object, and a destructor called when it goes away. Objects are usually created either automatically in a local scope, in which case they are destroyed when the scope is exited (via normal flow, return, or exception), or they can be created with “new” in which case they are destroyed by an explicit “delete”.

If the resource in question (a file, lock, window, etc.) is acquired (opened, locked, created) in a constructor, and released (closed, unlocked, disposed) in the destructor, then the use of the resource is tied to the lifetime of the object. Since object lifetimes are well-defined, so is the use of the resource

(Source: http://c2.com/cgi/wiki?ResourceAcquisitionIsInitialization)

But of course, that is written in terms of a language that has deterministic finalization (C++). Since .NET does not, the only way to apply it is to use the IDisposable pattern.

This got me thinking. I am one of those people who prefers short single-minded classes with short single-minded methods. The ultimate, yet unachievable goal is to have one line methods. I saw Jay Bazuzi post on the Refactoring List last month:

I absolutely agree that when you have to scroll, it makes things harder to understand.

Most people would agree with the statement “I like to keep my methods small”.

What people disagree on is what “small” means.

I strive to make my methods one line long. If they need to be any longer, I need a strong justification.

I also strive to write object oriented software. For me that means that interactions of objects should be important, not interactions of methods.

Because understanding classes is key to OO, I try to keep all my classes small enough to be visible without scrolling.

(Source: http://groups.yahoo.com/group/refactoring/message/6319)

So this “Introduce RAII Class” refactoring is a tool that we can use to create shorter, clearer code. In particular, in C# we get the using() statement which makes it really simple to see and understand what is going on. So if I applied the “Introduce RAII Class” refactoring to the code I wrote above, I might have this:

using( NastyPInvokeCodeHandler handler = new NastyPInvokeCodeHandler() )
&nbsp_place_holder;&nbsp_place_holder;&nbsp_place_holder; // Do something with handler

Ah yes. That is much better. The interesting thing to me is how often I’ve had people give me grief about this. “The docs,” they say, “tell you to use IDisposable for expensive resource allocation. Not for that.” But honestly, I would say that the docs are flawed. The point of IDisposable is getting a semblance of deterministic finalization. The point of the C# using statement is to have a nice try finally block around IDisposable code. Take those two things together and we have RAII.

As I said to Brian, “You know what I really want is an automatic refactoring for Resharper that lets me select a try finally block and it will generate an IDisposable class for me.”&nbsp_place_holder; As Homer J. Simpson might say, “Mmmmm refactoring.”

I think I’ll post some real world examples of using this idea with P/Invoke in a few days.

Geek Notes 2004-12-03

This morning at 4am, my wife Emily and son Finn got up to head to Denver. It was Emily’s firsy trip back “home” since we’d moved out to Seattle. That left me to take care of our 2 1/2 year old daughter, Hadley. We haven’t had any solo daddy-daughter time in a while so it should be fun.

Geek Noise 2004-11-28

December is rapidly approaching. Still rainy and cold here, but apparently that it to be expected in Seattle during winter.

  • Indie Label Adopts CC License - Wow, this is interesting.&nbsp_place_holder;A record label, albiet a small one, allowing their artists to use the Creating Commons License for their works. Very cool. [via Boing Boing]
  • Maxthon - A promising looking IE wrapper that gives you tabbed browsing and all that goodness. But the Googlebar doesn’t work and just don’t know if I can live without it. [via simplegeek]
  • Pragmatic Project Automation Review - John Lam reviews a book that has been sitting on my in queue for too long. Now I gotta read it.
  • WSE FAQ Site - John Bristowe has a new site up for WSE fans.
  • Stop the Window XP File Association Web Service - A wonderful little reg hack by Darrell Norton.
  • What Does Style Look Like&nbsp_place_holder;- The first of eight posts (here are 2, 3, 4, 5, 6, 7, and 8) where Larry Osterman reviews various coding styles. Although #8 claims to be “the end”, it ends with the question, “what does my personal coding style look like?” Stay tuned.

Now playing: Spock’s Beard - Made Alive Again / Wind At My Back

TestDriven.NET 1.0 Released Today

Testdriven.net.logoJamie Cansdale just dropped me a note giving me the scoop on the new 1.0 release of TestDriven.NET. Formerly known as NUnitAddin, this is an indispensable tool for the .NET developer. You gotta have it!

From the home page:

TestDriven.NET makes it easy to run unit tests with a single click, anywhere in your Visual Studio solutions. It supports all versions of Microsoft Visual Studio .NET meaning you don’t have to worry about compatibility issues and fully integrates with all major unit testing frameworks including NUnit, MbUnit, csUnit & Visual Studio Team System.

In addition to being&nbsp_place_holder;more solid and reliable than any previous release (as far as I can tell so far), the 1.0 version also:

  • No longer has those annoying timeouts (but now you are responsible for making sure you stay up to date yourself)
  • Has an excellent Quick Start that shows you exactly how to get up and running quickly
  • Has a new MSI installer that allows you to specify which test runners you want to use
  • Supports very cool pseudo-categories for collecting all kinds of interesting information. (More on this later, but for a hint see this post I made a year ago.)
  • Has lots of bug fixes

To download it, visit www.TestDriven.net, register go to the download page, and fill out the survey. You’ll only have to do it once,&nbsp_place_holder;and Jamie has ensured me that the information will only be used to improve the product and better understand how people are using it. (Expect some good blog posts from him once he has enough data to make some generalizations.)

Now playing: Porcupine Tree - The Sound of Muzak

Lord Robert May on Science

I do not believe in any philosophies of how science is done. It’s essentially an almost existential process of asking questions about how the world works. There are different styles. Some people will be hugely useful, as well as hugely happy, spending their lives going down a narrow channel, learning more and more and more about something. Others with&nbsp_place_holder;a shorter attention span, you might say, will be happy hopping around and are more interested in the earlier stages&nbsp_place_holder; of something: what are the essentials of this, and then leaving the elaboration of that to people of a different kind. That kind of personality is not necessarily the person who would flourish on a large team that’s going to spend 10 years on a problem. You need both. And I belong to the short attention span set.

– Lord Robert May interviewed by Jocelyn Selim, Discover Magazine, November 2004, p23.

Editor’s note: I think I belong to the short attention span set too.

Geek Notes 2004-11-26

Boy, campus was s a graveyard Wednesday. It seems that everyone took an extended vacation this week. As a new employee, I was at work. Yesterday we had a great Thanksgiving dinner in our new house. Since he is here without his family this month, Scott Densmore joined us. We ate too much, drank too much and had a great time.

  • Regex for RFC822 - Parsing email addresses with a regex is notoriously hard, but this regex is apparently very close. But is is possible the biggest, ugliest regex I’ve ever seen and I haven’t tried it with the .NET Regex class either.
  • Science Geek in the Kitchen - What happens when a geek gets into the kitchen on Thanksgiving? (free registration required)
  • Taxonomy for Bad Code “Smells” - Mika M├â┬ñntyl├â┬ñ originally created this list as part of his masters thesis and is now maintaining it online.
  • PureText 2.0 - I often copy-paste from IE, Outlook or Word into BlogJet or an email message and want only the plain text, without any formatting. This tool makes that really easy.
  • Place Holder Pages in SharePoint Site Definitions - Kris Syverstad has finally blogged a technique that he and Scott Pachelo use for leaving extension points in SP site defs. Also Kris is publicly showing off his most recent SP project. Check it out. It is the most customized SharePoint implementation I’ve ever heard of.
  • Grey Video - Remember the mashup of The Beatles White Album and Jay-Z’s The Black Album? It was called The Grey Album and now someone has made a cool video to go along with one of the tracks.
  • TiVo Sells Your Fast Forward Button - TiVo announced that starting next year they will be showing banner ads when you fast-forward. That itself isn’t all that annoying, but what is annoying–perhaps even disturbing–is that if you accidentally press the wrong button during one of those ads, they will send your personal information to the advertiser. Ugh.

Now playing: The Kleptones - Rock

WinKey Is Pissing Me Off

I’ve been hooked on Copernic WinKey for a while. I use it to launch Password Minder, BlogJet, Internet Explorer, etc. It has been a great tool.

But it does’t work very well when you run non-admin. It works, in that it launches programs when you press the keys, but it doesn’t let you pop up the keystroke editor. When you do, you get an “Error creating system registry entry” popup.

This morning I was finally annoyed enough to bring up Sysinternals’ Regmon to figure out what is going on.

It turns out that WinKey is using registry keys in HKEY_CLASSES_ROOT that are transient. It creates them during startup and then deletes them when it is done. So you can’t adjust the permissions on a particular key&nbsp_place_holder;to make this program behave (other than opening up HKCR–which I’m not going to do). You can’t manually create the missing keys because it will just delete them the next time it is launched.

That is rediculous! And it is pissing me off. That is not what HKCR is for dammit.

Now I’m gonna have to look into writing a new one from scratch unless someone knows of another good free one.

Vertical Laptop Stand?

I remember seeing someone blog about a cool laptop stand that holds your computer upright on your desk. You would open your laptop all the way and slide it into the stand, and it would the laptop upright so the screen was up at eye level. As I recall, the keyboard was tucked inside and the screen stuck out the top.

Does anyone remember seeing something like this out there? Please post a comment if you remember what I’m talking about.

Now playing: Porcupine Tree - Prodigal