Comment On To ISBN or not ISBN, that is the question

I'm trying, really I am. I don't want to have such a disproportionate amount of posts on VB/VBScript/ASP as opposed to the C#, Java, PHP, Perl, and all the others. But when folks like Ray S send in data validation functions from real, production systems like this, how can I resist? [expand full text]
« PrevPage 1 | Page 2Next »

re: To ISBN or not ISBN, that is the question

2004-09-20 13:11 • by Katrina
Hi Alex.

re: To ISBN or not ISBN, that is the question

2004-09-20 13:17 • by Manni
Wow... I... uh... wow....

So he's basically looking for a 10-character ISBN, the first 9 of which are guaranteed to be numbers, the last can be either a number or X. This could have been done so much simpler it's shocking. It reminds me of that code a little while back where the guy made a <select> tag in HTML by hand and manually entered all the possibilities for hours and minutes.

I can honestly say I've never used "GoTo", I avoid it like the plague or a hooker with herpes. I love how he has a GoTo that takes the code to the next line anyway, and at the very end he has "Exit Function". Good thing he put that in there, because the ambiguous "End Function" right afterward is unpredictable.

And correct me if I'm wrong, but if you pass the parameter as a string, won't IsEmpty() return True if the Len() = 0? That situation would already be caught with the line "If Len() <= 9" (which could have all been simplified to "If Len() <> 10")

Maybe he just didn't know VB supported loops? Maybe he had a head injury?

re: To ISBN or not ISBN, that is the question

2004-09-21 03:42 • by RJ
Actually in defense of the original author of the code .....

nah, can't do it. What was I thinking?!?

re: To ISBN or not ISBN, that is the question

2004-09-21 04:10 • by stu
it... runs... fast ?

then again, I should use the IF statement instead of CASE.

re: To ISBN or not ISBN, that is the question

2004-09-21 05:02 • by Martin DeMello
<i>
GoTo TheEnd
TheEnd:

# ...........

Exit Function
End Function
</i>

Looks like someone doesn't trust the program counter :)

re: To ISBN or not ISBN, that is the question

2004-09-21 05:07 • by J&#246;rgen S
Uh, this must be a fabrication. I simply refuse to believe that there are people as dumb as this one. The intelligence displayed in this piece of code isn't enough to stimulate automatic breathing. I've heard of nobody programming while in a respirator.

re: To ISBN or not ISBN, that is the question

2004-09-21 06:11 • by KoFFiE
Damn - I really was stunned for a moment... When I saw the first Select Case appearing on my screen, I was like "oh no - he didn't"... and stayed like that for 5 minutes...

What I really do like about this code is his errorhandling... What if the CPU just jumped from it's own to one of the labels? Well, hell must have broken loose then, and he raises the error 666... Good thinking, can't be safe enought now can we? Just missing the "PrayForMerci" label... Also, his errormessages are so clear we should really make a difference between the 2 error cases. Also when something went wrong, you really couldn't return "no", now could you? Also - booleans were invented only for educational purposes...

re: To ISBN or not ISBN, that is the question

2004-09-21 08:15 • by Mike R.
It's obvious this code is the root of all evil ;)

* Error Code 666 ...
* 9 Identical select blocks
* ... Select Blocks for finding digits?!
* GoTo is considered "unclean"
* String return value when boolean could suffice.

(...)

re: To ISBN or not ISBN, that is the question

2004-09-21 09:26 • by Jeff S
I would pay to see what the first version of this code looked like !!!!

Kind of like when you drive the down the road and see a car accident, you can't help but look...

the first version was probably:

If ISBN ="000000000" or
ISBN ="000000001" or
ISBN ="000000002" or
...etc...

over a billion lines of code !!!

re: To ISBN or not ISBN, that is the question

2004-09-21 09:36 • by Jannik Anker
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!

re: To ISBN or not ISBN, that is the question

2004-09-21 09:53 • by TJ
'Init Variables
programmerSucks="yep"
isGoodForTheIndustry="no"
shouldbeFlippingBurgers="yep"

re: To ISBN or not ISBN, that is the question

2004-09-21 10:48 • by Sam D.
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...

Meta comment.

2004-09-21 12:39 • by Dave
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.

re: To ISBN or not ISBN, that is the question

2004-09-21 14:24 • by Christian Romney
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.

Not real?? Too stupid?

2004-09-21 14:49 • by Anonymous
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?

re: To ISBN or not ISBN, that is the question

2004-09-21 16:07 • by JoeNotCharles
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?

re: To ISBN or not ISBN, that is the question

2004-09-21 18:00 • by foxyshadis
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

re: To ISBN or not ISBN, that is the question

2004-09-22 00:46 • by Perlist
<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>

re: To ISBN or not ISBN, that is the question

2004-09-22 01:47 • by Jeroen
@perlist: Uhm, shouldn't that last "return 'no'" be "return 'yes'"?

Or are you going for a WTF yourself?

re: To ISBN or not ISBN, that is the question

2004-09-22 09:46 • by dalboz
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...

re: To ISBN or not ISBN, that is the question

2004-09-23 09:15 • by deenus
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

re: To ISBN or not ISBN, that is the question

2004-09-24 00:46 • by Simon K
Hey the code was done in the year 2000.. so worst comes to worse.. it is at least Y2K compliant!!

