7 ms·
Self-confidence as a programmer is when starting a new project, storing the transaction ID as a long rather than an int...
by cm2187 9y ago
Self-confidence as a programmer is when starting a new project, storing the transaction ID as a long rather than an int...
- trendia 9y agoOr UUID...
- derefr 9y agoI pick UUIDs because experience has taught me that even for the smallest workloads, I'll inevitably have to shard my DB (to partition a shared public cloud from N isolated "enterprise" deployments), and then will inevitably want to do statistical-analysis things that involve ingesting rows from the shards (or log entries referencing those rows), and deduplicating them by ID, without generating false-positive collisions in the process. The simplest way to do that is to just throw UUID at all problems from the start. (https://github.com/alizain/ulid https://github.com/alizain/ulid s are better, but there aren't libraries to generate them in literally every language + RDBMS.)
- eru 9y agoI don't agree with all their reasoning---but ulid still seems like a good idea. (Though the main difference you care about in programming is how they are generated---via timestamps plus randomness, not that they have a different serialization format.) For some applications you don't want to leak the time. Choose wisely.
- rdtsc 9y ago> Self-confidence as a programmer is when starting a new project, storing the transaction ID as a long rather than an int... uint64_t even Or a UUID as others have suggested. Technically C spec doesn't really say exactly how many bits int, long and long long should be. If you want specific sizes and your code to be somewhat portable use the specific bit sizes to make that clear. There are also types for size-like things (size_t) and pointer and offset like things.
- fpgaminer 9y ago> If you want specific sizes I would go further and say you should _always_ use specific sizes, unless forced otherwise. There's no reason not to.
- majewsky 9y agoThere's a usecase for lower-bounded types such as int_least32_t, where the compiler may choose a larger type if it offers better performance. However, if you're using that, the test suite should run all relevant tests for multiple actual sizes of that particular type (through strategic use of #define, for example).
- masklinn 9y ago> There's a usecase for lower-bounded types such as int_least32_t, where the compiler may choose a larger type if it offers better performance. If you're looking for the best performances you shouldn't use leastX types, you should use fastX types (e.g. int_fast32_t for the "fastest integer type available in the implementation, that has at least 32 bits"). The difference between "leastX" and "fastX" is that "leastX" is the smallest type in the implementation which has at least X bits. So if the implementation has 16, 32 and 64b ints and is a 32b architecture, least8 would give you a 16b int but fast8 might give you a 32b one.
- wruza 9y agoThe reason is that anything else is using default types and you lose your safety battle in each: int32_t x = call_returning_int(); line. Otherwise, you assert/recover on each me-they borderline. C is a language where you have absolutely no guarantee that int or constants defined as int will fit into anything beyond int, long or long long, and then there is UB patiently waiting for your mistake. The method of handling that is to never change or fix types unless you have to, and then be careful with that.
- RcouF1uZ4gsC 9y agoThis is a perfect use for the C++ auto feature: auto x = call_returning_int();
- dom0 9y agoThat is, unless you're on Windows.
- simon83 9y agoThe naive, 9 years in the past me once was like "int will last us forever! and it'll save us some space!", only to have to change it to bigint a few months later
- WrtCdEvrydy 9y agoAlso see: IPv4 vs IPv6. Remember, these fancy computing devices were built for the rich and the government, not for the average joe, noone thought computing would be this easily accessible.
- brianwawok 9y agoExcept that isn't a great example because with Nat, ip4 can get us oodles of devices still. Can't really use NAT on a primary key...
- lstamour 9y agoSharding, or a second key, or detecting the iPad and using a lower number with an offset internally? Still requires special handling at one end or another.
- jdietrich 9y agoNAT is a colossal pain in the ass. I shudder to think of the number of man-years that have been spent on NAT traversal. NAT breaks one of the fundamental functions of an IP address - a unique identifier for a network device. It turns a simple identifier into a weird, amorphous abstraction. IPv6 isn't perfect, but we could have avoided a lot of hassle if we'd started off with it.
- Piskvorrr 9y agoSure. Now ping my computer at 10.3.1.4
- maxxxxx 9y ago"int will last us forever! and it'll save us some space!", There are still plenty of people with that mindset. Some will even quote "YAGNI" when you question them.
- maxxxxx 9y agoIt gets better when you realize that on Windows a long is still only 32 bit....
- qb45 9y agoYou mean 64bit Windows? It gets better yet when you realize that on 32bit systems (like in TFA) long usually is 32bit too ;)
- lacampbell 9y agoYou know what, you're right. I'm going to change some SERIALs to BIGSERIAL in the database of my side project. Someone has to start believing in it - it may as well be me.
- taneq 9y agoSo when is it self-confidence and when is it overengineering and invoking the wrath of YAGNI? :P
- hvidgaard 9y agoIt's the smart thing to do - 4.3 billion is not that much. I had some students that asked me if even a long would be enough to handle exponential growth, after all it's only twice as big. As a thought experiement I asked them to come up with a time to fill a 32 bit int completely. They came up with roughly a year. Then as a margin of error I said, let's assume you have 4.3 billion transactions every second instead. This volume can be sustained for 100 years, and we're still not in the danger zone yet.
- ReverseCold 9y ago2^64-1 is a lot more than 2 times 2^32-1
- hvidgaard 9y ago2 times 32 bits equals 64 bits...
- pc86 9y agoUh it's not twice as big. 2^32 ~ 4,294,967,000 2^64 ~ 18,446,700,000,000,000,000
- hvidgaard 9y agoOne is 32 bits, the other is 64 bits. It occupies exactly twice as much space. It can contain far more information, but it is only twice as big on the harddrive.