4 ms·
Similarly, here is your reminder than US Zip Codes aren't numbers, because many of us here in the Northeast have them start with a zero (or even two). So don't
by vitaliyf 7y ago
Similarly, here is your reminder than US Zip Codes aren't numbers, because many of us here in the Northeast have them start with a zero (or even two). So don't store them as integers, because Boston is 02108, not 2108.
See https://en.wikipedia.org/wiki/List_of_ZIP_Code_prefixes https://en.wikipedia.org/wiki/List_of_ZIP_Code_prefixes
- pwdisswordfish2 7y agoSome are yet to get the memo. Not so long ago, I've seen a TypeScript course that demonstrated union types with an example of representing zip codes as either strings or numbers…
- drstewart 7y agoMy general rule is if you can't add two values together then they shouldn't be represented as number types.
- pwdisswordfish2 7y agoSo a temperature is a number only as long as it's expressed in kelvins?
- elcomet 7y agoyou can add farenheihts or celcius.
- lmkg 7y agoYou can meaningfully add or subtract degrees to a temperature reading, but you can't meaningfully add two readings together (unless you're averaging them!). There's a subtlety here: A temperature difference is actually a different data type than a temperature. Dates and times have similar issues: You can add 2 hours to 3 hours, and you can add 2 hours to 3 o'clock, but you can't add 2 o'clock to 3 o'clock. A better litmus test is whether you can subtract values. The difference between two times, or two dates, or two temperature readings is something that is meaningful and commonly used in everyday life. The difference between two ZIP codes is nonsensical.
- zentiggr 7y agoToo bad the post office wasn't aware of space-filling curves when they started assigning regions :)
- Izkata 7y ago> The difference between two ZIP codes is nonsensical. Not completely, there's a rough east-to-west pattern: https://d33wubrfki0l68.cloudfront.net/979d9b9012d8bbb1e4f14b85fd7b0dc5f961feaa/058e9/assets/img/docs/zip-code-zones.png https://d33wubrfki0l68.cloudfront.net/979d9b9012d8bbb1e4f14b... So the difference is extremely crude geographic distance. /evil
- kaoD 7y ago> unless you're averaging them! Nitpicking, but that seems like a great case for them being numbers. You will never average credit cards or zip codes. Averaging times is meaningful too (e.g. the mean arrival time). I think op meant "adding" as generally doing math on them. Each quantity will have its own natural operations. I see what you mean though, subtraction seems like a good heuristic by virtue of difference being mostly (always?) meaningful.
- titanomachy 7y agoYeah, it's 5°C warmer than it was yesterday.
- egdod 7y agoThat’s the difference, not the sum.
- rocqua 7y agoPerhaps you should take differences instead? Same with pointers. Their addition isn't meaningful, but their differences are. In general, addition is only meaningful in linear systems, but differences can be meaningful in affine systems.
- jniedrauer 7y agoI once saw an integer overflow impact production because someone was concatenating primary keys together as strings to form new primary keys (and storing them as an integer type).