Testing Regexes

Recently I had to implement a Regular Expression (Regex) to validate that a property was a certain length. The validation rule was:

String should be  3-4 characters in length, first 3 must be numeric, third must be greater than 0. and fourth (if provided) must be alphabetical.

Since I rarely write Regexes, I generally catch up with the .NET Cheatsheat, or reference my copy of Mastering Regular Expressions. There is even a free tool online (created using Adobe Flex), that allows you to test and create Regular Expressions in real time.



[Author’s Note: This was actually written on 2/25/2010. I went looking for it to find the link to the Adobe flex tool and realized that I’d never published it. I’m publishing it now, especially because I goofed on the original requirements and have to refine my regex.]

Past Prologue

When I was younger, my 9th Grade English teacher, a gentleman by the name of Mr. Hurd, told my english class an anecdote I’ve never forgotten:

There was a child about the age of 13, his friends were astonished to see the advent of television. He was not. They would go on and on about Cowboys, Indians, Cops and Robbers, and he would quietly read his books.  They asked him one day, “Why don’t you watch Television? The shows are amazing!”.  His answer: Everything that had been done for television has been done before for books. There is no need to watch Television, I know how it ends.”

I remembered that anecdote as I read Joel Spolsky’s latest Blog post:

Philip Greenspun and Dave Winer (with DaveNet, even before Scripting News) pioneered the Internet Pundit style of essay writing which has served so well for fifteen years. They started as lone voices in a new medium, but the genre spread like wildfire. It was perfectly prognosticated in the 1990 Christian Slater movie Pump Up The Volume. If you’ve already forgotten it, here’s what happens (not a spoiler): Slater plays a kid with a low-power radio station in his bedroom, broadcasting in the middle of the night to the other isolated, angsty kids in his high school. Interesting drama ensues. 102 minutes later, by the time the credits roll, high school kids everywhere are spouting their opinions on their own pirate radio stations. And that’s exactly what happened with blogging, until we got where we are today, with millions of people expressing themselves and using the exact same narrative techniques and stories and styles that the first bloggers pioneered. (emphasis mine)

It was at this point that I resisted the urge to yell KHHHHHAAAAAAAAAAAAANNNNNNNNNNNN!!!! at the top of my lungs, and that wasn’t even the coup de grâce:

We need something that reflects the best new ideas about what authorship means in 2010, not just electronic forms of 18th-century pamphlets. We need to stop rewriting the same things again and again (fail fast! NDAs are worthless! Execution matters, not ideas! Use the right tools for the job!). Instead we should start filling in the long tail of knowledge. (emphasis mine)

I passed out right around the bold part.  This very thing he is railing against  is exactly what I’ve been writing, the same thing that my English teacher had railed against over a decade earlier. 

Everything I have been doing is doing everything old over again. I’ve become trendy. This is not good

So the question becomes: Do I continue what I’m doing, regurgitating years old advice with my own little anecdotes attached, or do I do something else.

I don’t know.

I do know that I love to write, and I love software. I love chocolate cake too; but I’m not sure that’s relevant. Normally I’d write some sort of call to action or some sort of resolution, but here I have none: Just the idea that if I do continue to write for something that’s published publicly, I need to bring something unique to the table.

The Project Dashboard

Quick, where is your project at?

Now, does everyone on your team know that information?

Ah ha. Gotcha.

If you’re an agile shop, then you probably hold Daily Standups. If you aren’t, then you probably hold daily Sitdowns (see also: boring meeting).

As everyone talks about their status in those meetings, everyone else is busy breaking Company IT policies. Only Youtube gets a pass (it’s really hard to watch a video with sound in a meeting. People tend to stare). At the end of the meeting, everyone who is still awake heads back to their desk. The management types (of course) schedule another meeting, and the cycle repeats itself.

Break the cycle.

Don’t discuss status in the Standup, discuss particulars. Keep the status information on a status board.  

Enter the Project Dashboard:

At a glance, anyone on your team can tell the following:

  • Server Status
  • Completion percentage
  • What’s going in the next release
  • Anything you want

How long does it take to build one?

For one as good as the Panic Status board, a few weeks. I’m building one now, and because I’m building it using ASP.NET MVC, it took me all of about a day to get the entire thing up. There are still metrics I’m adding, but the basic functionality is there. For it to be polished and out the door? About two weeks.

Why doesn’t your project have one?

If Programming had a Narrator

On Automation

<Narrator voice=”Michael Westen“>When you’re a programmer,you think of everything around you as something that can be automated. If you need to get something done, your first thought is usually how to get someone else to do it for you. Usually that’s a computer. In the course of automating this task, you may find out that it’s harder than you realize. But a good programmer works through those odds, because he knows that at the end of the day, the only thing that matters to the people you deal with is whether or not you were able to do it.</Narrator>

On Talking to A Programmer

<Narrator voice=”Michael Westen”>Being a programmer requires a sharp mind and great concentration. Every interruption causes a programmer to lose focus and often requires them to start over at square one. It’s no surprise then that they normally shy away from contact at work. In order to talk to them, you need to include food and something geeky.  Star Wars is normally a safe topic unless they have Star Trek paraphernalia on their cubicle. Pizza is always a safe bet. </Narrator>

Make it Happen

I used to work on a team that was full of smart people. Chock full of them. They were approachable and funny. Probably the best team I’ve ever worked on. Even with all these smart people, there was never any change. Awful processes stayed awful, deadlines slipped, and everyone felt like they were on the Voyage of the Damned.

Much like the Titanic, that team sank. As teammates, we drifted apart because of a number of issues, but all related around a fundamental problem:

Nothing ever Changed. 

What we could have used was someone to take the initiative and wake us up from our slumber. Preferably with loud cymbals:

To that end, I’ve made a promise to myself. If I want to see anything added to a project, I’ll take the initiative and do it. No Automated Unit Tests? Add them. No build process? Make one. Manual status reporting? Automate it.  

As a Lieutenant Colonel used to say to me. If you want something to happen, you have to Make It Happen.