Tuesday, February 24, 2009

“Legacy Code is Code Without Tests”

I wish I’d come up with that phrase first, but it was Michal Feathers who stated this in his “Working effectively with legacy code”. It’s a great statement, and it pretty much sums up what testing is all about; if you’re not covered by tests, it is hard to refactor and change the code and at the same time know that you didn’t break anything. And if you have code that is resistant to change or that makes you nervous every time you touch it, then you have code that won’t be changed. You have legacy code. And you can try to wrap it, hide it, and forget it, but someday it will blow up. And someday you’ll have to go in there and make it work. But you won’t have any safety net. You’ll have to change something you do not know the reach of, and you’ll have to do it blindfolded and pray that your changes aren’t going to break something somewhere else. But I promise you; it will.

image And man I can tell you; it is good to be a consultant with skills in a technology where the software industry hasn’t had time to produce that much legacy code yet! That alone should be a good enough reason for you to invest some of your time into learning new skills. Skills that make you more valuable in the projects that produce new code, instead of maintaining legacy code that someone else hacked together years ago. It’s those green field projects that are fun!

And because there’s not that much WPF-based apps out there yet, there can still be time to save some poor souls from aiming at that same old pit of failure. The pit of strongly coupled, untestable, monolithic monsters. There’s hope and I believe in the goodness of coders. I believe that we want to make solid code. I believe that we want to produce code that is maintainable and changeable. And I believe that we, the residents of the software community, can make the leap into software craftsmanship. It’s just a matter of making those right choices. And I believe that loose couplings, testability and modularity are definitely the right choices in most cases. These are the key principles that will make you a better person (or at least a better developer).

Loose couplings and testability are tightly coupled (touché!). If you’re doing test-driven development, or behavior-driven development, or any other development practice that use tests to drive the design, you will end up with code that is loosely coupled. And if you’re building an app with loose couplings between modules and classes, you’ll end up with code that lends itself to testing very well. And testable, loosely coupled systems will be easier to maintain and change than a tightly coupled system with no tests to verify your code.

Modularity is another beast though. Modularity is about splitting the application in to pieces that multiple teams can work on in parallel - without getting in the way of each other. Modularity is about scalability and maintainability. Adding new functionality without ending up with a logarithmicimage time/functionality curve is an important factor in software development (maybe not for you and me, but for those white collars* that are deciding whether to fund or close down your project, predictability is extremely important). And modularity is about mastering complexity. How do you master too complex challenges? You break it down in to smaller, more manageable parts. And in software terms those parts are modules.

So if you take these 3 ingredients – loose couplings, testability, and modularity – and you shake it together with WPF (shake, not stir), you’ll have a fantastic opportunity to do WPF right. You’ll end up with code, not legacy code.

imageIf you’re in Stavanger on the 5th of March, Bergen on the 10th, Trondheim on the 12th or in Oslo on the 19th of March, you can hear me and my colleague Pål Fossmo give a talk on this topic at the MSDN Live event.

 

 

* Which btw just managed to bankrupt Iceland and is about to break the back of some of the strongest economies in the world… how the he** did they do that?!

Thursday, January 15, 2009

“A desk is a dangerous place from which to view the world”

A while ago a colleague of mine posted a blog about his desk at work. He used the words of Gunnery Sgt Hartman, and so I will be no less of a man;

DSC_0180-1“The Desk is a system. That system is our enemy. But when you're inside, you look around, what do you see? Businessmen, teachers, lawyers, carpenters. The very minds of the people we are trying to save. But until we do, these people are still a part of that system and that makes them our enemy.”

(almost a quote from the great Morpheus)

This desk fetish was picked up by Anders Hammervold, which again challenged Joar Øyen, which again challenged me… And since Joar also challenged Pål Fossmo – who still haven’t published his desk – the pressure is now on The Reverend…

Oh, and before I forget; that quote in the title is by John Le Carré. A fabulous quote if I may say so.

Sunday, January 11, 2009

Custom iTunes installation

I love my iPod and I use it almost every day. Mostly I'm listening to podcasts, but also music off course. But I hate iTunes. Or maybe that's a bit strong. I hate the iTunes installer. I think it’s all too intrusive and it doesn't give me all the choices I feel that it should.

ipod If you go to the download page on iTunes’ web site and download the iTunes 8 version suited for your operating system, you’ll get an iTunesSetup.exe file. If you’ve tried to run this file, you might have noticed that you also end up with a bunch of apps and services that you didn’t asked for. This includes;

Bonjour – Apple’s take on implementing the Zeroconf for discovery of services on a local network. The only reason why I might need the Bonjour service, is if I want to share my iTunes library on my LAN. But for now, running iTunes on a single machine, there’s no reason to have this service running around wasting resources.

Apple Mobile Device Support and Mobile Me – Both of these are meant for synchronization between a computer and an iPhone/IPod Touch. I only have an iPod Nano, so why would I need a service to sync between my pc and something I don’t have?

Apple Software Update – This service will check for new updates on regular intervals, just like Windows Update. Luckily it won’t install anything automatically, it will only notify you if there’s a new iTunes version and let you decide if you want to download and install.

QuickTime – I’m not even going to start elaborating why I dislike QuickTime so much. It would just make me angry. Luckily, there are alternatives.

The last one in the package is off course iTunes itself.

As you might have guess by now, there are only one or two out of six that I actually want to have running on my pc. And it’s really not that hard to actually get it that way. It turns out that the iTunesSetup.exe is just a self-extracting package that contains installers for all of the apps and services above. So if you’d like to have a custom install of iTunes without the nagging apps and services that comes out of this black box, you’ll need a packaging-app like WinRAR or 7-Zip. Then you can just extract the iTunesSetup.exe and delete the parts you don’t need/like. The only thing to be aware of is that iTunes requieres QuickTime, but if you’ve installed QuickTime Alternative before running the iTunes installer, you’ll be safe and sound. So to make a short-list of how to install iTunes only and keep your system a bit less cluttered;

  1. Download and install QuickTime Alternative
  2. Download, but don’t install iTunes
  3. Extract ‘iTunesSetup.exe’
  4. Delete the files you want need. For me that means everything except iTunes.msi and AppleSoftwareUpdate.msi.
  5. Open the command prompt, navigate to the folder where you extracted iTunes.msi, and run the following command; msiexec /i iTunes.msi /passive
  6. If you’d like to be reminded of new updates (which you definitely should), run the same command for the updater service; msiexec /i AppleSoftwareUpdate.msi /passive

(If you want the regular GUI-based installation, you can just skip the “/passive” parameter (or just double-click the msi-file in Windows Explorer).)

Now, I didn’t figure out all this by myself. Google helped me find this article by Ed Bott and this thread over at the PC Pitstop forum.