Monthly Archives: January 2008

Don’t Forget to Profile Your Code

Being a good developer is about a lot more than just slinging good code. After you’ve compiled your application you’ve really just begun. One important step that some developers forget is profiling.

If you’re a .NET developer make sure you run FxCop over your code. It’s a free Microsoft tool that checks your code both for performance issues as well as basic coding standards such as avoiding Hungarian notation, correctly casing variables and basic good practices. While FxCop is more geared towards framework developers it has some great performance checks and little insights into your code that can only make your applications better. Some of my favorites are warnings about unused local variables and property collections with setters, which rarely make any sense on a collection yet are so easy to do when you’re coding on auto-pilot.

If you’re a .NET or Win32 developer a great must have tool for profiling and checking over your application is AQtime. I’ve found more memory leaks and performance bottle-necks with this tool over the years that it’s easily paid for itself many times over. There is a lot to the tool and for the first year I used it I only used 5% of what this tool can do, and that was checking for memory leaks in our Delphi applications. I finally explored it’s profiling features when I was tweaking some XML parsing code and it really helps focus efforts one which lines of code you should really worry about vs. trying to optimize everything in sight.

Even if you don’t have any coin to spend try running FxCop over your .NET code, you’ll probably find a few interesting things and learn a bit about best practices.

.NET Framework Guts Exposed

Remember that scene in Star Wars when Luke (or was it Han Solo?) cuts open that crazy goat-beast thing’s belly and slides inside for life-giving warmth? Well the .NET guys have done the same today by making the .NET Framework Library source code available for nerdly enjoyment.

When I was learning CodeGear’s Delphi (still the best tool for creating native Win32 apps I must say) having the complete source to the VCL (the Delphi framework) was the best learning tool I could have asked for. Whenever I was unsure of how to code up a certain pattern I went trolling through the source and found inspiration. Sometimes I just browsed it for fun and other times it was a life-saver when it came to debugging and tracking down hard to find issues.

Even if you don’t think you’ll use it for debugging download it anyway and just browse the developer comments to see how the crew aboard a big ship like Microsoft treats their code.

Why does ASP.NET WebForms hate the ID?

Just needed to reiterate my hate for the way ASP.NET WebForms munge the id attribute on rendered HTML controls. Seriously, there is nothing more annoying than going to write a little JavaScript and wanting to grab an element by it’s id and you can’t because it’s been turned into “cntHolder1_cntHolder2_cxtPlaceholderArea98_lblButtonMaybe”. It’s obvious that whomever designed WebForms had never actually worked with HTML or CSS before.

If someone has an easy solution I’d love to hear it but this is one of the reasons I’m so excited about ASP.NET MVC.

Books That Have Influenced Me

My wife gets ‘O’, the Oprah magazine, and I have a bad habit of reading whatever is near me while I’m having breakfast and so found myself perusing an article where some celebrity such-and-such listed off the top influential books in their life which got me thinking of what mine would be. My list isn’t as deep or grand as theirs but it’s honest.

1. Stranger In A Strange Land

This book shaped a huge portion of how I view the world, religion, relationships, how to treated others and as a reminder to always question everything around me. Oh, and to laugh because sometimes that’s all we have. It introduced the new verb ‘grok’ into the nerd lexicon and to this day you’ll see it pop up anywhere nerds mingle. Stranded on a desert isle with only one book, this is it.

2. Perdido Street Station

A rich tapestry of weird with fine political stitching. A relatively new book compared to how long I’ve been reading but it still managed to work it’s way under my skin. It presented the concept of egalitarianism in a way that I hadn’t considered before and so thoroughly mixed genres that it was a real adventure to read. It came along at at time when I needed a jolt and this was just what the doctor ordered.

3. Hamlet

This will always hold a special place in my heart because of the memories I have of learning to read Shakespeare from my high school teacher Mr. Tosh. I’m sure that without the guided tour through Shakespeare’s language and the double and triple entendres I would have found this a rather dull read but instead I learned that just because something is old it doesn’t mean there isn’t bite or relevance and that some books should be read for their craftsmanship as well as their plot.

4. Your First Basic Program

Your First BASIC Program

This was the book that turned me into a software developer. I still remember the day my dad took me to the book store and helped me pick it out. I must have been all of 11 or 12 at the time and I’m pretty sure I picked it because of the really cool dragon illustrations on the inside and the big castle on the front. I read it cover to cover, over and over, until it was tattered and creased, all while learning the classic control, flow and looping constructs that every developer still uses to this day. In fact it wasn’t until the Gang of Four’s ‘Design Patterns’ that a single programming book had that much effect on me.

5. Acid House

Most people picking an Irvine Welsh book would probably go with Trainspotting but I never actually read Trainspotting, instead I read almost every other book he wrote and Acid House was the first one, the one I cut me teeth on learning to read his delightful written Scottish brogue. It begs to be spoken and I’d entertain myself for hours just reading passages outloud, chewing through brogue and feeling myself slightly transported to gritty Edinburgh streets. It was the first time a written brogue actually worked for me and I loved how much texture it added to the experience.

6. Towing Jehovah

I picked this up on a whim, mostly because of the quirky title, and ended up not only enjoying the story but viewing people’s relationships with religion in a different light. Having no strong religious affiliation myself I was exposed to some of the issues others struggle with as well as some very scary realizations about how certain people could act if they lost their faith. The concept of God being dead and having to be towed across the ocean was pretty much the perfect device to explore theology, culture and more without losing sight of the humor in life.

