4 ms·
In the first part (balanced signed integers) I had sort of expected this to eventually say "Oh, this is basically how Rust's niches work, huh" but it doesn't. T
by tialaramex 4y ago
In the first part (balanced signed integers) I had sort of expected this to eventually say "Oh, this is basically how Rust's niches work, huh" but it doesn't. This is especially weird because Jonathan explicitly calls out the "new languages" like Carbon and whatever Herb will call his thing.
Rust's Option<NonZeroU32> is guaranteed to be the exact same size as u32 (4 bytes) and the standard library could do the same thing with a BalancedI32 type if it wanted to.
- jxf 4y agoQ: Who is Herb and what's the "new thing"?
- tialaramex 4y agoHerb Sutter is the WG21 convener. Versions of the C++ programming language are standards from the ISO/IEC Joint Technical Committee JTC1, sub-committee WG21 often referred to as just "the committee" in this context. The convener is in effect head of the committee. For comparison WG14 is the C language commitee. Herb has made lots of proposals for changing C++ over the past half a decade or so, a few of them have shipped in newer C++ versions, most didn't go anywhere. At CppCon (a big C++ convention) Herb's keynote was about a transpiler which takes a different syntax, including most of Herb's features that didn't make it and some new features, and turns that into C++. This has been referred to as either "cppfront" or "cpp2".
- foonathan 4y ago> This is especially weird because Jonathan explicitly calls out the "new languages" like Carbon and whatever Herb will call his thing. You overestimate my knowledge of Rust :D I wasn't aware that NonZeroU32 is a thing, thanks for pointing it out.
- TakeBlaster16 4y agoI was expecting that too. It seems strictly more expressive, since once you have the niche, you can do anything you like with it. And INT_MIN is a better place for it than zero imo. If Rust had a `BalancedI32` I would reach for it a lot more than I use the NonZero types. In my code at least, I've found zero is a pretty useful number.
- tialaramex 4y agoAIUI The sticky problem is that the Rust compiler today wants to see a single contiguous range of scalar values to enable this trick and from its perspective e.g. BalancedI8 would have two ranges, 0 to 127 inclusive and then 129 to 255 inclusive, it doesn't see the signed interpretation when thinking about this problem. That's clearly not impossible to solve, but if I'm correct it means significant compiler development work rather than just a fun weekend chore writing and testing a custom type intended to work only in the standard library.
- codeflo 4y agoIt’s obviously 129 to 127 inclusive, hoping that the implied unsigned overflow has the correct consequences. ;)
- tialaramex 4y agoWoah, that actually seems to work. My toy Option<BalancedI8> compiles and works (in a hacked environment).