Hacker News new | past | comments | ask | show | jobs | submit login

Sometimes I feel weird coding zip codes as strings but this is a great example why. If my program ever treats a zip code like a number I would like it to throw an error. At least in this case the error looks like an accident.

On topic, from yesterday: https://news.ycombinator.com/item?id=21067764

It's another social sciences paper but in this case a co-author has requested a retraction over his strong belief that the paper includes fabricated data. The retraction request has been denied. It differs from this paper in that the data anomalies look intentional.




My rule of thumb is that anything that’s not part of a calculation will be a string. Any chance I ever want to multiply a zip code? Doubtful. String, it is.


> If my program ever treats a zip code like a number I would like it to throw an error.

One interesting thing you can do though, is sort by zipcode. This sorts your mail from East to West in the US. You can use that as a rough estimate of shipping time.


That's really cool, even if I never find a place to use it.

Anyway you can still sort strings.


So? You make sure the zip code is left zero filled and the strings sort fine. Admittedly, numbers would sort a bit faster.


Non-US postal codes often include letters and spaces, and some areas don't use postal codes at all.


All US postal codes have an optional - (hyphen) in them as well, and so you should always encode them as strings anyway.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: