Programming languages are tools for programmers.

If you're not a programmer, you shouldn't be using Perl. Programming languages are tools for programmers. I apologize if people see that as an elitist statement, but it's true. The mere act of picking up a toolbox doesn't make me an auto mechanic. Would you let me work on your car just because I had a set of tools? I have a pair of scissors at home; you should let me cut your hair.
     -- gbacon@itsc.uah.edu (Greg Bacon)

Sometimes you get to see THINGS. Sometimes you see someone writing code they do not understand, using tools they do not understand, ... Like the guy who wrote this "validation" code below:

function validate(myform) {
    var msg = "";

    if(!myform.surname.value.match(/\D+/)){
        msg += " Your surname\n";
    }
    if(!myform.town.value.match(/\d{4,}/)){
        msg += " Your town/city\n";
    }
    if(!myform.postcode.value.match(/\D+/)){
        msg += " Your postcode\n";
    }
    if(!myform.phone.value.match(/\D+/)){
        msg += " Your daytime phone\n";
    }
    if(!myform.email.value.match(/\w+\@\w+\.\w+/)){
        msg += " Your contact email\n";
    }
    if(!myform.ref_one.value.match(/\D+/)){
        msg += " First reference's name\n";
    }
    if(!myform.ref_three.value.match(/\D+/)){
        msg += " First reference's house number/name\n";
    }
    if(!myform.ref_five.value.match(/\D+/)){
        msg += " First reference's town/city\n";
    }
    if(!myform.ref_seven.value.match(/\D+/)){
        msg += " First reference's postcode\n";
    }
    if(!myform.ref_one_two.value.match(/\D+/)){
        msg += " Second reference's name\n";
    }
    if(!myform.ref_two_three.value.match(/\D+/)){
        msg += " Second reference's house number/name\n";
    }
    if(!myform.ref_two_five.value.match(/\D+/)){
        msg += " Second reference's town/city\n";
    }
    if(!myform.ref_two_seven.value.match(/\D+/)){
        msg += " Second reference's postcode\n";
    }
    if(!myform.dpa_agree.value.match(/\D+/)){
        msg += " Data Protection Act agreement\n";
    }
    if (msg == "") {
        return true;
    }
    else {
        alert("The following fields must contain valid information:\n\n" + msg);
        return false;
    }
}

Now I don't remember his name even though I've heard it, but I'll surely remember the code. Take this for example:
  if(!myform.surname.value.match(/\D+/)){
Here the Surname is all right if ... it contains a character other than number. Anything which contains at least one nonnumeric character will do. Beautifull ... but well ... is this validation? According to him proper surname is "123 456" or ":::" or prettymuch anything you can think of.

Or this:
  if(!myform.town.value.match(/\d{4,}/)){
This one is even better. It requires that Town names do contain a group of four or more numbers. So I guess it's OK if I claim I come from town "%#$45@$1234#4dd", but not if I say I come from "Blatna".

And the other validations are the same. I really wonder ... did he at least once read the regexp docs? Did he stop for a sec and asked himself if he understands regexps well enough to use them? Did he think?


Don't use functions you do not understand!
If you don't understand WHAT are they doing, and how do control what are they doing, simply don't use them. You don't have to know HOW are they doing it, but if you don't feel you understand properly how to use them ... ask someone to help you with the code, let someone review the code, read the documentation ten more times or use something else.      -- me

(BACK)