Do Regular Expressions scare developers? - Brian Johnson

Do Regular Expressions scare developers?

I have harped on about the joys of Regular Expressions before, and find them an indispensable tool in my developer toolkit.  In fact, I never leave home without this one.  What concerns me gravely is the fact that too many other developers appear to completely overlook (or ignore) regular expressions, although this lack of knowledge does produce some fine examples of user input validation code that usually has me in giggles (and defining further parameters of "Developer Culling" that is fast becoming a sport I will be partaking in).

What I would like to know is whether or not regular expressions are feared by developers?  Surely in this day and age of distributed systems and complex architectures regular expressions should be part of what you know.

I have come to realise however that most developers appear to be 'writers of lines of code' rather than true developers; there's a very worrying sign of a lack of understanding of why things should be done in a particular way, and a lack of awareness of basic tools.  Regular expressions are probably one of the most powerful concepts for user input validation, which also happens to be one of the most forgotten steps in code development (how many systems I come across that throw "data is too large for column" errors is also a worrying trend).  Could there be a relation here?

I won't list all the samples of painfully written loops and conditions I have seen to validate a South African ID number, or the laughable routines used to determine South African Mobile Phone number validity.  I will however make a statement: Learn the tools, know they exist.  You do not have to be a master of them, but know they are there.  There are places to find the information you need for specifics that you do not know (the internet, use it), but at least realise that these things are actually available for your use.

Remember this quote: "good code is written by good programmers".  By deduction we can then say that bad code is written by bad programmers (and trust me, these particular validation routines fall well within this realm).  Also remember this other quote: "You need someone who is creative enough to find innovative solutions to problems".

Regular expressions have been around for years, and all of .NET's life, deal with it.

 

Published 14 March 2007 01:31 PM by brian

Comments

# Craig Nicholson said on 14 March, 2007 05:35 PM

I doubt that the majority of developers know what a regular expression is let alone possess the ability to write their own reasonably useful expressions.

When it comes does to validation of data whether in forms (I generally don't do forms), utilities or XML schemas (more my area) I tend to prefer using regular expressions over the classic programatical approach.

# brian said on 14 March, 2007 06:32 PM

Thanks Craig, your point is exactly mine: "I doubt that the majority of developers know what a regular expression is let alone possess the ability to write their own reasonably useful expressions" :)

# Armand du Plessis said on 15 March, 2007 04:20 AM

A regular what?

# Trivium DawnWalker said on 15 March, 2007 05:50 AM

lol @ Armand, dude shouldn't you be in a conference or something ;)

As for the topic at hand, great post man! I fully agree with you. Once I discovered Regular Expressions I never looked back!

# mailowl said on 15 March, 2007 08:25 AM

Are regular expressions taught in developer courses?  I have to admit my ignorance on the subject, and short of getting a book on the subject I'm not sure where I'll learn to use it or encourage its use in the office

# brian said on 15 March, 2007 09:09 AM

Unfortunately it is the lost brother in the world of development, especially around .NET and Java.  It is huge in the Perl, Python and Ruby worlds however.  It is often downplayed with disastrous results (take a look at any of your validation code in your organisation to see how often System.Text.RegularExpressions is imported).

The best resources on regular expressions is MSDN (for the howto in .NET) and http://www.regular-expressions.info/ (on actual regular expression help).

Regex is not difficult to use, although very difficult to master ;-)

# Trivium DawnWalker said on 15 March, 2007 10:29 AM

I know for a fact that CTI(Computer Training Institute) does not mention Regular Expressions at all, not sure about the universities.

I actually discovered them by mistake a while. also check out http://regexlib.com/ for some resources.

# auratius said on 15 March, 2007 12:07 PM

Been developing for ages and I steer away from them....far away from them

# brian said on 15 March, 2007 01:34 PM

...I would like to hear the "Why" of your comment :)

# Ernst Kuschke said on 15 March, 2007 10:10 PM
The ol' "Fear of the unknown" ;o)
# Ernst Kuschke said on 15 March, 2007 10:22 PM

The ol' "Fear of the unknown" ;o)

# Client side Regular Expression Validation | stevenmcd.net said on 30 May, 2007 11:45 AM

Pingback from  Client side Regular Expression Validation |  stevenmcd.net