MetaChat REGISTER   ||   LOGIN   ||   IMAGES ARE OFF   ||   RECENT COMMENTS




artphoto by splunge
artphoto by TheophileEscargot
artphoto by Kronos_to_Earth
artphoto by ethylene

Home

About

Search

Archives

Mecha Wiki

Metachat Eye

Emcee

IRC Channels

IRC FAQ


 RSS


Comment Feed:

RSS

23 May 2005

Well, the winning iPod health warning was really good (referencing the iPod advertising silhouette graphics, right?). The code snippet looks monstrous, but I'm too stupid to get the whole implication.
posted by taz 23 May | 10:20
Reasons why it's a bad piece of code:
1) The function is repeated wherever it's needed instead of only being in one place.
2) It doesn't work properly ("12345678P~?" will still validate as a valid SSN)
3) Code for testing each section is repeated. (It should be in a loop)

Even without the *evil* regexp, you should be able to shrink this down to 10 or so lines of code)

in VDF...(My language)
function isValidSSN string sSSN returns boolean
    boolean isValid
    string sChar 
    
    move (true) to isValid
    if (length(sSSN)) ne 8 move (false) to isValid

    for iIndex from 1 to 8
        move (mid(sSSN,1,iIndex)) to sChar
        if ((sChar"9")) move (false) to isValid
    loop
    function_return isValid
end_function
posted by seanyboy 23 May | 10:46
Off topic. It appears that between preview and post, metachat strips out &nbsp's and replaces them with spaces.

Plus it doesn't play nice with gt and lt characters. My Code got mangled.

For a test try posting something containing the phrase  
posted by seanyboy 23 May | 10:49
Damn you code stripper box....That should read...
For a test try posting something containing the phrase &nbsp
posted by seanyboy 23 May | 10:51
Damn it. I've added that bug to the bug list.
posted by dodgygeezer 23 May | 11:02
I don't really know Java and regexes are still fairly new to me but I guess this would be fairly close to what the coder intended:
ssn.matches("[0-9]{9}");
Still, as they say in that thread, this still wouldn't be the correct way to validate SSNs but it does go to show just how bloated the code is. Nightmarish.
posted by dodgygeezer 23 May | 11:26
"matches" hah. You young 'ens have got it easy.
I remember when you only had four variables, and you could only compare strings one byte at a time. We 'ad to program uphill both ways back then.
posted by seanyboy 23 May | 14:35
You were lucky!
posted by dg 23 May | 18:35
confirming that my bugfix has worked:
<testme>
 insert text here
</testme>
posted by dodgygeezer 26 May | 13:22
The magic roundabout || Brits Statistically most European Europeans.

HOME  ||   REGISTER  ||   LOGIN