- 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
If it's any consolation, Troy, all of the people who have corrected you are wrong, also. The correct spelling is "'bated" as in "abated" with the initial "a" elided.
Admin
This back and forth quoting stuff is getting old, so I'll just do it this way:
The BigInteger point is an analogy. A BigInteger class is used to store arbitrarily long integers. It shouldn't care about complex numbers. Just as a ZIP should care about Canadian postal codes. This is in direct reference to webhampster and chesta. Not anything you said.
My comment about C++'s virtual functions was simply in agreement with your comment, and an explanation as to why you might find my example classes repellant. In Ruby, for example, it's all kosher, though. A big difference between C++'s inheritance and Ruby's is that C++ starts at the pointer's type and works down the subclassing hierarchy. Ruby, though, starts with the type of the object itself, and goes back through the ancestor list until it finds a class that defines that method. In short, you always get virtual methods in Ruby.
I'm talking the internals of ZIP code because the comment I initially replied to was, too. Though I said I wouldn't, here's a quote:
I'd do it as a char[5] because whenever I do ToString (), I'm going to want to make a copy of the data anyway, so that nobody messes with my data. I can easily append a 0 to the end of that without trouble. I'd just create the return variable as a char[6] and zero it out before copying the data.
The comments about an abstract postal code are, again, based upon chesta's comment that a ZIP code implemented as an integer won't be able to handle a Canadian postal code.
You seem to think I have some problem with you, but I really don't. Contrary to what you seem to believe, I didn't call you dense. I did, however, call webhampster and chesta dense. Anyway, this was fun. Let's do it again.
Admin
'quay' is the word that isn't pronounced 'kway' . . . um, is that a word in the US, or is it used only here in the UK? (off topic, but I'm curious)
Admin
I'm pretty sure they will NEVER go to 9 digits. And I doubt there is a country that uses letters in their zipcode. That would be crazy.
Admin
To paraphrase Family Guy:
Programmer 1: Fine, I'm going to go write conditional boobs! Programmer 2: Go ahead, they always come out pointy.
Admin
'0' is always the character for zero! 48 is correct if the character set is ASCII but wrong if it is something else like EBCDIC.
Furthermore, 48 is harder to read than '0'.
This is not the IOCCC. Or do you have a pain fetish? BTW your whole code snippet is awful.
Admin
correctly :-p
Admin
Not sure that this is valid, you'd have a table of zipcodes surely to reduce errors and replication - the indexing can then happen on the foreign key if we are talking about databases or you can make your own indexing rules if we are talking about in memory data.
The internal representation is not something you are going to think about upfront. You don't know the problem but have already assigned it to a string or an integer....
How long before you see a zipcode as "John Doe" if you accept it as a string or your code base littered with protections around the zipcode? :-)
Admin
The checkdigit is chosen so that all the digits, including the checkdigit, add to a multiple of ten. (One of the things I learned working for the Eagle.) This whole function only makes sense for USA-based zip codes anyway, as the checkdigit rule isn't applied in, say, Canada.
Here's what my mind comes up with:
Oh, and using the ASCII codes is dangerous too, if the value might be stored with a hyphen in it.
Admin
Assumptions... In the Netherlands we use letters in zipcodes (I am at 3584 BH now).
Admin
Yes, we have quays (/kees/) here in the states, as well. I don't think a lot of people recognize the word in print, though. I thought of "quay" earlier when someone was talking about someone mispronouncing queue as /kway/. I don't find that to be an obvious mistake. (How do you ever get /kway/ out of queue?)
Admin
As a filthy commie European, I'd have to say "who's to say that ISN'T a valid postal code?". If you take into account even the slightest internationalization issues, a string is the only reasonable way to store a postal code. You might want to do some light validation on the input side of things, provided you actually know the postal code scheme that is being used and are prepared to update the validations when it inevitably changes - and specialized classes that e.g. generate barcodes may require some specified format (but again, those will be country specific).
There's always a tendency to want to do too much with ZIP codes; like trying to translate ZIP codes to addresses based on deprecated databases. Another thing that irks me is that, yes, there are addresses that span multiple lines and won't fit in the standard format, and there are adresses with no housenumber, or a huge housenumber (e.g. an appartment complex I lived in that, for no good reason, had 4-digit appartment numbers, even though each floor had it's own housenumber and only contained 12 appartments). I say; an address is a bunch of strings, most of the time.
Also, let's not forget there are too many applications which do not even support ZIP+4 codes.
Admin
Admin
Admin
Yeah, if not just in terms of daily WTF. :D
Admin
Nice graphics this double arrow thingie.
Admin
I'm pretty sure he was being sarcastic.
Admin
Sorry, which part of "and none of the others" wasn't clear?
Admin
OMG WTF !!!
erm what about the poor sap coming along behind you that has to maintain your mess, or make a small change im sure he will have a deadline too.
Im fairly certain it is exactly this sort of thinking that is the root cause for a lot of the WTF's we see. It certainly is for the ones i come across in projects i work on.
Sure you know you should 'probably' do it the right way, but because you cant be bothered spending an extra minute or two doing it properly you dont? sheesh! hell most modern IDE's will do half the work, if not more, for you.
<runs away to burry his head in the sand>Admin
[quote user="Troy Mclure
Ok well when databases/programming languages establish the zip code or telephone number datatype please let me know. I'm sitting here with baited breath[/quote]
Do you mean that you have a worm in your mouth (baited) or that you are holding your breath (bated)? It probably makes a big difference to most people who know you.
Admin
"As has been pointed out above, it makes no sense to apply arithmetic operations on zip codes. Ergo, they are not numbers. It makes no sense to concatenate them, or to compare them lexically, or to do any one of a number of stringesque things with them. Ergo, they are not strings."
I work in a mailing house. We have to deal with millions of Zip codes per week.
Hate to say you're wrong, but I have to perform "stringesque" operations on Zip codes all the time.
For example, comparing the first 2 or 3 characters to the first 2 or 3 characters of other Zips. This gives you the state, and the first level of presort discount (a "3-digit presort" gives you a discount on the postage of the mailing; a "5-digit presort" gives you a bigger discount).
(Has to be range comparisons on the first 2 digits. California, for example, has several "first 2s".)
I have to parse them pretty regularly. (To generate check-digits, amongst other things.)
I also regularly have to concatenate them to generate paragraph-format lists of Zip codes. The address list tables have 1 address per row, which has to be concatenated for certain reports into a single field (usually comma-delimited) on a per-mailing basis. This, of course, also means pulling out the +4 portion of 9-digit Zips, and eliminating duplicates.
These are all very basic, very simple operations, and the code I write does them very easily, but they are all string manipulations on Zip codes.
Sure, if the only time you have to pay attention to a Zip code is when you're typing yours into an order form on Amazon.com, or when you're filling out an application for a credit card, you can assume that Zips aren't treated as strings. But in the line of work I'm in, Zips are, very definitely, strings. Let some spreadsheet file treat them as numbers and drop leading zeroes or subtract the +4 from the Zip, and there are major problems.
(And, since what I do with them is what the Post Office originally created them for, I think it's fair to assume the basic type is "string".)
Admin
Yeah, let's do serialization without forcing metadata in-band. Oh, wait, that's the entire purpose of serialization.
Admin
Never mind, he's just an aarrogant aardvark.
Admin
Well put, aardvark. You are absolutely right about the proper use of abstractions. And you are also a loud-mouthed, self-indulgent, unmannered dirtbag who makes Amon Göth look like a philanthropist. Should a truck run you over as you cross the street, I promise to buy the driver a bouquet.
Captcha: sanitarium (again, I swear!)
Admin
Admin
Admin
Overflow. ;)
Admin
Perfect example of "NICE and clean" code
Admin
-- If you pronounce "queue" as "kway", people need to know so they can stay the fuck away from you.
-- Yes but spelling and pronouncing are not the same thing. Baited and Bated are pronounced the exact same way - hence the reason I didn't spell it right. Queue and Kway are not pronounced the same.
Ok - maybe this is a Brit. U.S. thing. What is this Kway of which you speak? Could it be the word quay which on this side we pronounce as key?
Admin
00ps - sorry, missed that reply when i skimmed. over 2 years ago anyway so prob will never know.