30 October 2008

Application Manifests

I was bitten by an interesting problem with our service today.

When I ran the service on a clean XP SP3 system, I got

The system cannot execute the specified program.

Googling this phrase, it implied we had a missing dependency (DLL), so I ran Dependency Walker but found no missing dependencies.

However, Dependency Walker did find an error, giving me another set of phrases to Google:

Error: The Side-by-Side configuration information for "foo.exe" contains errors. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem (14001).
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
"Side-by-Side configuration information" is the clue that this is actually a problem with the application manifest. Now we're getting somewhere...

As it turns out, the Visual Studio 2005 project was configured to have the linker generate the application manifest, but for some reason (I haven't root caused it yet), the manifest being generated is wrong: it specifies a dependency on the VC8 runtime, but the service is actually statically linked to the runtime to minimize dependencies.

So, the reason we're seeing this vague error when we run the service is because the application manifest is horked. When I rebuilt the service without the application manifest, the problem "went away."

The next step is to take a look at the manifest and see what it ways.

You'd think looking at an application manifest would be simple: it isn't.

Fortunately, the indispensable Kenny Kerr has written a tool which will display the application manifest: Manifest View.

24 October 2008

Compare and contrast

Sarah Palin says clothing budget row is sexist

versus



Picture by Callie Shell, from an excellent Digital Journalist piece here.

11 October 2008

Why I'm voting for Barack Obama

While I lean so far to the left on most things that I'd be more at home in someplace like Boulder or Berkeley (perhaps), I can't think of any of the Republican candidates who were noteworthy.

Rudy Giuliani: noun verb 9/11. He's an idiot, too, showing poor judgment with Kerik, his affairs, etc.

Mike Huckabee: very personable, so long as you overlook his fundamentalism and the corruption when he was governor of Arkansas. Sorry, I have no tolerance for any religious fundamentalists: Christian, Muslim, Jewish, etc.

Mitt Romney: the smartest of the bunch, and certainly he has some business credibility, but he was very quick to change his views to match what people want (and eerily reminiscent of a Stepford husband).

Fred Thompson: please. An actor? Did we learn nothing from the disaster that was Reagan, worst president until W?

On the Democratic side, I liked Kucinich (a lot) for saying the things that needed to be said, but he was nowhere near viable.

I couldn't support Hillary Clinton because she voted for the invasion and occupation of Iraq (as did Biden). That, and I don't want another ruling family.

I like Chris Dodd a lot - smart guy, good record - but his relationship with the insurance companies was a little uncomfortable.

I like Bill Richardson for a number of reasons - record on foreign policy, record at the Department of Energy, he's governor of my favorite state, he isn't another white guy, etc. - and I was really pulling for him.

I didn't care for Barack Obama at first: his lack of experience annoyed me immensely, and I couldn't understand why people were talking about him. Just like with John Edwards, he came from nowhere to national prominence without actually doing something noteworthy, and I'm sorry, but I still believe you have to pay your dues, get your scars, earn your experience.

However, his choice of Biden addresses most of my concerns about experience (most), and Barry has earned my respect, which is no mean feat.

Look, he's been campaigning for almost two years now, he's been all over the country, he's talked to thousands of people, and he's managed to stay civil, focused, and commanding. Unlike the bitter old white guy running against him.

Barack Obama's campaign is and was much better run (ethically, financially, etc.). Both McCain and Clinton had poorly run campaigns during the primaries, and it doesn't speak well of their organizational abilities.

Barack Obama is smarter, more even-tempered, and more ethical than John McCain. No contest here.

Barack Obama did a much better job at picking his Vice President. Much, much better. I have always liked and respected Biden (apart from the Iraq vote).

Finally, Barack Obama is younger and healthier than John McCain, and the thought of Sarah Palin being anywhere near the oval office scares the hell out of me.

It should scare the hell out of everyone.

Look, we have some serious, serious problems:
  • an impending worldwide recession, possibly even a depression
  • the end of cheap oil, in a culture built entirely on cheap oil and with no viable alternatives in sight
  • global warming, massive habitat destruction, and an increasing extinction rate
  • the impending death of the seas from rising CO2 and increasing ocean acidification
  • religious fundamentalists, here and abroad
This is some terrifying stuff, and ignoring it, jumping in the SUV, and going down to the mall to load up on Cheetos and DVDs isn't going to change it.

I'm looking for someone who speaks to our better natures, who can inspire us to work together to make the world a better place, to lead us into the 21st century and away from fear, poverty, war, and ignorance.

John McCain is not that person.

Barack Obama is.

So get out there and vote. It really is likely to be the most important election of your life.

03 October 2008

Using devcon to update a driver

If you work with drivers, it quickly becomes a PITA updating them, although I've gotten quite fast at doing this on XP, thanks to muscle memory.

(Vista doesn't change the focus properly in the Device Manager wizard, by the way, so my muscle memory doesn't work on Vista.)

Anyway, it turns out there's a tool available from Microsoft called devcon: it lets you do pretty much everything from the command line that Device Manager does, and then some.

For example, here I'm using it to update a driver:











By the way, the grep I'm using is from UnxUtils.

02 October 2008

Excess commenting considered harmful

With apologies to Dijkstra.

I'm a big fan of comments, provided they're in the right place and convey the correct information.

While the near-total lack of comments in my current codebase irritates me, I also come across stuff like this in some of our common code which is utterly pointless:

//----------------------------------------------
// File: spizzbar.cpp
// Author: Earnest Programmer
// Created: 8/05/2008
// Purpose: Implements an API that will allow...
//----------------------------------------------
// Changed: never
//----------------------------------------------


Let's start with the lines of dashes which separate the comment block into regions:

//----------------------------------------------

I'll admit to still occasionally doing such things, and I'd argue in the case where you have a small set of headers (2, in the case of our current SDK) and the headers are likely to be the documentation users of the SDK are most likely to see, you can get away with such cruft, but 99.9% of the time, it's pointless (and I really need to stop).


Next, we have a line which tells us the name of the file:

// File: spizzbar.cpp

Umm, if we're reading the code, it's already in a file and it already has a file name and it came from version control, which can tell us all the different names this file has ever had, so this is also pointless.


Next, we have a line which tells us the name of the original author of the file:

// Author: Earnest Programmer

Aw, your mom sure must be proud. However, this information is also in the version control history, so why are you cluttering up the code with it?


Next are a couple of lines which tell us when the file was created and last modified:

// Created: 8/05/2008
...

// Changed: never

You can guess where this is going, so repeat after me: "this information is also in the version control history, so why are you cluttering up the code with it?" Nicely done, thanks.


Finally, we come to some lines which purport to add value:

// Purpose: Implements an API that will allow...

So let's see:
  • it's a .cpp file, so I'm pretty sure it's implementing something.
  • the API is in the matching header (presumably spizzbar.h), so the purpose of the API should already be documented there

In conclusion, there's no value here: the entire comment block is useless.

"So what's the big deal?", you may ask.

Fair enough: let's go through this.

Comments are no different than code: they have to be maintained, and useless comments are like dead code. Linkers usually strip dead code, but programmers spend most of their time reading code, so we're optimizing for that scenario.

Also, the DRY principle says you want to abhor duplication, so if you document a function in the header, you don't need to copy the documentation to the implementation. Otherwise, you'll have to maintain comments in both locations.

Finally, like every line of code, you should look at every comment and ask yourself: If I ripped out this comment and I or someone else came back in six months to look at this code, could we still understand the code? If the answer is yes, strip the comment.

I believe part of our focus as software developers should be on writing as little code as possible - most of the cost of software development is maintenance, and the more you have to maintain, the more it costs - and this extends to comments.

As the phrase misattributed to Einstein goes:
Everything should be made as simple as possible, but no simpler.