Jul 28
Commenting out old code kills puppies
icon1 Darrell Mozingo | icon2 Musings | icon4 July 28th, 2011| icon31 Comment »

There, I said it. Actually, I’m kind of worried that title won’t adequately state the intensity of this situation.

This is one of the fundamental reasons we have source control people, so we can go back through a file’s history and see the different revisions. Please, for the love of all that is holy, don’t comment out old code. Just delete it! Feel free to slap your own knuckles with a ruler if you start to think about commenting it. Don’t try to recreate a source control system through commented out code. Everyone knows exactly what I’m talking about:

// John Doe - 7/5/2011 - Changed to allow a higher limit.
// dozens of lines of old code....
// John Doe - 7/18/2011 - Changed algorithm slightly.
// dozens of lines of old code....
// random dozen lines of old code with no comment at all
public void ActualCode() { }

Those extra comment chunks are just crap to sift through to get to the real code, extra stuff you’ll have to parse to see if it’s relevant to the current situation, and creating more false-positives for ReSharper (and I’m guessing other refactoring tools) to pick up when you rename a variable/method that’s used inside those commented chunks. That chunk of old code at the bottom without even a hint as to why it’s commented out? That’s the worst of the worst – someone’s going to sit there and stare at it for a good while before they figure out why it was commented out, and we know when the author actually committed this file with that commented out the commit comment was blank too. Awesome.

So anyway, just remember what actually happens the next time you’re about to comment out old code and don’t do it, you’ll be doing future programers (and more than likely yourself) a huge service…

Commenting code kills puppies

Jul 20
Consistent modal dialogs, the easy way
icon1 Darrell Mozingo | icon2 Web | icon4 July 20th, 2011| icon3No Comments »

So we all know the default alert dialog box visually sucks. Any of the hundreds of jQuery modal plugins work wonderfully for replacing it with something a bit snazzier (although putting the information on the page for a user is even better, but that’s for another post). The biggest problem with most of those dialogs are either the setup cost, or the memory cost:

  • Setup cost: having to set heights, widths, button names, text & title fields, yada, yada, yada. A lot of that can be skinned through CSS, and a lot of plugins reduce that noise to virtually nil, but many leave a lot on your pages. It’s ugly to look at in your code, and ugly to configure. Not to mention all those config settings spreads through your code base like the freakin’ ground ivy is spreading through my lawn as I type this. Want to change the widths for a new redesign, or localize the button names? Good luck!
  • Memory cost: relates to the Pit of Success. Do you really want the burden of always remembering to use that modal dialog instead of alert? What about the new guy, is he going to know or remember? Sure, forgetting isn’t that big of a deal, but given enough slip ups and your nice consistent UI goes to hell. Tests checking for calls to alert are also possible via straight searching through files or through UI tests some how, but I can see a future of false positives ahead of that idea.

How about a better way? With some very slight Javascript-foo, you can override the default alert and confirm dialogs so not only is there nothing to copy & paste between pages, but you don’t even have to remember to use your nifty modal boxes – it’ll just happen. We’ll use the jQuery UI Dialog plugin inside a stock ASP.NET MVC app, though this is easily transferable to any other platform or with any other modal plugin.

First we’ll override the default alert method on the window object, calling the dialog function from jQuery UI and setting some default parameters:

