imageI've thought about writing this post several times over the past two years.  Having had regular expressions come up three times last week, I thought it time to address the lack of programmers out there who understand regular expressions.  The sheer amount of fear surrounding regular expressions and the work that goes into avoiding them is astonishing.

Last year I used to troll around the asp.net forums and quite frequently I would answer the regex questions.  One question was posted which illustrates the problem with regexes among developers.

"...and i also i need to add a validator for the password textbox where the user is required to fill atleast [sic] 6 characters"

I suggested a solution to the problem using a regular expression validator. Making sure there are at least 6 characters, is a simple regex (example: \w{6,}), and yet my solution was met with skepticism.  The following was said, in the event a change was requested,

"Putting a new version of a web site can take a surprising amount of time than can go into man-weeks". 

Man-weeks?!?!?  To change a regular expression?!?!?  I see two problems, first the original developer who didn't know that regex would easily solve their problem.  The second problem is the other developer who doesn't know regex advocating his way as "the way", in effect, spreading his ignorance.  The first developer is easily forgiven, the second is not.

It's been said programmers can't program when faced with a simple FizzBuzz test, Imran states:

"Want to know something scary? - the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution."

I'll pile on.  You want to know something scary?  The majority of professional programmers can't write regular expressions, even simple ones.  I'm not the first to say this.  Last year, at the ALT.NET conference, Scott Guthrie made the following statement when talking about routes in the new MVC framework:

"It's pluggable, so you can use Regexes...<some incoherent stuff>...if you wanna use regexes you can.  What we found is, regexes are super powerful, but only about 10% of people actually understand 'em."

Are regular expressions easy to understand? Well, let me ask you, was HTML easy when you started?  Were you born understanding the following HTML?

<fieldset class="CheckRadio">
    <div id="OngoingEventContainer">
        <input type="checkbox" id="OngoingEvent" name="OngoingEvent" value="1" />
        <label for="OngoingEvent">
            This is an ongoing event (no dates and times)
        </label>
    </div>
</fieldset>

If you understand the above, you didn't always.  My guess is that at some point you buckled down and learned HTML because you're job requires it.  Well, if you're a programmer, web or windows, you need to know regular expressions, your job requires it, it's that simple. 

imageRegular expressions have been around so long that they're deeply ingrained in many of the tools we use.  Christopher Bennage illustrates how regular expressions solved a recent problems in Visual Studio.  In a recent post he posts:

"Then I realized that I was missing the simple solution. Ctrl+F and a regular expression!"

I don't know that many people would be able to come to the conclusion that Christoper did.  It's my belief that regular expressions are fundamental, yet the average developer doesn't treat them as such.  They're ultimately doing themselves a disservice.

Regular Expressions are a tool that should be in every programmers bag.  If you don't understand regular expressions and do a google search every time you need a regular expression, shame on you!  It's time to bite the bullet and learn regular expressions.


 
Categories: .NET | Musings | Software

February 21, 2008
@ 11:48 AM

This video was posted at channel8.  It's a talk by Bill Gates at Standford. During his speech he shows a video of his last day at Microsoft, which I found quite funny, have a look.  (Note: The video Bill shows starts at the 8:35 and runs for about 10 minutes).

Video Link


 
Categories:

After a snowy weekend being stuck in Minnesota I was greeted by an email in my inbox saying that I was registered for the 2008 ALT.NET Open Spaces, Seattle conference.  Last year the Alt.NET generated a lot of post-conference buzz and was where the .NET MVC Framework was announced by Scott Guthrie.

After looking at the list of participants I'm gushing with enthusiasm.  I feel like a 14 year old freshman who was just asked to the homecoming dance by the homecoming queen.  For the sports enthusiast, I feel like Jason Kapono at the NBA All-Star game.  Kapono won the three point shootout, but many of you are probably asking yourselves, "who is Jason Kapono?"  Kapono, and his three-point skill, was overshadowed by the All-Star game itself and all of the NBA talent on the floor at one time.  I am Jason Kapono.  I must admit I have borderline unhealthy geek-love-man-crush on some of the attendees (listed in no particular order):

Sure, these guy go to conferences and it's not rare that they're in the same place.  What is rare, is that they're all together and there are only 150 participants.  That means the geek-expert to journeyman ratio is going to be quite high.  In other words, they can't avoid me.

Martin, will you autograph my POEA book?


 
Categories: .NET