- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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...
Admin
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.
Admin
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.
Admin
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?
Admin
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?
Admin
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
Admin
<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>
Admin
@perlist: Uhm, shouldn't that last "return 'no'" be "return 'yes'"?
Or are you going for a WTF yourself?
Admin
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...
Admin
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
Admin
Hey the code was done in the year 2000.. so worst comes to worse.. it is at least Y2K compliant!!
Admin
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
Admin
@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.
Admin
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.
Admin
"<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 @...
Admin
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
Admin
'yup
Um... OK.
Way to go, clock-milking retard!
Admin
Yet another Perl solution
sub CheckIfISBNIsGoodISBNOrNot {
(($arg = shift) =~ /^\d{9}(\d|x)$/i) ? 1 : 0;
}
But really ...
Admin
Perl solution #3 [even simpler version of the previous one]
sub CheckIfISBNIsGoodISBNOrNot { ((shift) =~ /^\d{9}(\d|x)$/i) ? 1 : 0; }
Admin
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]$/
}
Admin
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!!!!
Admin
I particularly like the comment masterpieces. What literature!
ErrorChecking:
'Check errors
:-D
Admin
?????? ???! ????? ????? ?? ??????
Admin
"I'm a (beeping) writer but I can kick that thing's a$$."
- line from Henry Rollins.
Admin
"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."
Admin
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?
Admin
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!
Admin
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));
}
Admin
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);
}
Admin
Al these regexps are for lazy people! Real men code in C:
Admin
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.