7. How To Be Good

I love this book because it highlights just how hypocritical we can be when we talk about how to cure the world of it’s ills. It slyly holds a mirror up to the reader with comical wit and satirical poking at what it means to be ‘good’ and how for as much as we talk about it how often we fail miserably. It got me thinking of my own actions and intentions and judgements and that maybe I shouldn’t cry foul on others before giving myself a good hard look. All done with of course the one element I need from any good book, humor.

I’m sure more will pop into my head but those are the ones that jumped out. I could of course go on and on with various books that I loved or just found greatly enjoyable, but I tried to pick books that actually had some impact on me besides just being a good read.

Mp3tag Action to Populate Album Artist

My favorite tag editor is Mp3tag and I use it at least a couple times a week to populate the album artist field that both WMP and Zune seem to depend upon for proper organization.  Instead of manually typing in each album artist field I use this handy script:

$if(%band%,%band%,%artist%)

Basically if the album artist field is already populated then I don’t touch it, otherwise I transfer the value from the artist field into the album artist field.  Mp3tag calls the album artist field ‘band’ but I don’t let that stop me.  If you feel like using it as well here is how to add a new action:

  1. On the menu select Actions –> Actions (or just hit Alt + 5)
  2. Click the ‘New’ icon in the upper right
  3. Give the action a name, I used ‘Populate Album Artist’
  4. Click the ‘New’ icon again to add an action type
  5. Select the ‘Format value’ action type
  6. For field select ‘ALBUMARTIST’
  7. For format string use: $if(%band%,%band%,%artist%)
  8. You’ll end up with a dialog that looks like this:

OK your way through everything and now you have an action to automatically fill out that needed Album Artist field and help prevent the silly ‘Unknown Artist’ folder that Zune seems to like to create.

To use the action it’s as simple as selecting the tracks you’d like to apply it to and then either bringing up the Actions menu from the menu bar or the toolbar icon.

UPDATE: Thanks Oscar for pointing out that you need to remove the space before the %artist% portion of the formula.  I’ve updated the post to reflect that (still working on the screen cap though).

UPDATE #2: I’ve updated the steps to reflect version 2.48 of Mp3tag, this post was a little crusty.  Thanks to Eric Nemchik for pointing out that ALBUMARTIST is now the correct Field vs. BAND in old versions.

Video Games that Should Be Made

The media world is cannibalistic, books become movies, video games are based on movies, books are written for video games with every permutation in between. Granted a large number of these tend to be real stinkers but every once in awhile something is actually gained in translation. Over the years a few movies and books have really stood out as prime candidates for the video game treatment, some of which are below:

"Ultraviolet"

This 2006 movie came out to some pretty bad reviews but since I'm a sucker for anything Milla Jovovich I laid down my hard earned cash to see this on the silver screen and the only thought in my head as I walked out was how great a video game it would make. It's high on visuals and fast-paced combat with a smorgasbord of "future talk" vernacular while not overly stressing the plot which is high on drama, low on surprises. In other words the perfect elements for a video game. It comes with built-in factions and feuds, uneasy truces, a bevy of places to draw talents/skills/powers from, vehicles, gadgets and even some mini-game ideas like driving up the sides of buildings and quickly shifting the direction of gravity.

As much as the style was ridiculed in the gaming press I see this as Shadowrun-style game play, quick rounds with chances in between to upgrade abilities and powers. It would need a single-player story though, there are just too many elements that wouldn't multiplayer well yet would be great in a solo or co-op fashion. Basically a slightly beefier Halo that's not so static in the initial player load-out during multiplayer.

Altered Carbon by Richard K. Morgan

Anyone that's read this book or any of the other Takeshi Kovacs novels, Broken Angels and Woken Furies, probably harbors the same thought I do, that these books are just crying out to be turned into a video game. There is already a great death handling mechanism in the form of "cortical stacks", basically backups that can be used to slot you into a new "sleeve" or body, which is where you have a rich source of player upgrades and customizations. There is even a black-ops force, Envoys, which work on either end of a game plot line, either starting as an Envoy and having to track down the baddies or working towards the ultimate goal of becoming an Envoy.

Given the detective anti-hero narrative of the books any game based on this franchise would need strong RPG elements, with a good plot, a bit of snooping yet a great combat system. I'm thinking a mix between Gears of War and Mass Effect with a heavy upgrade and player customization system.

Revelation Space by Alastair Reynolds

This is the first book in one of most intelligent space operas I've read in a long time. Great interweaving plots and layers of interactions are spread out across the books and there are some very distinct factions all with their own career and upgrade paths yet they do mix so you get some common equipment, plot and upgrade items. The books span a huge range of time and there are a ton of great events to center a game around as well as enough unwritten history that new timeline slots could be opened up.

Given the shifting alliances, rich characters and plot thick aspect of these books a RPG in the vein of Oblivion and Mass Effect would be perfect. A great twist would be to mix in some ship-to-ship combat and perhaps a sprinkling of the RTS genre, though I'd keep it grounded in RPG.

There are tons of books and movies that could be given the game treatment but these few I've listed seem like natural candidates, you can practically image the various selection screens and character creation systems. Of course they'd need first class treatment vs. the usual rush job with the hopes that fans will buy anything as long as it has they're favorite franchise name splashed across the front. I'd even put good money that someone has already approached Richard K. Morgan about licensing his world for a video game.