4 ms·
Hard-won pro-tip: IDs should pretty much always have some sort of prefix when stored as strings, even if you swear you're never going to change them. You're not
by jerf 8y ago
Hard-won pro-tip: IDs should pretty much always have some sort of prefix when stored as strings, even if you swear you're never going to change them. You're not going to want to try to divine which id was which based on string length or what chars are where later.
I qualify "when stored as strings" because id numbers in database rows are in a sufficiently strong context on their own, for instance. But once they get serialized to strings, you really ought to stick a prefix on them. You may only change 10% of your ids, but the saving on that 10% will be well worth the cost of prefixing your ids.
- ex3ndr 8y agoBut why this doesn't needed if you use numerical ids?
- cbhl 8y agoIf you work on a sufficiently long lived system, you also discover that you usually want string ids instead of numerical ids. Among other things, numerical ids are subject to enumeration attack (especially if exposed in a GET url parameters).