Coding Horror

programming and human factors

Stupid Registry Tricks

Scott Hanselman's Power User Windows Registry Tweaks has some excellent registry editing tweaks. I've spent the last few hours poring over those registry scripts, enhancing and combining them with some favorites of my own. Here are the results:

My Computer right click menu, after registry tweaks

  • Open Command Window Here

    Adds a right-click menu to all Explorer folders that launches a command prompt window (cmd.exe) at that folder. Incredibly handy.

  • Force Start, Search to search all filetypes

    For some godforsaken reason, Start, Search only searches files with known extension associations by default. I've run into this "feature" before and I nearly pulled my hair out trying to figure out why it couldn't find the source file that I knew was there. This registry fix forces it to search all files, as you would expect. Really a no-brainer.

  • Improve the Disk Cleanup Wizard

    Microsoft added a Disk Cleanup wizard in Windows 98, which all subsequent versions have inherited. It's located at Start, Accessories, System Tools, Disk Cleanup. Unfortunately it kinda sucks. Via the wonders of registry editing, you can change this annoying, useless tool into something that's actually effective:

    • Remove the time-consuming, useless "compress old files" rule
    • Make rules stricter for files in the temporary folder
    • Add rule to check entire disk for temporary files
    • Add rule to remove unnecessary files in Windows folder
    • Add rule to remove debug dump files

    With these changes, I get a first run Disk Cleanup savings of ~11 megabytes on a clean Windows XP install in a VM. Nothing refreshes like giving the Windows undercarriage a little how's your father. If you can think of any other files in a typical Windows install that are completely safe to remove*, let me know, and I can modify the .reg file to incorporate them as well.

    This should probably go without saying, but we are deleting stuff here. Use this at your own risk. For what it's worth, I have used it on several of my machines and inside a VM with excellent results.

  • My Computer right-click menu additions

    Wouldn't it be cool if you could right click My Computer and bring up the registry editor? Or the service manager? Or Add/Remove Programs? With this registry editing batch file, you can. In fact, you can add as many commands to the My Computer right-click menu as you like. Once you try it, you'll wonder why these menu options (see screenshot) aren't there to begin with.

    I changed this script from a plain .reg file to a batch file that calls the REG.EXE command. Why? Because it's far easier to modify this script to taste when you can see the actual right-click command lines as a plain string. For some reason, regedit can only import/export the REG_EXPAND_SZ key as a byte array, even though it's just a basic string with an environment variable in it (eg, %windir%). The alternative is to eschew the use of environment variables entirely and hard-code the windows and folder paths as plain REG_SZ strings.

In the cases where there are a number of modifications to the registry, I also included a copy of the unmodified registry key in the zip file. If you don't like the results, delete the key and re-import the default registry file to get back to square one.

Scott's post has some additional registry tweaks, including one that puts notepad.exe on every right click menu. I prefer to do this using the built in Send To functionality: just put a shortcut to the editor of your choice in the %USERPROFILE%SendTo folder and it will automatically appear in the right-click Send To list for all files. I suppose it is one more click, but I prefer it this way.

* insert LINUX joke here.

Discussion

Speeding up web browsing

In order to speed up my web browsing experience, I disable Flash in Internet Explorer. I've got nothing personal against Flash, mind you, but it's generally chrome. It's visually (and sometimes audibly) distracting, and it adds download time to each page view.

Managing Add-Ons in Internet Explorer

An image is worth a thousand words, but for completeness, here's the step-by-step:

  1. Select the Tools, Manage Add-Ons menu
  2. The dialog defaults to add-ons currently loaded. Look for "Shockwave Flash object" and "Shockwave ActiveX Control" from publisher "Macromedia, Inc". If these aren't visible, choose "Add-ons that have been used by Internet Explorer" from the dropdown menu. Sort the list by Publisher and look for Macromedia.
  3. Click each add-on, then click the Disable option button.
  4. Click the OK button. Upon exiting the dialog, it will warn you that you need to restart IE, but this isn't the case. The current page will simply refresh and the flash movies will be either gone entirely or replaced with GIFs.