re: To ISBN or not ISBN, that is the question

2004-09-28 04:26 • by Peter
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

re: To ISBN or not ISBN, that is the question

2004-09-28 14:10 • by Chris
@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.

re: To ISBN or not ISBN, that is the question

2004-09-28 20:04 • by Dale
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.

re: To ISBN or not ISBN, that is the question

2004-09-29 10:29 • by Patrick
"<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 @_...

re: To ISBN or not ISBN, that is the question

2004-09-29 12:09 • by rikkus
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

re: To ISBN or not ISBN, that is the question

2004-09-29 13:35 • by TheBitters
'yup
Um... OK.

Way to go, clock-milking retard!

re: To ISBN or not ISBN, that is the question

2004-09-30 23:02 • by Andrew Shugg
# Yet another Perl solution

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


But really ...

re: To ISBN or not ISBN, that is the question

2004-10-03 08:06 • by Fubarer
# Perl solution #3 [even simpler version of the previous one]

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

re: To ISBN or not ISBN, that is the question

2004-10-20 07:06 • by j.a.v.b.h.
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]$/
}

I've seen code like this before....

2004-10-21 19:20 • by Rick
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!!!!

re: To ISBN or not ISBN, that is the question

2004-11-06 05:57 • by Daniel H.
I particularly like the comment masterpieces. What literature!

ErrorChecking:
'Check errors

:-D

re: To ISBN or not ISBN, that is the question

2004-09-20 13:17 • by Gah
It burns!

re: To ISBN or not ISBN, that is the question

2004-09-20 13:18 • by Matt K
+1 Point for readability! -4000 points for stupidity. I sincerely hope no one defends this code.

re: To ISBN or not ISBN, that is the question

2004-09-20 13:21 • by Manni
My mistake, IsEmpty will always return False on a string, as long as it's Dim'ed or passed as a parameter. Either way, IsEmpty is useless in this context.

re: To ISBN or not ISBN, that is the question

2004-09-20 13:29 • by Mike R.
Scary that this went through 5 versions and is still like this.

There are just hundreds of ways this could be done better.

I love the error messages. Very descriptive to the person calling this "beast" of a function ;)

re: To ISBN or not ISBN, that is the question

2004-09-20 13:36 • by Chris
I love the end of the function:

Exit Function
End Function

I guess sometimes you REALLY have to be sure you don't walk past the end of the function... :)

re: To ISBN or not ISBN, that is the question

2004-09-20 13:38 • by Bu
Does VB support regular expressions? If so, this is yet another one-liner that didn't happen because the instruction manual is still in the shrinkwrapped box. :)

re: To ISBN or not ISBN, that is the question

2004-09-20 13:45 • by stubs
I especially like if <= 11 and >= 9 when you want something that is a length of 10... Lets you know right off the bat that you are in for a treat.

re: To ISBN or not ISBN, that is the question

2004-09-20 13:45 • by Steve
Guess he never heard of Regular Expressions

lol @ "it burns", that made me laugh for a few minutes

re: To ISBN or not ISBN, that is the question

2004-09-20 13:48 • by Jason Mauss
How come the error number is '666' ? Is this the work of the devil? ;-)

re: To ISBN or not ISBN, that is the question

2004-09-20 13:54 • by Derick Bailey
Bu and Steve: VB6 doesn't support RegEx out of the box... you actually have to use the VBScript runtime for that.

One time on a vb6 project, i needed to do a regular expression to simplify 30 or 40 lines of code down into like 3 lines of regular expressions... and my manager forbid me from doing it because he didn't want to include the VBScript runtime in the setup package.

re: To ISBN or not ISBN, that is the question

2004-09-20 13:59 • by Martin
Must be another example of <A HREF="http://thedailywtf.com/archive/2004/09/17/1844.aspx">consultant code</A> where every line of code equals more money!

re: To ISBN or not ISBN, that is the question

2004-09-20 14:06 • by Ben Hutchings
And after all that, it doesn't even check the checksum! Perhaps the programmer tried to do it with Select and gave up when the code grew too long for the VB editor or compiler to handle.

re: To ISBN or not ISBN, that is the question

2004-09-20 14:06 • by Steve O.
Most VBers don't know regular expressions....

re: To ISBN or not ISBN, that is the question

2004-09-20 14:25 • by Joshua Bair
If (aValue <> "no") And (aValue <> "yes") Then Err.Raise 666, ,"SCREW YOU! I DON'T KNOW WHAT THE F**K HAPPENED!"

re: To ISBN or not ISBN, that is the question

2004-09-20 14:30 • by Maik
Alex, as for non-VB code, check your inbox...

re: To ISBN or not ISBN, that is the question

2004-09-20 14:32 • by Hassan Voyeau
This is how I would have done it...

Private Function isValidISBN(strISBN As String) As Boolean
Dim regex As New RegExp

regex.Pattern = "^\d{9}(\d|X)$"
isValidISBN = regex.Test(strISBN) 'And isValidCheckSum(strISBN)
End Function

'download MS windows script hear : http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp

re: To ISBN or not ISBN, that is the question

2004-09-20 14:35 • by Hassan Voyeau
Actually isValidCheckSum(strISBN) in above code should be hasValidISBNCheckSum(strISBN)
« PrevPage 1 | Page 2Next »

Add Comment