Re:Microfeatures I'd like to see in more languages
by ablob on Thursday January 05, 2023 @06:32PM
(#34268548)
The point made is independent of the integer size and I think we should assume in good faith, that uint8 was chosen for the purposes of an example.
Re:Microfeatures I'd like to see in more languages
by feoren on Friday January 06, 2023 @02:56AM
(#34272122)
Um, maybe, but then his example is sixteen million times worse than reality! If I argued against some technology by showing how bad it would be if it were sixteen million times worse, that's just not a very good argument, is it?
If you're indexing with a [u]int32 you need to worry about this once every 4 billion increments, and if an incomplete cycle is a show-stopper for you, you can compute a safe modulo yourself based on the size(s) of your circular array(s), but more likely you just need something else. But really, you don't care if your cache hiccups a little once every 4 billion caches.
You make a good point, of course, I'm just allergic to people poking holes in back-of-the-napkin explanations of things with the trite "but integers can overflow!" It's one of those most common well actuallys written on this site. Of course integers can overflow. They almost never do though, do they? And if they do, a test fails and you add a single line somewhere to fix it.
I really think the vast majority of programmers are too often thinking about bits when they should be thinking about math.