Flash is also the source of a giant memory leak in Firefox, so it's probably a good thing to disable there as well. I rarely need to see Flash movies as part of my normal web browsing, but if I do, I just reverse the above steps. I'm sure there's some fancy Firefox conditional display mod (eg, click to display the flash movie) out there, too. Some quick Google searching confirms that indeed there is. Go figure.

I'm also experimenting with using a custom HOSTS file that blocks ad domains. I'm not anti advertising so much as I am pro speed. And the fastest downloads of all are the ones you don't have to do!

So what's the HOSTS file?

In computing, a host file, stored on the computer's filesystem, is used to look up the Internet Protocol address of a device connected to a computer network. The host file describes a many-to-one mapping of device names to IP addresses. When accessing a device by name, the networking system will attempt to locate the name within the host file if it exists. Typically, this is used as a first means of locating the address of a system, before accessing the Internet domain name system. The reason for this is that the host file is stored on the computer itself and does not require any network access to be used, whereas DNS requires access to an external system, which is typically slower.

What we're doing is redirecting a bunch of ad-specific domain names to the loopback 127.0.0.1 IP. That way, when your browser tries to download an advertising image from, say, m.doubleclick.net, it returns in under a millisecond with a 404 "file not found" error. Compare that to the time it would take to perform an actual download of a 20-50kb flash or GIF advertising file from a remote website. It's a substantial speed boost!

I'm not aware of any negative effects of blocking ad domains this way, but I encourage you to visit the hosting page for details. For convenience's sake, here's a direct link to the zipped HOSTS file from the mvps site. Make a backup of your c:windowssystem32driversetchosts file, then overwrite it with the ad-blocking version contained in that zip file.

Discussion

The Spolsky-Babbitt Connection

I noticed something strange in a Windows ME screenshot embedded in a Joel Spolsky article I linked yesterday:

spolsky_desktop_qantas.gif

Notice the Qantas icons? Those are shortcuts to a now-defunct unix machine at Joel's company, Fog Creek Software. You can find evidence of it at the bottom of this forum post (search for qantas). It's also shown in some of the screenshots that depict command line interfaces in Joel's UI book.

So Qantas is an Australian airline company, and the name of a UNIX machine. That's when it clicked: the whole thing is a pun on a Raymond Babbitt, aka Rain Man, quote:

Dustin Hoffman in Rain Man

Charlie: Ray, all airlines have crashed at one time or another, that doesn't mean that they are not safe.

Raymond: QANTAS. QANTAS never crashed.

Charlie: QANTAS?

Raymond: Never crashed.

Charlie: Oh that's gonna do me a lot of good because QANTAS doesn't fly to Los Angeles out of Cincinnati, you have to get to Melbourne! Melbourne, Australia in order to get the plane that flies to Los Angeles!

Pretty funny, Joel.

Even if I don't always agree with him, the guy has got to be fun to work with.

Discussion

The Problem With Configurability

I've recently been experimenting with a few hand-picked desktop utilities, but I am rapidly reaching the point of diminishing returns: the effort required to run and maintain all these utilities is greater than the productivity benefit.

Furthermore, if I learn to rely on a highly custom desktop, I've crippled my ability to work on a stock Windows XP or Win2k3 box. I can certainly bring my favorite apps with me on a USB key, but I also have to spend time setting them up on each box I touch. Is it worth it?

Configurability is mixed blessing, even for developers. You can completely customize your VS.NET 2003 environment, including setting all the keymappings to a compatibility mode. But have you ever tried to work on someone else's "customized" Visual Studio? I do this occasionally when we're hashing out quick solutions to problems, and if VS.NET is highly customized on that developer's machine, I can't get any work done. None of the standard shortcuts do anything recognizable. We can't work on the problem together at all. At least not on that machine.

Joel explored a similar topic in chapter 3 of his UI book when he asked: is customization worth it?

The trouble was, I don't use one computer. I use all kinds of computers. I use other people's computers. I use three computers fairly regularly at home and three at work. I use computers in the test lab at work. The trouble with customizing your environment is that it just doesn't propagate, so it's not even worth the trouble.

