 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
On embedded systems without a file system...
Admin
Looks like a pretty optimised piece of code to me. Why should I trust a compiler to unroll my loop?
Admin
Who needs to learn compex math when you have the power of if at your disposal?
Admin
Shouldn't it be 10  (39 mod 10) ?
Admin
Alex clearly learned a lesson from this WTF and unrolled the (39 mod 10) operation inline.
Captcha: plaga, the idea of excessive loop unrolling was plagarised?
Admin
There seems to be a few semicolons missing.
Admin
The lack of a filesystem is not the limiting factor. It's that there is no math library available once printed to a barcode.
Admin
AWTF: "As for the most wondrous thing about this program? The coder took special care to find out exactly what ZIP code ranges aren't used by the postal service, so as to avoid unnecessary coding for those ranges."
Looks to me like this "code" goes to extra pains to test every zipcode against every range. Otherwise they would have used an ifelseif construct.
Admin
I'm betting that someone had the ingenious idea to move all of their systems to a web platform and they hired someone's teenage kid who knew some javascript to write it.
Admin
Some coders should have their clipboard disabled.
Admin
Boss: Postal code validation? Oh no! What do we do?! I've got a team of crack developers, who can do this in 20 minutes, or..... HELP! BOSS'S NEPHEW!
Offscreen Voice: Someone needs my help! And it uses a compewtor! I know what they are, I read a book once! This sounds like a job for <BOOMING VOICE>Boss's Neeeeeeephewwwwww!</BOOMING VOICE>.
Narrator: In today's episode, we find Boss's Nephew in charge of a hamster, a jar of vaseline, and a computer. His task: Ensure we have valid postal codes. Let's see how he can screw it up!
[8 hours later]
Boss's Nephew: "Well, the hamster's dead, he drowned in the vaseline, I can't find my shoes, and I set a horse on fire, but I think the postalcode checking thing is complete!"
Boss: "Great job! You get a bonus! Thanks for being so awesome! Say hi to my sister!"
Boss's Nephew: "Thanks UncleBoss!"
Other developers: sobbing
[fade to black]
Admin
I'd prefer a giant switch block
Admin
you would recieve a sound thumping about the ears for wasting precious flash eeprom on code like this.
Either that, or Alex needs to improve the "Prove you're not a bot" test.
Admin
Admin
I was just sick in my mouth a little.
Admin
A very impressive piece of coding. The programmer was aware that division and converting numbers to strings (and v.v.) for string manipulation are both more expensive operations than comparison and addition, so he/she took steps to avoid them, at the price of a little extra maintenance. Of course, the code could have been optimized further by eliminating the "3 + 4 + 2" sections  that's a high price to pay for selfdocumenting code.
Admin
Surely this is a for for...recursion!
Admin
So the WTF is that he didn't use a forcase, right?
Admin
Not that adding elses would help.
Admin
How would string manipulation functions help calculate the check bit?
Admin
Admin
Or even simple math.
Admin
Should have used a look up table.
Admin
I wonder if we can find more Counter math in his code...
Admin
Admin
The code is pretty scary, what happens if the value of 1 changes in the future to 2 or even 3? It would be much faster and easier and secure to create an access database, in one table you have every possible barcode and in another table you have every possible address and then a 3rd table that is used to join the address to the barcode.
As a bonus, this ensures you will always only create barcodes for addresses that exist which will save the post office money because they won't try to deliver to an address that does not exist.
Admin
Can anyone explain the advantage ou using 10(n mod 10) over simply using n mod 10?
I've also seem a lot of check digits based on (n mod 11) that end up mapping two results to the same check digit. Never understood why.
Admin
Seems that they are missing the 'zzzipcode' variable, or perhaps the 'zzzzipcode'
Admin
It is possible that the code is a port from dBase III. That damned language didn't have a mod function (or many math functions at all).
There was still a much easier way of calculating mod. And it was surprisingly strong in string manipulation.
Admin
comment = comment + "w" + "t" + "f";
Admin
The saddest part is, that what idiots manage to figure out and utilize very well is the search and replace tool of their IDE which in turn makes abominations like this possible.
Admin
This WTF is too sick to comment. o_O
Admin
How I would do it if there was no string slicing or Mod command....
C=0; if (Zcode=>10000 and Zcode<=19999) { Zcode=Zcode10000; C=1; } If (Zcode=>20000 and Zcode<=29999) { Zcode=Zcode20000; C=2; } ' Repeat for 30000,40000,50000,60000,70000,80000 & 90000 ... If (C>10) then {C=C10;} ' Simple Mod 10 If (Zcode=>1000 and Zcode<=1999) { Zcode=Zcode1000; C=C+1; } If (Zcode=>2000 and Zcode<=2999) { Zcode=Zcode2000; C=C+2; } ' Repeat for 3000,4000,5000,6000,7000,8000 & 9000 ... If (C>10) then {C=C10;} ' Simple Mod 10 If (Zcode=>100 and Zcode<=199) { Zcode=Zcode100; C=C+1; } If (Zcode=>200 and Zcode<=299) { Zcode=Zcode200; C=C+2; } ' Repeat for 300,400,500,600,700,800 & 900 ... If (C>10) then {C=C10;} ' Simple Mod 10 If (Zcode=>10 and Zcode<=19) { Zcode=Zcode10; C=C+1; } If (Zcode=>20 and Zcode<=29) { Zcode=Zcode20; C=C+2; } ' Repeat for 30,40,50,60,70,80 & 90 ... If (C>10) then {C=C10;} ' Simple Mod 10 ' Zcode should be between 0 and 9 so just add it on... C=C+Zcode; If (C>10) then {C=C10;} ' Simple Mod 10 CDigit=10C; if (CDigit>9) {CDigit=0;}
Admin
The goggles, they do nothing!
CAPTCHA: veniam  I'll have a bottle of 1856 veniam  would you like to try some?
Admin
Are you serious?
See below for a simple mod if mod didn't exist.
Admin
frankly i have no words to describe this WTF ...
oh ... i do have some words ... Genius ... pure genius !!!
now again i have run out of words :((
Admin
Admin
replacement for positive mod: i = i  ((i/10) *10)
Admin
The CASS Technical Guide defines the check digit thus:
So sounds more like the check digit is: (10  (sum % 10)) % 10.
Admin
They could halve the speed of that code by wrapping it in another if that splits in the middle. Ooh, or better yet, keep nesting that in both sides. It's a BTree of ifs! Brilliant!
Admin
Admin
Pathetic. The enterprisey way to do this would be to have an SQL database containing the correct check digit for every possible postal code.
Admin
Embedded systems is the new "Frist!"
Admin
I wonder if the person was getting paid by LOC.
Admin
int chkdgt(int zipcode) { switch (zipcode) { case 10000: return 9; case 10001: return 8; case 10002: return 7; case 10003: return 6; case 10004: return 5; case 10005: return 4; case 10006: return 3; case 10007: return 2; case 10008: return 1; case 10009: return 10; case 10010: return 8; case 10011: return 7; case 10012: return 6; case 10013: return 5; case 10014: return 4; case 10015: return 3; case 10016: return 2; case 10017: return 1; case 10018: return 10; case 10019: return 9; case 10020: return 7; case 10021: return 6; case 10022: return 5; case 10023: return 4; case 10024: return 3; case 10025: return 2; case 10026: return 1; case 10027: return 10; case 10028: return 9; case 10029: return 8; case 10030: return 6; case 10031: return 5; case 10032: return 4; case 10033: return 3; case 10034: return 2; case 10035: return 1; case 10036: return 10; case 10037: return 9; case 10038: return 8; case 10039: return 7; case 10040: return 5; case 10041: return 4; case 10042: return 3; case 10043: return 2; case 10044: return 1; case 10045: return 10; case 10046: return 9; case 10047: return 8; case 10048: return 7; case 10049: return 6; case 10050: return 4; case 10051: return 3; case 10052: return 2; case 10053: return 1; case 10054: return 10; case 10055: return 9; case 10056: return 8; case 10057: return 7; case 10058: return 6; case 10059: return 5; case 10060: return 3; case 10061: return 2; case 10062: return 1; case 10063: return 10; case 10064: return 9; case 10065: return 8; case 10066: return 7; case 10067: return 6; case 10068: return 5; case 10069: return 4; case 10070: return 2; case 10071: return 1; case 10072: return 10; case 10073: return 9; case 10074: return 8; case 10075: return 7; case 10076: return 6; case 10077: return 5; case 10078: return 4; case 10079: return 3; case 10080: return 1; case 10081: return 10; case 10082: return 9; case 10083: return 8; case 10084: return 7; case 10085: return 6; case 10086: return 5; case 10087: return 4; case 10088: return 3; case 10089: return 2; case 10090: return 10; case 10091: return 9; case 10092: return 8; case 10093: return 7; case 10094: return 6; case 10095: return 5; case 10096: return 4; case 10097: return 3; case 10098: return 2; case 10099: return 1;
... [SNIP] ...
}
Admin
I agree completely. It's very tiresome.
(I'm not terribly proud that my first comment on this WTF is a grumpy one.)
Admin
Admin
No no, you're doing it wrong.
Admin
Of course, the database iwll be behind a firewall, inside the VPN, to prevent "hackers" from getting access to the trade secrets kept in the database.