Jonathan de Halleux started an open-source site called NCollection, where people can contribute the collection classes that are missing from .NET (trees, sets, linked lists, ternary search trees, circular buffers, etc.) and put them all in one namespace. They’ll be emphasizing coding standards and peer review, unit testing (using MbUnit), and FxCop. Very, very cool. If I get some time off from packing, I need to check them out; maybe I could contribute a HistoryList/UndoList.

Live and learn…

So as I was packing boxes, I ran across some stuff I wrote maybe eight or ten years ago (good grief, has it been that long?). One was a list of things I was thinking of sending in for the “Live and Learn and Pass it On” books but never did, and I figured they might be worth passing on before I pack them away again. As in the real books, I’ve put some of them in bold just because I feel like it.

I’ve learned that few things are quite as satisfying as impulsive, totally spontaneous acts.

I’ve learned that, no matter what you think your attitudes are, you still don’t quite know how to react when you find out one of your friends is gay.

I’ve learned that, while most people cling to the things they know, I’m usually happiest when I’m doing something new.

I’ve learned that the only stupid people are those who are ignorant and refuse to admit it.

I’ve learned that the surest way to offend me is to try too hard not to offend me.

I’ve learned that “crazy” means something you want to do but that society frowns on for some reason — and you shouldn’t necessarily let that stop you.

I’ve learned that trying to recapture a fleeting emotion is a sure way to get yourself really frustrated.

I’ve learned that everyone is always trying to get attention, even if they don’t realize it.

I’ve learned that sometimes you can’t tell if what you’re doing is a mistake, and if it turns out to be, you shouldn’t be hard on yourself.

I’ve learned that there’s no point in worrying about the things you can’t change.

I’ve learned that, no matter how much people may long for security and consistency, it’s always randomness that really makes life worth living.

I’ve learned that you can’t blame yourself for not knowing everything.

Explorer Bar control

Found an article on CodeProject about a theme-aware but not theme-dependent Explorer bar (the sidebar you see in Explorer windows in Windows XP). It picks up the current theme if you’re running XP, but falls back to a reasonable look-and-feel in pre-XP OSes (not the first to do that, although I like this one’s pre-XP look).

I’m just guessing when I call this an Explorer bar; I don’t know what the official terminology is. The author calls it a “taskbar”, which it obviously is not; this goes on the side of a window, not the bottom of the screen. But aside from the naming issues, it looks pretty good. He’s incorporated several suggestions from readers; for example, instead of sliding the panes open at a constant speed, someone suggested making the motion more like a cosine curve, and it looks like he incorporated that into the control. Looks like it should be a pretty nice control. I’ll have to actually download it sometime…

Intercepting constructors

.NET has some features that could be very, very cool for writing unit tests and doing test-driven development.

One area that shows a lot of promise is mock objects. For example, if I want to test my database-access code, but don’t want to create a clean database every time I run my tests, I could create a mock object that isn’t a real database connection but that plays one on TV — a class that knows just enough to react appropriately if the test class does what it’s supposed to, perhaps by using a state machine (NMock does this). That idea is nothing new, but prior to .NET it was easy to mock an interface but hard to mock a real class. In .NET, you can mock a real class, even intercepting non-virtual methods and making GetType() pretend that you’re the actual class.

The easy way to do this is with RealProxy. Just descend from it, pass the type you’re mocking to the constructor, call GetTransparentProxy() and cast it to that type, and go. The transparent proxy looks like the real thing, but any calls to it are magically turned into calls to RealProxy.Invoke(), with a bunch of parameters (via an IDictionary) like method name, parameter list, etc. Even non-virtual methods can be intercepted. The only downside is that you can only mock a class if it descends from MarshalByRefObject. (You can also mock an interface if you like.)

But things get even more interesting. .NET Remoting can actually intercept constructors. Just add some options to a configuration file, and suddenly every time you call new Foo() it’s actually returning a remoting proxy instead. Looks exactly like a Foo, but adds whatever custom behavior it needs (e.g., passing calls to another computer). And totally automatic. Sweet, huh? Imagine hooking that for testing. “The first time someone creates an instance of Bar, expect these parameters, and return an instance with these properties. The second time someone creates an instance of Bar, expect these parameters, and throw this exception.” Very interesting possibilities indeed. And there’s got to be a way to hook constructors the same way Remoting does, right?

Well, I haven’t found it yet, but I’m looking. Method interception happens at a lower level than IL, so this is one case where Reflector can’t help (much). If you descend from ContextBoundObject and put the right attribute on your class, you can have someone intercept your constructor; that’s a possibility, but I’d rather have it also available for classes that didn’t expect to have their constructors intercepted. I found an article that delves deep into the mysteries of ContextBoundObject that may have more insight. (So far I’ve only read half the article; I’m posting about it here to remind me to finish reading it later.)

VS add-in for adding #region to the selected block

This post on CodeProject looks pretty cool… I’ll have to spend some time looking at it (in, as usual, my copious spare time). It’s not so much what it does that’s interesting (though the “Add to Existing Region” is pretty intriguing), it’s more that it does it at all. I’ve written a VS macro to collapse code and then selectively re-expand the stuff that I know I always want to see (some comments, TODO items, the using statements at the top of the file); but actually modifying the code in an active document is just horribly awkward — otherwise I would have written several more by now (something to prompt me for a namespace name, and then add using SomeNamespace; to the top of the file, keeping the usings in alphabetical order, and without moving the cursor from where it was originally, would probably be the first). Dissecting this code should make for a lively weekend, sometime when I’m not hunting down boxes and then filling them with stuff.

Custom file types and code generators in Visual Studio

Ran across an article on CodeProject that does some interesting things. It adds a new file type to the File New dialog (an “xfg” file, which as it turns out is kind of like a .config file), and when you add an .xfg file to your project, it automatically creates a code-behind .cs file with strongly-typed properties for reading the XML. Looks pretty slick, and worth looking into in my copious spare time.

Mortgaged birthday

Happy birthday to me…

We made the offer last night. Paperwork; eight or nine things to read and sign. (I’m told there will be many, many, many more at closing.) Our Realtor was actually surprised that we wanted to get the house inspected, which has me a bit puzzled; I would’ve thought it would practically be a given. But on the plus side, the inspection will cost less than we had thought it would.

Technically, the offer hasn’t been accepted yet, but our agent is also the sellers’ agent, and he had talked to them about it beforehand and everyone knew what the deal would be. So there’s still a vague chance that it might not go through, but… well, the inspection is already scheduled. 😛

The enormity of it all didn’t really sink in until I woke up in the middle of the night. Good Lord, we just made an offer on a house.

Squarified treemaps

This post on CodeProject talks about squarified treemaps, which are an interesting way of visualizing the same kind of data that you might otherwise put on a pie chart. Treemaps are foreign-looking the first time you see them, but they would have some benefits over pie charts: with treemaps you don’t lose all that space in the corners, and you also have a better way of viewing small segments — instead of being itty-bitty really-thin slices, they’re somewhat-small squares. The article wanders far afield, and its code samples are for Avalon, so not useful for apps today; but the first quarter or so of the article contains a walkthrough on the squarified-treemap algorithm, which has plenty of illustrations and explains the algorithm quite well.

On a different note (though still on data visualization), take a look at this amazing interactive ZIP Code map. Imagine that kind of interactivity in a combo-box’s dropdown.