- 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
"Ivan 04627" would get to me when I lived in Deer Isle.
Admin
Umm, "[0-9]{5}"?
I had to write a regex for UK postcodes just recently and it was a complicated nightmare. Are you trolling?
Or do you mean that a regex on zip codes would pass many that meet the format but do not really exist, while all postcodes that pass a relatively-simple regex would be valid? That seems unlikely, but ...
Admin
According to this site -- http://maps.huge.info/blog/2011/04/new_zip_codes_for_2010.html -- the US postal service added 41 new zip codes in 2010. I don't know if that's typical, but if so, that's a fair amount of updating to have to do on a regular basis.
Sounds like way too much trouble to me. What's the real advantage over just doing a format check, and if the customer types 12345 when they meant 12354, oh well, too bad for them. Plenty of typos would result in valid zip codes anyway.
Admin
*number from 2010
Remember that with only Gender, DOB, and Zip code you can uniquely identify 87% of the US population.
Admin
When I was a kid and we were all going off to college, one of my friends told me that his school had its own zip code, and that room numbers in the dorms were all unique within the campus, i.e. if there was a room "123" in one dorm, there wouldn't be a room "123" in any other dorm. So, he said, a sufficient address to get a letter to him was:
I never got around to trying it.
Admin
Now you've done it. Some idiot will now insist we use this as the primary key for our customer database.
Admin
Admin
If you have a Post Office Box (a real PO Box, not one at The UPS Store or something), a 9 digit zip by itself will get things to you accurately...
Admin
Even with the correct ZIP code in the 88xxx range, a neighbor of mine once got a package in Silver City, NM that had been misdelivered to Siler City, NC. Nineteen hundred miles off.
Admin
...And yet, still quite intelligent for a manager.
Admin
Admin
The true WTF is not using regular expressions.
Admin
Admin
I cannot justify that. From what I have read, a primary key requires 94% uniqueness, at a minimum.
Admin
Not high enough a percentage to be reliable.
Admin
I see what the real WTF is. It's spelling "ziparray" as "zipary". Outrageous. That should have been caught at code review.
Admin
And by the way, the parrot is quite dead.
Admin
View Larger Map
Admin
http://maps.google.com.au/maps?q=One+And+All+Drive,+North+Haven,+South+Australia+to+Gulf+Point+Drive,+North+Haven,+South+Australia&saddr=One+And+All+Drive,+North+Haven,+South+Australia&daddr=Gulf+Point+Drive,+North+Haven,+South+Australia&hl=en&sll=-34.791563,138.486357&sspn=0.003401,0.007601&geocode=FTsa7f0dYChBCCkDvL2zqLiwajE2PoJr0wxTDw%3BFTIv7f0dgRpBCCm1dl8ErriwajEe7jSkuZaq3A&oq=One+And+All+Drive,+North+Haven,+South+Australia+to+Gulf+&t=m&z=16
An akismet can go and blow a dead goat
Admin
I think Nagesh misquoted:
Admin
I once received some mail addressed:
Human,NowWhat
This from the famed Sevorbeupstry of the planet Preliumtarn of the sun Zarss of Galactic Sector QQ7 Active J Gamma.
It turned out to be some ancient fruit cake, which the locals interpreted as some sort of biological threat. When I tried to acquiesce them by actually eating a portion of said cake, quite tasty actually if a bit dry, they recoiled in horror and assumed I was some sort of God. At which point, they would test that theory regularly, but more often irregularly, by sticking me with their most pointed of weapons, which happened to be a soup ladle, the bowl part, as opposed to the handle, which actually would have made a better weapon.
I thought it was a small price to pay for deity.
Admin
Zipary doo dah, Zipary aye, My oh, My, what a wonderful day,
Admin
Operator with two arguments: binary. Operator with one argument: unary. Operator with no arguments: zipary.
Frankly, I don't see the problem.
Admin
Hardcoding this is ugly, but it could still be done so much better. First make sure the zipcode entered is a five-digit number, then convert it to int and check against a string like this:
valid_zips = "0010101110 /* ...snip 99980... */ 1010101100"
Zeroes for invalid zipcodes, ones for valid. If your int is N, just check valid_zips[N]. This string is one-sixth as long as the submitter's zipstr and doesn't need to be split into an array every damn time. You don't have to type out the 0s and 1s by hand; you've got a list of valid zipcodes, and it would be easy to write a quick one-use program to turn that into valid_zips.
The US has it easy with strictly numerical postal codes. This wouldn't work here in Canada; we have three letters alternating with three digits, e.g. N2L 6G6. With just numbers, it's almost a crime not to take advantage of it.
Side note: There are apparently about 43000 zipcodes in use, so it doesn't much matter if you check against a positive or negative list. What I can't figure out is which one the submitter's got. Neither 00001 nor 00013 (the first one left out) is a valid zipcode.
Admin
I don't remember this part from the trilogy, it has been years since I last read it, but I was thinking of the guide even before I noticed who posted it.
I suppose that human, being mostly solid (from the outside) due to our skeletal system and skin, fear the handle more. Whereas a liquid being would fear the bowl end.
Admin
I think this will do the trick:
http://www.geonames.org/export/ajax-postalcode-autocomplete.html
//Don't care enough to test it out
Addendum (2012-03-26 22:23): I think this will do the trick:
http://www.geonames.org/export/ajax-postalcode-autocomplete.html
//Didn't test it out
Admin
In AUS, you would use a delivery point code to identify a mail drop exactly. Mail which is pre-sorted and pre-identified with a delivery point code (as a bar code) gets a cheaper mail rate. Mail which is not pre-identified is overprinted with a florescent bar code as it goes through the automatic sorting machine.
...And then they give it to the delivery contractor, and he delivers it based on the sorting order and marked street number, completely disregarding the marked country/state/suburb/zip/street, and delivering to an adjacent house if he gets ahead of or behind the sequence.
Admin
In the Netherlands a zip code consists out of four digits and two letters. It uniquely identifies any street in the country. So I don't think any post addressed to "1234AB 12, NL" would have any issues arriving at its destination from anywhere in the world.
Admin
Some other sad part: There are web sites that ask one for BOTH the zip code AND the state, where the zip code is enough to do the job (You only need to look up the first three digits of the zip code to get the state).
Even MORE infuriating is a survey web site that asks you for BOTH your ARE and Year of birth. Can't they do simple subtraction?
ARRGGGH
Admin
I agree, that makes sense. A zero-argument operator is a constant. Which is what the "zipary" in this context is.
Perhaps constants ought to be called ziparies from now on. The word is shorter and should therefore take less time to write.
Admin
@Dotan,
RS components in the UK used to be very proud of having received a letter to 'RS, UK', which I think would be hard to beat.
A family member received a letter at work in the last few years from the USA to the UK, addressed as
Fred Bloggs Company, UK
(Name and company changed to protect the postally innocent, wouldn't want him to be deluged with mail to the real address!)
Admin
Simple subtraction doesn't work. Someone born on the first of January 2000 would be 12 years old, while someone born on the 31st of December 2000 would be 11 years old.
You could attempt to fix the "off by one" by doing a day of year comparison, but there's some spectacular edge cases (e.g. involving when the Gregorian calendar was adopted in various locations).
If you actually do get it right (including all the corner cases) it'd be a huge bloated mess; and it'd still fail to take time travellers into account.
Admin
hmm, I wonder how many hours they logged just for writing that bit of code?
Admin
No you're fired.
You may check 100% on client side for latency reasons.
You MUST check 100% on server side for consistency reasons.
And either way the coder was a moron, client or server side.
But what some may not have realized is this is probably from an excel -> export to text separated values -> use tab and the guy never typed it in.
Admin
DAGS,nub
Admin
The true WTF is ZIP codes.
R*Tard system . have they ever heard of GPS coordinates ? much easier for orbital mail, @ home nuclear warhead delivery and all that stuff.
Admin
But at one place I worked, one of my co-workers was named Pat, and was married to another Pat.
At another job, I worked in a four-story office building where there was someone else in the same building, at a different company, with the same first, middle, and last name of my co-worker. The last name wasn't even a common one.
My street name is 22 characters (with spaces but without abbreviating), so sometimes I just put my name and zip code as the return address on the envelope.
A bit of zip code trivia: 55555 is Young America, MN, the home of a major rebate fulfillment center.
Admin
I see nothing wrong with this code, really. Of course, you could optimize it in some ways if you had some knowlege about particular zip codes scheme used in particular country, but I believe that algorithm should not be tightly coupled with data, current law, 3rd party practices, etc.
Proposed approach separates algorithm from data. Algorithm would be the same for all countries mentioned in this thread.
If you agree that:
Then you must agree, that optimizing further is pointless.
Admin
TRWTF is that this allows for invalid zip codes. The lowest zip code (numerically) is in the 00500's -- Roosevelt Island NY.
Admin
[quote]for (z in zipary) { if (Zip == zipary[z])[/quote]
Correct me if I'm wrong, but z would be values, not keys, right? It should be just
[quote][quote]for (z in zipary) { if (Zip == z)[/quote]
Admin
And how the hell did my [quote] tags not get parsed?
Admin
Admin
This isn't an exciting enough question to have a protracted argument about, but ...
RE regex for US zips: Surely there's plenty of point in doing a [0-9]{5} regex validation. Yes, if someone types "12345" when they meant to type "12354", then yes, such a regex would do nothing to catch it. But if they accidentally typed "1234" and missed on the last digit, or slipped and typed "1234r", or got off by a field and typed their state abbreviation in the zip code field and the zip code in the phone number, or many other possible mistakes, such a regex would catch it. No validation can catch every possible wrong entry; all you can do is play the percentages. (If you could catch every possible wrong entry, then that must mean that you know the one possible correct entry. In which case, why do you need the user to enter it at all? Except for special cases like passwords and quizes, I suppose.)
RE invalid UK postal codes won't past a regex: Really? In the end a regex is only going to say that a certain position must be a digit and not a letter and that sort of thing. Is it really true that if, say, I meant to type "RG14 1EA" (a valid postcode, I believe), but I accidentally type "RG14 2EA", that a regex would catch that? How? As RG14 2EA is also a valid postcode.
RE pk: I once worked on a system where the primary key for the customer table was first initial plus first (some number, I forget) characters of last name plus birth date plus zip code, concatenated together. It was explained to me that the chances that this would not be unique were too small to worry about. I pointed out that twins who were both still living in the city where they were born and who happened to have the same first initial would produce a duplicate. Not to mention there could be purely coincidental duplicates. I was told I was being ridiculous, that it would never happen, shut up and go away. We are surrounded by idiots.
Admin
Maybe with a zip+4 (9 digit zipcode). Gender+5 digits gives you a maximum of 200,000 possibilities excluding DOB. ~300,000,000 us persons, giving 1,500 people of each gender average in each zipcode; for DOB to uniquely identify 1305 of them, only 195 people of each gender can share a DOB in a zipcode. That seems reasonable, until you look at New York City, with 176 zipcodes and ~8m people; roughly 11,000 people of each gender per zipcode; 32 years worth of birthday paradoxes, and roughly 3% of the US population in once city.
Admin
Of course, a really smart programmer would have created a list of NOT allowed zip codes, as obviously there will be less and less of those after each USPS update.
Admin
That's an interesting definition of "upgrade".
Admin
Seems like a bitmap would have been a far better choice.
Admin
If they were 'very clever', then they would not use a linear search on ordered data. Simply keep the codes as numbers and use a better search algorithm.
Admin
I have an even more impressive story regarding the UK post office. Google once needed to send me something from the US in the mail, but for various tin-hat reasons, I don't want the big G to know my address. All they had was the first half of a name (not a personal name even, just my trading name) and the name of the nearest big city (which is in another county), plus a totally ficticious postcode. The post office still managed to deliver it!
Admin
I'm surprised the programmer didn't construct a regular expression from Zip to match against zipstr!