- 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
Storing customer IDs as number types is not just "not ideal", it is WRONG, TRWTF, and the source of all these issues.
I'd like to hate on Microsoft, but this is not their fault.
Admin
Oh, and "I like to prefix" is also just wrong. Either you always pad to a specific width, or you never prefix.
Admin
Sorry, I was a bit unspecific: Storing as floating point numbers (no matter the precision) is wrong. Proper integers are fine.
Admin
Consideration: If we can't do arithmetics with them, they are not numbers, no matter how we call them. Let's say we have customer 123 and customer 456, can we do something like "customer 123 + customer 456" to get customer 579? What if we substract 100 from customer 12345? Do we have 3 times customer 23456? What is 1/12th of customer 9876? Would that make any sense? No? Then: Those are strings (or maybe even a specific native or constructed datatype), but not numbers, no matter if we "implicitely" consider them integers, floats our doubles just because they could look like those. It can even start with plain words, thought about carefully, maybe: "customer ID" (an ID doesn't imply it's a number) instead of "customer number", and on the other hand, customer IDs like "003.0278854", "CT8879556", "187/9965/0002774" wouldn't be called "numbers" either. Sadly, we routinely say things like "phone number" and then use integers... Language enables thinking. And that should have been possible decades ago.
Edit Admin
The only main reason you'd use numbers instead of strings is for storage size... if customer IDs are guaranteed to always be integers (e.g. they're auto-increment IDs), they use way less storage than a string, and things like indexes are much more performant. Obviously depends on the scale of data you're working with, how big the strings/numbers are, and how important performance is.
Admin
re: phone numbers Technically... you can int-divide and modulus telephone numbers to get area code and local part (which should be done with substrings)