3 ms·
If you want to treat a number like a string, why not just treat it like a string? When people enter zip codes online they enter 07045, so why not just store tha
by 3pt14159 13y ago
If you want to treat a number like a string, why not just treat it like a string? When people enter zip codes online they enter 07045, so why not just store that? Even forget about other countries like Canada it seems like the best way...
- z0r 13y agoAgreed - if you're going to validate anything at all, define a new type and don't hide the constraints checking within a secret unit testing lair. I hope I would be agnostic about the code here though, there is no point rewriting poorly conceived stringly typed code - that's a symptom that such efforts would be part of a losing battle
- mtsmithhn 13y agoThe code was for handling zipcodes from a CSV file so we don't really know where the data came from.
- dagw 13y agoThere are lots of way to accidentally lose a leading zero along the way. For a quick and realistic example make a csv file the looks like: 01234,Hello import it into Excel, edit something and export it as csv again. Unless you pay careful attention to what you're doing, you've just lost your leading zero.