• Sam D. (unregistered)

    I am not going to blame the programmer for the GOTO stuff. It is how try-catch-finally works in VB.

    But after a year and five months and four versions, urrr...

  • Dave (unregistered)

    Richard Tallent: "This is why I've petitioned Microsoft to rename VB.NET to B#"

    I think Kernighan and Ritchie would have cause to sue. B Sharp is C.

  • Christian Romney (unregistered)

    I have a really hard time believing someone wrote this in any system. Maybe they submitter just wanted to get a rise out of us. The give away is as variant. They know about selects and strings and never heard of booleans? Still, even if it is a hoax, it has entertainment quality.

  • Anonymous (unregistered)

    Too stupid!? Puleezzee ...

    I hate to bring politics ... but only 41% of people in recent Newsweek poll said that Saddam was not "DIRECTLY involved in planning the attacks on 9/11" (exact wording of question, including empahsis). That's nearly 60% of Americans who are complete morons!

    Surely one or two of them are coders?

  • JoeNotCharles (unregistered)

    Given that he's using goto (which I'm not defending) the "goto TheEnd" just before the label is actually good practice, because otherwise adding another block and forgetting to add the now-necessary "goto" would introduce bugs.

    My major whap would be the function name. OrNot?

  • foxyshadis (unregistered)

    Where's the line numbers? He's obviously quite comfortable with BASICA style coding.

    "+1 Internationalization for supporting encodings where [0-9] are not contiguous (do these exist?)"

    I doubt that's an issue. An implementation not smart enough to expand [0-9] into the set of roman numerals independantly of charset would probably just use latin-1 anyway.

    I bet the checksum function would be called CheckIfPossibleISBNCheckdigitIsCorrectISBNCheckdigitForISBN(PossiblyAnISBN)

    Hey, at least he doesn't have:

    Function CheckIfPossibleISBNCheckdigitIsCorrectISBNCheckdigitForISBN(PossiblyAnISBN as String) as variant
    CheckIfPossibleISBNCheckdigitIsCorrectISBNCheckdigitForISBN = "yup"
    Exit Function
    End Function

  • Perlist (unregistered)

    <i>
    So please, send in your non-BASIC code snippets and the like -- if for no other reason than to make me feel less bad about my language of choice ;-).
    </i>
    <pre>
    # Perl solution

    sub CheckIfISBNIsGoodISBNOrNot {
    my ($possibleISBN) = @_;

    my ($isbn) = ( $possibleISBN =~ /^\d{9}(\d|X|x)$/ );

    unless( $isbn ) {
    return 'no';
    }

    return 'no';
    }
    </pre>

  • Jeroen (unregistered)

    @perlist: Uhm, shouldn't that last "return 'no'" be "return 'yes'"?

    Or are you going for a WTF yourself?

  • dalboz (unregistered)

    We obviously need to take away this guy's Ctrl, C and V keys and lock them in a box and then weld it shut and then cast a sealing spell on it and then place it on a rocket and then fire it into the sun and then blow up the sun and the universe...

  • deenus (unregistered)

    Maybe there's a clue in the error number: 666

    diffult to think about good code while you're chasing all those souls thru hell

  • Simon K (unregistered)

    Hey the code was done in the year 2000.. so worst comes to worse.. it is at least Y2K compliant!!

  • Peter (unregistered)

    I've only just discovered this site, but has no-one else noticed that it will accept any string of 10 chatacters that ends in [0-9X]

    stupidtitX

    is a valid string for this routine as it overwrites its detected errors with the next character

    This is really really bad

  • Chris (unregistered)

    @Peter

    Where does it overwrite its detected errors?

    'yup looks like it's just a comment. (I don't know VB.)

    The code does continue to check the following values, but I don't see where it would overwrite the errors.

  • Dale (unregistered)

    I don't know about current versions of VB, but what I remember of VB3 (before abandoning it), is that On Error handlers were required to explicitly exit the error block using either a Goto an Exit Function, and possibly by something else. In any event, they weren't allowed to just drop out the bottom. Either later versions of VB relaxed that, or this might be old code from VB3 days.

  • Patrick (unregistered)

    "<i>
    So please, send in your non-BASIC code snippets and the like -- if for no other reason than to make me feel less bad about my language of choice ;-).
    </i>
    <pre>
    # Perl solution

    sub CheckIfISBNIsGoodISBNOrNot {
    my ($possibleISBN) = @;

    my ($isbn) = ( $possibleISBN =~ /^\d{9}(\d|X|x)$/ );

    unless( $isbn ) {
    return 'no';
    }

    return 'no';
    }
    </pre>
    "

    Shouldn't that first line be:
    my ($possibleISBN) = shift;

    as you end up with $possibleISBN being equal to the number of elements in @
    ...

  • rikkus (unregistered)

    One line of code, some explanation because it's not readable for those who don't know regexps. I left the method name alone, though it hurt, but had to change the return value to boolean to avoid throwing up.

    Did I miss any test cases?

    def CheckIfISBNIsGoodISBNOrNot(possibleISBN)

    # An ISBN is apparently made up of nine digits followed by either a tenth,
    # or the letter 'X'.

    !/^\d{9}[\dX]$/.match(possibleISBN).nil?

    end

    if FILE == $0

    require 'test/unit'
    include Test::Unit

    class ISBNTest < TestCase
    def test_empty
    assert(!CheckIfISBNIsGoodISBNOrNot(""))
    end
    def test_too_short
    assert(!CheckIfISBNIsGoodISBNOrNot("000"))
    end
    def test_kinda_random
    assert(!CheckIfISBNIsGoodISBNOrNot("asdsaoidaiodjasjdasd"))
    end
    def test_too_many_chars
    assert(!CheckIfISBNIsGoodISBNOrNot("00000000000X"))
    end
    def test_dash
    assert(!CheckIfISBNIsGoodISBNOrNot("0000-0000X"))
    end
    def test_ok_with_x
    assert(CheckIfISBNIsGoodISBNOrNot("000000000X"))
    end
    def test_ok_no_x
    assert(CheckIfISBNIsGoodISBNOrNot("0000000000"))
    end
    end
    end

  • TheBitters (unregistered)

    'yup
    Um... OK.


    Way to go, clock-milking retard!

  • Andrew Shugg (unregistered)

    Yet another Perl solution



    sub CheckIfISBNIsGoodISBNOrNot {
    (($arg = shift) =~ /^\d{9}(\d|x)$/i) ? 1 : 0;
    }


    But really ...
  • Fubarer (unregistered)

    Perl solution #3 [even simpler version of the previous one]



    sub CheckIfISBNIsGoodISBNOrNot { ((shift) =~ /^\d{9}(\d|x)$/i) ? 1 : 0; }
  • j.a.v.b.h. (unregistered)

    patrick: no, ($x)=@; is a list assignment.

    Folks with the regexes, whats with the alternations? char classes are more efficient.

    sub CheckIfISBNIsGoodISBNOrNot {
    $
    [0] =~/^\d{9}[\dxX]$/
    }

  • Rick (unregistered)

    It was on PHP (rollseyes). Don't get me wrong, PHp is a nifty (or actually powerful = dangerous?) language.

    Anyway.

    I think i can solve the mystery behind this:

    COPY/PASTE!

    Some programmers are so lazy that they rather copy/paste hundreds of lines of code instead of just adding some if's.

    So this guy probably did one line of code, copied it 10 times, changed the numbers, copied it again 5 times... etc.

    This is the result.

    Well, the programmer got praised for doing a heavy database management system in 5 minutes. But boy, oh boy the horrors I felt when I had to MAINTAIN IT!!!!

  • Daniel H. (unregistered)

    I particularly like the comment masterpieces. What literature!

    ErrorChecking:
    'Check errors

    :-D

  • ??_????? (unregistered)

    ?????? ???! ????? ????? ?? ??????

  • (cs)

    "I'm a (beeping) writer but I can kick that thing's a$$." 

       - line from Henry Rollins.

  • John Hensley (unregistered)
    Alex Papadimoulis:
    'Digit 10 - careful, this might have an "X"

    "Oh!  Piglet,"  said  Pooh excitedly, we're going on an
    Expotition,  all  of  us,  with  things  to  eat.  To  discover
    something."

    "To discover what?" said Piglet anxiously.

    "Oh! just something."

    "Nothing fierce?"

    "Christopher Robin didn't say anything about fierce. He
    just said it had an 'x'."

    "It isn't their necks I mind," said Piglet earnestly. "It's their teeth."

  • (cs) in reply to Jannik Anker
    Anonymous:
    I have to join the (surprisingly small) group of readers who cannot believe that someone could actually be dumb enough to write code like this.

    Actually, I "coded" ASP/VBScript for a full week before discovering loops (quite a while back ;-)... Makes you wonder just how long this guy has been in the game!

    Exactly! This code reeks of a beginner: rigid use of control structures, the verbose but pointless comments, suboptimal conditions, and failing to code the hardest part, the checksum. Enthusiasm, but no experience.

    Self-taught programmers can go for months before getting their head around loops, actually. This coder might actually know about loops; they just don't think in terms of loops yet.

    The real question is: how did a beginner get to work on production code?

  • (cs) in reply to PPP

    Hey, my WTF woke up again after being asleep since 2004. :-)

    Work long enough contracting for people fixing up nonsense written buy guys working from a copy of "VBA for dummies" that they got from eBay and you just stop asking "why" "how" and "wtf?" A surprisingly large amount of code out there, especially in small businesses, is written by people who just aren't developers, but get given the task to "get it done". If you're lucky, it'll be a hobbyist.

    The worst thing for code quality in small businesses bar none IMHO is the "record macro" functionality in MS Office. Oh how much less hassle (and, admittedly, work) I'd have if it weren't for that!

  • fre0n (unregistered)

    C#.  In general, I suck at regular expressions, but this works.  (probably could have made the expression simpler).  But hey, two lines...

    public bool IsValidISBN(string possibleISBN)
    {
        Regex regex = new Regex("[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9Xx]");

        return (possibleISBN.Length == 10 && regex.IsMatch(possibleISBN));
    }

  • (cs) in reply to fre0n
    Anonymous:
    C#.  In general, I suck at regular expressions

    Agreed. Try this:

    public bool IsValidISBN(string possibleISBN)
    {
        Regex regex = new Regex("^\\d\\d\\d\\d\\d\\d\\d\\d\\d[0-9Xx]$");
        return regex.IsMatch(possibleISBN);
    }


  • Bart (unregistered)

    Al these regexps are for lazy people! Real men code in C:

    char *isisbn(char *c) {
      char i = 0;
      while (*c++ && *c>='0' && *c<='9' && i<8) i++;
      return ((*c & 0x0058)=='X' || (*c<='9'&&*c>='0')) && !*++c && i==8 ? "yes":"no";  
    }
    
  • Peter (unregistered)

    This is what happens when you pay your developers by the number of lines they produce.

    Note how skillfully the developer added comments between each case to almost double his salary for this function.

Leave a comment on “To ISBN or not ISBN, that is the question ”

Log In or post as a guest

Replying to comment #:

« Return to Article