Comment by kazinator
8 hours ago
> you have to mention the size explicitly
It's unbelievably ugly. Every piece of code working with any kind of integer screams "I am hardware dependent in some way".
E.g. in a structure representing an automobile, the number of wheels has to be some i8 or i16, which looks ridiculous.
Why would you take a language in which you can write functional pipelines over collections of objects, and make it look like assembler.
If you don't care about the size of your number, just use isize or usize.
If you do care, then isn't it better to specify it explicitly than trying to guess it and having different compilers disagreeing on the size?
Actually, if you don't care about the size of your small number, use `i32`. If it's a big number, use `i64`.
`isize`/`usize` should only be used for memory-related quantities — that's why they renamed from `int`/`uint`.
A type called isize is some kind of size. It looks wrong for something that isn't a size.
Then just define a type alias, which is good practice if you want your types to be more descriptive: https://doc.rust-lang.org/reference/items/type-aliases.html
3 replies →
Is it any better calling it an int where it's assumed to be an i32 and 30 of the bits are wasted.