Live data from Hacker News

Thoughts on Integers (2023)

blog.xoria.org

11–12 of 12 posts

Re: Thoughts on Integers (2023)

#11
post #8

> Given the roughly 30% overhead of overflow checks, I think restricting them to debug builds is a reasonable tradeoff. I can also see an argument for using wrap on overflow even in debug builds for consistency and simplicity. I don’t understand the sentiment to want different behaviour for overflow in debug and release mode. You want to catch overflows because they’re thought of as errors, but not in production. In…

In production you generally want your code to not be 1.5x-2x slower than C/C++, otherwise people will ditch your whole language with all its other benefits in pursuit of performance.

There's a lot of safe but slow languages, Rust is trying incredibly hard to be a safe language that is still seen to be in that general C/C++ ballpark of performance.

Re: Thoughts on Integers (2023)

#12
post #9

> Rust eliminates each of these points: all integer types have an explicit size, and all types are prefixed with either i or u for signed and unsigned respectively. There’s no bias towards a certain size or signedness. Most of that paragraph is objectively false: fn main() { let i = 1; let j = 1; print!("i: {:?}\n", !i); print!("j: {:?}\n", !j); // spooky action at a distance let v = vec![1, 2, 3]; v[i]; } Only a sma…

Yeah, this has come up a few times when I was coding Rust. From just reading your code I know for sure that i is a usize (indexing is very common), but don't know what j is (I usually expect Rust to throw some kind of "could not infer integer type" compiler error, and it doesn't do that here). I'm guessing maybe i32. Code at the end of the function changing the meaning of code at the beginning of a function has also surprised me a couple times.

In my particular case I'm using Zed with type hints enabled, so the editor displays that expression as `let i: usize = 1;` automatically (which is really useful in a language with type inference, especially with expression as weird/complex as Rust iterator method chains). You're right that I wouldn't know if I were to open the file in a simple text editor.

Post reply on HN