(Glad I started this discussion; thank you Nathan for the enlightening links, I need to review all my code now!)
Jeff, maybe what we need is a new value type that advertizes that it's unsigned, but doesn't have the unwanted 2^N wrapping (and its effects on bug-finding tools and compiler optimizations). `class Unsigned { int mValue; /* magic API here */ }` -- feels like unsigned, but underneath it's all `int` arithmetics, with optional >=0 assertions. Would that help? Gerald On Friday, July 5, 2019 at 5:35:30 AM UTC+10, Jeff Gilbert wrote: > That's what CheckedInt is for, and that's what we use. > > The problems webgl deals with aren't arithmatic. Arithmatic is easy. > (CheckedInt!) Reasoning about constraints is hard. > > We have some entrypoints where negative values are valid, and many > where they are not. It's really nice to have a natural way to document > which we expect /at compile time/. Saying "no unsigned types" really > throws out the baby with the bathwater for me. > > On Thu, Jul 4, 2019 at 11:46 AM Botond Ballo <bba...@mozilla.com> wrote: > > > > On Thu, Jul 4, 2019 at 2:03 PM Jeff Gilbert <jgi...@mozilla.com> wrote: > > > It's a huge > > > help to have a compile-time constraint that values can't be negative. > > > > The question is, how useful is that guarantee. Suppose you have some > > code that decrements an integer too far, past zero. Instead of having > > a -1 you'll have a 4294967295. Is that an improvement? Will it give > > the code saner behaviour than the -1? > > > > Cheers, > > Botond _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform