4 ms·
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
by pezezin 2y ago
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?
- kazinator 2y agoA type called isize is some kind of size. It looks wrong for something that isn't a size.
- pezezin 2y agoThen 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 https://doc.rust-lang.org/reference/items/type-aliases.html
- kazinator 2y agoNope! Because then you will also define an alias, and Suzy will define an alias, and Bob will define an alias, ... We should all agree on int and uint; not some isize nonsense, and not bobint or suzyint.
- jclulow 2y agoAlas, it's pretty clear that we won't!
- pezezin 2y agoOk, it is obvious that you are looking for something to complaint about and don't want to find a solution. That is not a productive attitude in life, but whatever floats your boat. Have a good day.
- kazinator 2y ago> looking for something to complaint about You know, that describes pretty much everyone who has anything to do with Rust. "My ls utility isn't written in Rust, yikes! Let's fix that!" "The comments under this C++-related HN submission aren't talking about Rust enough, yikes! Let's fix that!" I'm obviously pointing to a solution: have a standard module that any Rust program can depend on coming from the language, which has a few sanely named types. Rather than every program defining its own.
- hahamaster 2y agoYou insist that we should all agree on something but you don't specify what.
- heinrich5991 2y agoActually, 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`.
- kazinator 2y agoIf you use i32, it looks like you care. Without studying the code, I can't be sure that it could be changed to i16 or i64 without breaking something. Usually, I just want the widest type that is efficient on the machine, and I don't want it to have an inappropriate name. I don't care about the wasted space, because it only matters in large arrays, and often not even then.
- heinrich5991 2y ago> If you use i32, it looks like you care. In Rust, that's not really the case. `i32` is the go-to integer type. `isize` on the other hand would look really weird in code — it's an almost unused integer type. I also prefer having integers that don't depend on the machine I'm running them on.
- kazinator 2y agoSome 32 bit thing being the go to integer type flies against software engineering and CS. It's going to get expensive on a machine that has only 64 bit integers, which must be accessed on 8 byte aligned boundaries.