Most advanced users use several computers regularly; they upgrade their computer every couple of years, they reinstall their operating system every three weeks. It's true that the first time they realized you could completely remap the keyboard in Word, they changed everything around to be more to their liking, but as soon as they upgraded to Windows 95 those settings got lost, and they weren't the same at work, and eventually they just stopped reconfiguring things. I've asked a lot of my "power user" friends about this; hardly any of them do any customization other than the bare minimum necessary to make their system behave reasonably.

If customization is a mixed bag for advanced users like us, that can't bode well for average users:

Every time you provide an option, you're asking the user to make a decision. That means they will have to think about something and decide about it. It's not necessarily a bad thing, but, in general, you should always try to minimize the number of decisions that people have to make.

In other words, don't make users think. Or at least don't make them think about anything outside the narrow focus of their immediate goal. Furthermore, making everything configurable really means the designer isn't doing his job. This is something Jakob Nielsen points out in his introduction to the book Designing Visual Interfaces:

In the bedroom wall example, people might buy the house anyway and then paint over the wall with a more agreeable color. This example leads me to consider an excuse some developers have for not providing a satisfactory visual interface to their products: "the user can just customize the design to his or her individual taste!" Leaving the design to the users is the ultimate abdication of the designer's responsibility to provide a quality product, and many studies have shown that users are in fact very poor designers and often customize their interface in ways that are detrimental to their productivity (eg, by using color combinations that are known to cause reduced readability of screen text). Even though there are often reasons to allow users to customize some aspects of their environment, it is absolutely essential for the designer to give the users a carefully thought out set of defaults to start with. Also, users will be much more likely to end up with appropriate customized design if they are given some pre-specified (and well-designed) options to choose from as done, for example, in the Pantone ColorUp set of recommended color combinations for presentation slides.

There's an interesting extension of this philosophy in Ruby on Rails called convention over configuration:

Convention over configuration means an end to verbose XML configuration files--there aren't any in Rails! Instead of configuration files, a Rails application uses a few simple programming conventions that allow it to figure out everything through reflection and discovery. Your application code and your running database already contain everything that Rails needs to know!

You might come out ahead by intentionally choosing to make things not configurable:

  1. It forces you to carefully select good default values
  2. It forces you to pick a strategy and run with it rather than hedging your bets and trying to satisfy everyone
  3. It's one less thing for the user to think about when using your software

Discussion

Managed Code Analysis Tools

Navigating a new codebase can feel like like landing on an alien planet. That's where static code analysis tools come in handy; they're akin to software tricorders. They provide a general snapshot of unfamiliar code: Is it normal? Is it unusual? Is it dangerous?*

Classic Star Trek Tricorder

There's an element of "correctness" associated with static code analysis, but I think this should be de-emphasized. The last thing developers want is a Code Nazi peering over their shoulder. I prefer to think of these tools as software tricorders, collecting a bunch of recommendations and metrics about our code. What we choose to do with that data is up to us.

The most famous static code analysis tool for .NET is, of course, Microsoft's FxCop. If you haven't tried FxCop in a while, I recommend running the latest version across one of your compiled assemblies. You'd be surprised how helpful it is, particularly for identifying unused variables and functions. You may also be surprised how annoying some of the rules are; that's why the entire list of rules can be selectively enabled or disabled and saved as profiles. You can even write your own custom FxCop rules-- how about a custom rule that requires XML documentation for each assembly, as illustrated in this June 2004 MSDN article?

FxCop is currently a standalone .exe in an informal GotDotNet workspace, but in Visual Studio 2005, it's an integrated part of the build process. You can enable output from the console version of FxCop by ticking the checkbox on the Code Analysis tab of the project properties. Any FxCop warnings or errors then show up as you would expect in the standard Task List tab.**

There's at least one commercial tool that also does .NET static code analysis, namely FMS Total .NET Analyzer. I tried the evaluation version which is limited to identifying only one issue for each category. It's nice enough, but it also seems to overlap quite a bit with FxCop. And it's pricey.

In addition to those well-known tools, Raymond Lewallen and Robin Curry found some additional lesser known managed code analysis tools:

I've heard good things about NDepends in particular, but I haven't had a chance to check it out yet.

* Don't bother if you're wearing a red shirt. In classic Trek fashion, you may not be around long enough to care.
** at least in VS.NET 2005 beta 2, you can.

Discussion