Sometimes I wonder if we (as software developers) should have some form of a code of ethics, where violations can get you barred from writing software in the future. Mainly, this would apply to the spyware/malware developers (or perhaps the ethical violation is more directable to those who bundle the spyware).
If this ethical code existed, I would add a violation for any application that did not inform and offer a choice to the user at install time that some startup or background task will always be running. Some typical offenders are QuickTime, Real, Adobe, Microsoft Office, Microsoft Messenger, printer driver "status monitors", and more. These startup applications increase boot time and memory/pagefile requirements. Most of the time, I don't use these applications each time I boot the PC.
If the goal is to make your application start up faster (or appear to start up faster) there are ways of accomplishing this. Rebasing your DLL's, background/on demand loading of plugins, delay loading dependent DLL's, etc. are a few common tricks that can be used. The utility "Adobe Reader SpeedUp" accomplishes a magnificent improvement in load times, and this doesn't involve rewriting any of Adobe's code. If you wrote one of these startup applications anyway, at least offer the user the option at install time if they wish to use it.
Saturday, March 12, 2005
Application Preloading at System Startup
Checking or Changing System Settings
Raymond Chen reminded me of a story I wanted to share. In non-MSI setups (and I am only using setups as an example of a larger problem in application programming), installing a service was a bit strange and usually flaky. Some installation engines would simply write the service registry keys directly into the "CurrentControlSet" section of the registry and require a reboot for the service to work. The reason was the Service Control Manager only looks at that portion of the registry when the machine is starting. Some engines decided to write values to the HKLM\System\ControlSet001 key - an even worse idea. Recall that "CurrentControlSet" does not really exist, it is mapped to the "real" ControlSet001 or ControlSet002 based on how the machine was booted. This is sort of like the HKEY_CLASSES_ROOT virtual key I blogged about before. If you need to query information about services, install them, etc. use the API's intended for this purpose - not the registry keys. Not only is this good advice for services, but in general. If you are using a registry key to check or change a setting, check for an API to set/check for the setting first. This generally isolates you from potential incompatibilities across future OS versions.
Raymond's post relates to User Interface settings, and describes an application that crashed under Windows 2000 because of the reliance on registry keys and not API's. Rephrasing my earlier point - if there is an API that reads or writes registry key data, it should be considered "Private".
One commenter to Raymond's post responded "sometimes its extremely hard to find the right api, with so many apis hanging around" - and he is 100% correct. This is where having experienced people around your development shop helps. If you don't have the former, this is a case where reading portions of the MSDN library (and blogs like Raymond's and Larry's) helps. If you are short a photographic memory, you won't retain everything - but you may remember reading something in the past and a few keywords that you can Google for later. Microsoft can help programmers avoid this trap somewhat by adding the keys that are read from or changed by API's in the MSDN documentation with a disclaimer - "The following key stores data related to this API but should not be relied upon as an implementation detail in future OS releases."
Sometimes it is hard to follow these "rules." Take for instance the Distributed Transaction Coordinator, or DTC for short. If you wanted to get or change any particular setting related to DTC you can't do it the same way across OS versions. In Windows 2003, there is the IDtcNetworkAccessConfig interface you can use. To change the same settings on Windows XP, the registry appears the only option. Furthermore, the upcoming Windows 2003 SP1 DTC changes (which mirror the XP SP2 changes) has not updated the API to reflect the change (at least in the SP1 RC2 version of the SDK documentation). Specifically, there is no updated method of allowing or disallowing specific transaction permissions such as inbound or outbound, so the API is useless - back to registry keys! Checking the DTC authentication level never had an API - just some registry keys documented in a KB article. I hope they fix this oversight for the final SP1 release - but in the meantime, what is a developer expected to do?
Saturday, February 26, 2005
Code Quality and the "Total Software Product Quality Triangle"
Today I came across "The Code Quality Myth" by Frank Sommers. Several quotes in the article really hit home. I could have written some of this essay. For instance, "I have almost never met a developer working on real-life, production software in a business environment who was completely satisfied with the code he was working on."
The code I am "proudest" of is typically short, "one-offs". This is typically stand-alone software or routines that serves one tiny purpose and is not tightly integrated into a larger product. Usually this software is not written under deadline, and is almost always a version 1.0 or a complete rewrite with few aspects of backwards compatibility. I am usually very proud of software when I have time to "do it right," and the quality is generally the best possible that I can produce.
Frank pretty much echoes my above sentiment with "I almost discern an inverse relationship between how satisfactory a piece of code is to the developers working on that code, and the amount of money that code makes for those developers' employers." Commenter Robert to that essay asked for metrics on that statement - I think he misses the salient points I am about to cover here.
Frank later talks about how the source code is not what we ship, and that only the binary matters - since this is typically all that the customer sees. This is where our opinions start diverging, and Frank misses one point that is staring him in the face: Why is this the case?
After 1.0 is released, or when that pristine little one-off class is integrated into a larger program, things start to go sour. Now we have to start working on new stuff and maintain backwards compatibility with the old stuff. It may be quite clear that the current API or XML Schema is not perfect for the new feature. Rather than refactoring or rewriting, we (as developers under a deadline) merely attempt to shoehorn the new feature into the old codebase. This is not perfect, pretty, or something to be proud of - but we think that we will be able to "do it right" for the next iteration, whose time ultimately rarely ever comes.
Besides the "shoehorning" there are other issues. Perhaps you want to move from the Old Hungarian into the New Hungarian. Perhaps there is a new "coding style" that you are supposed to use from now on. Different programmers working on the same class introduces some additional considerations. Maybe all of your string manipulation functions from today forward are to use the new "strsafe.h" functions. Whatever the reason, this results in fragmentation of your codebase. Some of it is the "new" way, some of it is the "old" way, and you get that massive maintenance programmer headache when attempting to context switch between two or more different coding philosophies in the same routine! Are you proud of this mess - heck no! Is this improving overall code quality and maintainability? Likely not!
The last thing that spices the code up a bit are platform differences and/or new technologies. Maybe you are porting a single class at a time to UNICODE and have ugly #ifdef's all over the place. Perhaps you want to take advantage of http.sys in XPSP2 and Server 2003 while still working under OS's that don't support it. Plus, that hack-around for people with IE4 installed is still lurking in the bowels of the core program. While this may assist in code "robustness" it certainly does not contribute to overall quality or maintainability.
In short, ALL source code gets uglier with time. For many reasons it has to. A solid developer knows that he or she can do much better in a rewrite with hindsight as our guide. An experienced (pre-agile) developer will architect classes with some degree of foresight (and bloat) to help mitigate this. The experienced agile developer (working with an organization that uses the agile philosophy) will write the bare minimum such that the affected classes need to be refactored for any major change to mitigate hacking around.
Planning for dealing with these future changes is what can help lessen the ugliness of the underlying code. In my opinion, the agile refactoring philosophy is one of them. Too many development organizations fear refactoring as "introducing risk" from 1.0 to 1.0.1 instead of fearing future effects of hack-arounds. This fear is unfounded (since it is easily mitigated with automated unit testing), and the tradeoff in having quality code vs. unmaintainable goo to propagate forward into the next major version is a no-brainer. Consider that the 1.0.1 fixes will be integrated back into the mainline. Is the fix you are making the correct one for the future? Does the fixed code look the same as it would have been written in 1.0 had it worked?
This is where Frank and I start converging again. "...total product quality, as Edwards Deming noted, is not the result of merely improving the quality of a single activity, but is rather the outcome of a set of processes focusing on the quality of the total output... Developer testing, agile development methods, quality assurance, continuous integration - these are all processes that facilitate a high quality of total output." We begin to diverge from there almost immediately.
To use an analogy that Steve McConnell did not, overall software quality is similar to the "Fire Triangle." To have fire, there needs to be Oxygen, Heat, and Fuel. Note that you can have all three without actually having fire - as fire is the result of the chemical exothermic reaction that occurs when all three of the other elements are present under the right conditions. Once fire occurs, take any one of these elements away, and there is no more fire.
In software development, I propose the "Total Software Product Quality" triangle. The three components are "Solid Code", "Complete Unit Testing," and "Continuous Integration Testing." In the presence of a "solid management process" that combines the three elements under the right conditions, we can have "Total Software Product Quality." Take any one of these elements away, and there is no more total quality - only fires that will need to be put out later at a tremendous cost.
Thursday, February 17, 2005
Random thoughts
I apologize for not posting much lately. I've been fairly busy are work and some other side projects. I do have some nice articles planned for the upcoming weeks - from some installation related stuff to some specific Win32 programming topics (http.sys is one of them). Plus, I plan to finally publish the custom action dll sample for MSI that I've been promising since forever.
First, let me thank "G-Man" Geoffrey for offering some server space to store the custom action stuff. Also, thanks to Tim for kicking me in the behind for not addressing the Steeler's loss after the last posting - we simply were beat by a better team. Google's Ad program thinks this blog is completely sports related now! As a side note, Tim touched on the whole Mark Jen story, and I concur 100% with his thoughts, especially his 'fourth criteria'. You will notice that I don't even mention my employer in any way nor blog about work related items that are not general domain knowledge.
Looking at some blog stats, my largest referral was from Joel on Software. Second was referrals related to a tablet pc review I did a while back. G-Man is the third best referral, closely followed by Aaron Stebner. I don't get too many off-topic Google search queries, and MSN Search ignores me completely. Heck, there are 12 referral URL's in their index, plus I submitted the URL months ago, yet not one page was indexed yet!
I'm actually surprised that the MSI Custom Action in script topic keeps coming up elsewhere. Of course, when you look at some strange behaviors in the Scripting engine, I can see why! Not that any of us would write code like that anyway...
Saturday, January 22, 2005
Go Steelers!
In my hometown of Pittsburgh, PA we are in the midst of "Steeler's Mania." For my international readership, the Steelers are my local American style NFL football team. We are about to play in the AFC Championship game against the New England Patriots this Sunday (January 23, 2005) at 6:30 PM EST in Pittsburgh at Heinz Field. Assuming we win this game, we are off to the Super Bowl!
My normally revolving blog banner was changed to a panorama of Heinz field to celebrate this game. Some interesting tidbits about the stadium involve the implosion of the previous stadium (Three Rivers Stadium), some interesting specifications about the new stadium (including some construction pictures), and the difficulty it presents for kickers.
Our quarterback, "Big" Ben Roethlisberger is poised to become the first "rookie" to lead his team to the Super Bowl. Ben has become quite the Pittsburgh hero, having both beef jerky and hamburgers named after him, joining him in the same club as some of other elite Pittsburgh sports players.
Throughout the season, I have been disappointed in the quality of commentary presented by the television media outlets. My preferred way of enjoying a Steelers game (aside from being in the stadium) is to watch it on TV, but with the TV volume turned off, listen to the radio broadcast. Long-time (34 years!) Steelers announcer Myron Cope's birthday happens to coincide with the game on Sunday. I think a Steelers win, plus a Happy Birthday song at the end of the first quarter by the game attendees (As suggested by broadcaster Ellis Cannon) would make a wonderful present!
Myron was the inventor of a fan prop known as the "Terrible Towel," which is a bright yellow towel emblazoned with the "Terrible Towel" logo. It all started as a gimmick so that Myron could pretty much keep his job many years ago. Myron's take on using a towel for this gimmick was: "I'll tell 'em they can use the towel to wipe their seats clean. They can use it as a muffler against the cold. They can drape it over their heads if it rains." Aside from the practical, it provided both color and motion in the stadium. Any Steelers game, at home or away, you can be sure to notice the Steeler's fans because of these waving towels.
Myron is known for expressions known as "Copeisms" - especially the term "Yoi!" - meaning good - and its variants (double and triple Yoi's), with some Yiddish terms thrown in for good measure.
Watch out, New England Patriots, the Terrible Towel is poised to strike! Go Steelers!