window.alert = function (message) {
	.html('<span class="ui-icon ui-icon-alert custom-ui-icon"></span>' + message)
		autoOpen: true,
		resizable: false,
		height: 200,
		width: 350,
		title: "Alert!",
		modal: true,
		buttons: {
			"OK": function () {

The HTML is cleared out and a default alert icon (from jQueryUI) is added via the class attribute ui-icon-alert. This allows us to create a standard <div id="dialog"></div> in our master page with nothing inside it, and reuse it for alert/confirm/prompt boxes. Then a standard alert call, like the one at the bottom, gives us:

Alert modal dialog vs
Default alert

Similarly, we can override the default confirmation box. Here’s a version that’ll take the title, a message to show, and a callback function to execute if the user clicks “OK”:

window.confirm = function(title, confirmMessage, successCallback) {
		.html('<span class="ui-icon ui-icon-help custom-ui-icon"></span>' + confirmMessage)
				autoOpen: true,
				resizable: false,
				height: 200,
				width: 350,
				title: title,
				modal: true,
				buttons: {
					"Yes": function() {
					"No": function() {
confirm("Are you sure?", "Are you sure you want to create a confirm?", function() { alert("Sweet, all done!"); });

Again, compare the results (the first question mark is an icon from jQuery UI, which can also be changed with the class written out in the confirm method above):

Modal Confirm vs
Default Confirm

Pretty neat, if you ask me. This whole thing is very DRY, as everything you need is referenced in your master page (the dialog div, the javascript & css files, etc) and your individual pages don’t need to include anything – just call away. You also don’t have to remember to call special methods (or at least terribly special ones in confirm‘s case). It just works.

It’s not too hard to imagine extending this system to override the default prompt box either. Just pass in a callback that’ll set whatever string you need, similar to how confirm works above. Closures work wonders.

You can grab the code used in this post right here.

Jun 26
The Pit of Success
icon1 Darrell Mozingo | icon2 Design Principles | icon4 June 26th, 2011| icon31 Comment »

Pit of Success

I’m a huge believer in the Pit of Success. Quite a few have written about it before, though not always in development terms. Put simply, there’s two pits you can create in your application through conventions, infrastructure, culture, tools, etc: success and failure. I obviously choose the former.

The Pit of Success is when you and the other developers on your team have to think less about the mundane stuff and when there’s only one easy development path to follow. Less thinking about crap = more thinking about business problems = faster software with less bugs. In general, if I see something that’s going to be in a lot of classes/pages and it has a decent bit of setup and baggage for it, I instantly picture another developer forgetting to bring all that along when they start new features or refactor. If things break (visually or programatically) when that happens, there’s a problem. Same goes for huge chunks of documentation explaining how to use a certain feature elsewhere in the system – time to make it easier to use! Here’s a few examples of how we’ve dug out a Pit of Success on our current project:

  • Need to create a new schedule task? Drop in a class and implement a simple interface. That same principal goes for a slew of other areas – missing information checks for users, HTTP handlers, sample data for geographic areas, etc. You don’t have to go hunting down a master class to add these new things to, just create the class and you’re golden.
  • Security in our system isn’t that complex yet, so we’re able to consolidate everything in a nice tidy ActionFilter. It’s applied to our custom controller, and we have a unit test that makes sure all Controllers in the system inherit from that custom one. So by following the rules (on your own or with the help of a broken test), you get security handled for you auto-magically.
  • We continuously deploy with our build server, so it takes care of not only making sure all our unit/integration tests pass, but that all the needed debug settings are flipped, sites are pre-compiled, everything still works once it’s live, etc. That saves us from remembering to do all that every time we push live, which is almost constantly these days.
  • We completely agree with Chad Myers, Jeremy Miller, et al: if we’re working with a static language, make the best of it. Everything in our system is strongly typed, from text box ids in HTML/Javascript/UI tests to URLs and help points. You shouldn’t have to remember to go hunting and pecking through the whole system when you want to rename something, just rename it with ReSharper and move on. Same with finding where something is being referenced. The harder it is to rename things, the less they get renamed, and the crustier the system gets.
  • We started creating one off modal dialogs to present information to the user. They looked great, but needed a lot of baggage and duplication to do it, so we overrode the default alert and confirm dialogs with our modal ones. Now there’s not only nothing to add to your page to get this, but in most cases you don’t even have to remember we’re overriding it! There’s a forthcoming post that’ll cover what we did in more detail.
  • We have a unit test that’ll scan through all of our test files (which end with *Fixture), and make sure there’s a file name that matches (sans the Fixture part) in the corresponding directory structure in the main assembly. We constantly move files around when refactoring, and forgetting to move or rename their test files is a pain, so this test gently reminds us. Note we don’t always follow a one-class-per-fixture setup, but even when we don’t, we stick them in a matching fixture class for easy grouping and ReSharper discoverability.

It’s worth noting we didn’t set out from day one to build all this stuff. Its all grown over time as the project and our stakeholder’s needs have changed. We always strive to keep KISS in mind (even if it is hard) and not build anything until it’s absolutely needed. Don’t try to create infrastructure to handle everything for you when a project’s in its infancy. Harvest it out later.

There’s also exceptions to all of these rules. Is automatic security always the right thing to do? No – if you need highly configurable security, put it out in the open and remember to set it on each request. Don’t force things into the infrastructure if they’re fighting you and have lots of exception cases. Perhaps there’s another route of attack that’ll solve the problem and still keep you circling around the Pit of Success.

You’ll create your own Pit of Success on your project just by falling into the bigger Pit of Success that is the SOLID principals. The majority of the examples up there were arrived at by just adhering to the Open/Closed Principal or the Single Responsibility Principal. They create a sort of recursive pit, I suppose.

What have you done on your projects to help create a Pit of Success?

May 27
Canton Software Craftsmanship
icon1 Darrell Mozingo | icon2 Events | icon4 May 27th, 2011| icon3No Comments »

Just a quick reminder about the next Canton Software Craftsmanship meeting on June 6th. It’s the usual 6pm at Stark State College with free pizza and drinks, and sponsored by Synergy Data Systems this month (who’s coincidentally looking for another junior C# developer, if you’re interested). Asher McCune will be giving a talk on the Open/Closed Principle (the O in SOLID) and we’ll be doing more katas together, trying to push the pairing aspect and getting everyone to work with different partners.

Hope everyone can make it! Please don’t forget to register right here so we have a head count for pizza.

May 24
Code Katas
icon1 Darrell Mozingo | icon2 Misc. | icon4 May 24th, 2011| icon3No Comments »

I added a page listing a bunch of code katas, mostly for my own reference, but I guess you guys can mooch off of it too.

Let me know if I’m missing any. I’ll expand the page as I stumble across more.

May 9
StirTrek: Thor Edition
icon1 Darrell Mozingo | icon2 Events | icon4 May 9th, 2011| icon3No Comments »


I went with a few co-workers to Stir Trek this past Friday. They’ve put an event on for the past two years, but this was the first one I’ve been to. It was an excellent event. Good talks, very well planned out, and a pretty decent movie to boot! Here’s the talks I went to:

  • Are You Satisfied With Your Tests? (Jim Weirich) – Jim gave a good overview of testing (do it, make them fast, etc.) and tips (clear naming, refactoring, when to combine/split tests, etc.). Overall pretty good. My co-workers gave a laugh as I harp on many of these points all the time already.
  • Node.js – Show and Tell (Leon Gersing) – A neat explanation of this async javascript framework. Leon gave a demo of a simple client/server chat setup, and a run down of a slightly more advanced website. I hadn’t seen any Node.js stuff other than very broad overview articles, so it was cool to get the explanation of when/where to use it, and look at working examples. Unfortunately he ran out of time before getting to the testing examples, but I guess that give me a place to start in my personal learning.
  • Testable Object-Oriented JavaScript (Jon Kruger) – One of the better talks I attended, as it tilted more towards the intermediate/advanced level than others. Jon walked through a live demo of building out a simple Twitter client by test-driving the javascript with Jasmine to run the tests, and his custom JS View framework to fake out the HTML. Pretty darn neat, and I’m looking forward to digging into it a bit more for our new features, as they’ll be far more client-side dependent than previous ones, and we haven’t gotten to the UI part just yet.
  • Getting Started with User Research: DIY Quick Course (Carol Smith) – Carol went over the basics of user research via interviews, observance, and card sorting, which helps you structure you application’s layout to match how users would expect it to be. Very helpful for a high-level overview talk, and gave me a few tips to pursue with getting information on our application.
  • Testing Web Applications with Selenium (Jim Holmes) – I was definitely looking forward to this talk the most, and it didn’t disappoint. We use Watin at work and have only dabbled once in Selenium, so seeing how he structures his tests was helpful. Unfortunately he spent 80% of the time going over a basic UI test and overview of Selenium. By time he got to the lessons he’s learned from running 14,000 some-odd UI tests, he ran out of time. Booo. It was actually quite comical… “OK, now the most important things you need to know… I’m out of time, aren’t I?”. A few of the database/browser handling tips will come in handy for our UI test suite though, and I’m looking forward to giving them a shot.

I really wanted to hit up the GitHub talk, executable requirements, and a mobile talk or two, but I guess there’s always next year. Overall it was an excellent conference, and the peeps that ran it did a great job. Thor itself turned out to be pretty decent flick, too.

They already scheduled next year’s version in May: StirTrek Avenger’s Edition. Looking forward to it!

Apr 11
Know your tools
icon1 Darrell Mozingo | icon2 Musings | icon4 April 11th, 2011| icon34 Comments »


How many carpenters do you think don’t know about kerf widths? How many plumbers don’t know the difference between MAPP and propane for soldering? Probably not many.

Masters of their craft know their tools inside and out. They don’t just skirt by barely knowing how to use them, and end up taking longer to complete a job because of that. We have the same situation in our craft. We use tools day in and day out – our IDE’s, debugging tools (for our main languages and web based ones), OS, browsers, websites, etc. They’re all tools of our trade. Learning how to really use them is just another stepping stone on the path to being a craftsman.

The best way to really make use of your tools and increase your programming speed is to ditch the mouse. Use the keyboard as much as possible, which can be almost everything. Really get good with the keyboard and you’ll be amazed at how much more efficiently you can pump out code and navigate around.

I use Windows and Visual Studio, so I’ll use that as an example. Visual Studio itself has a metric ton of built-in keyboard shortcuts, but add ReSharper to the mix, and you’re golden. Check out the keyboard shortcut cheat sheet, it’s ridiculous, and overwhelming. Pick one or two shortcuts you think you’ll use, then use those exclusively for a week. Make sure to purposely use them as much as possible until they become muscle memory. It won’t take long.

Look at Tools -> Settings -> Keyboard. There’s lots of stuff you can key bind on your own that doesn’t come setup by default. Create a key combination to run your unit tests rather than reaching for the mouse. If a default key combo feels unnatural for you, rebind it. Find something that works for you, and don’t be afraid to experiment.

Start learning keyboard shortcuts in other programs you use on a regular basis. There’s cheat sheets for GMail and Google Reader. For your mouse-free text editing needs (and IDE needs if you’re super experimentative and working with .NET) there’s the grand-daddies themselves: VIM and Emacs. There’s even plugins for Firefox (Vimperator) and Chrome (Vimium) to make each browser navigable in a VIM-esque way, and other plugins for each browser to simply add more keyboard navigation tricks. Heck, there’s even a few VIM plugins for Visual Studio itself if you want to go all the way, including ViEmu (paid) and VsVim (free).

It’s also super helpful to get a keystroke launcher on your box, such as Executor (my personal favorite) or Launchy. These guys basically give you the standard Windows Run dialog on steroids – letting you make custom launch commands and scripts. Definitely play around with one of these and work it into your normal workflow. I find myself leaning on it all the time.

So start practicing with a keyboard-only setup today. Disable your mouse driver and force yourself. It’ll kill your productivity in the short term for sure, but it’ll pay dividends every day for the rest of your career once you get used to it. You’ll thank me in a few weeks. Seriously, I’m marking my calendar.

Mar 31
Canton Software Craftsmanship
icon1 Darrell Mozingo | icon2 Events | icon4 March 31st, 2011| icon3No Comments »

The next Canton Software Craftsmanship meeting is this Monday. We’ll be going over TDD basics by having everyone follow us along on simple exercises.

Register here if you’e interested.

Hope to see you there!

Mar 8

Thanks to everyone that attended the first Canton Software Craftsmanship meeting this past Monday. It was a great turn-out (around 33 people?) and everyone seemed genuinely excited to see where this goes, myself included. Good food and good discussions all around. Sign up for the next meeting on April 4th if you haven’t already, and be sure to spread the word to anyone that might be interested. Remember, we’re about the practices, not the language, so everyone’s welcome.

I’d also like to thank Brandon Joyce and John Hoover for doing a great job with the logistics needed to get this group off the ground. Great job guys!

Mar 4
Taskie runner is now bundled
icon1 Darrell Mozingo | icon2 Taskie | icon4 March 4th, 2011| icon3No Comments »

The latest version of Taskie (which is available on NuGet) now comes bundled with a console runner. Simply implement ITaskieServiceLocator with your IoC container of choice, and put your compiled assembly with that implementation in the same directory as Taskie.exe. Taskie will pick up on the implementation and use it like normal.

This should reduce the usage overhead if you don’t feel like creating a virtually empty console project in your application, and lower the getting started barrier even more. If you’d still like to host your own console application for Taskie, that option will continue to be supported and its usage hasn’t changed.

« Previous Entries Next Entries »