3 ms·
Which is why Rust has `usize` for indexes and memory offsets. Beyond that, a good programming language can't fix a bad programmer. Were you aware that, because
by ssokolow 4y ago
Which is why Rust has `usize` for indexes and memory offsets. Beyond that, a good programming language can't fix a bad programmer.
Were you aware that, because people use `int` so liberally, the LLP64 model 64-bit Windows uses and the LP64 model Linux, macOS, and the BSDs use keep `int` 32-bit on 64-bit platforms? Hello, risk of integer overflow.
LLP64 even keeps `long` at 32-bit.
https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_m...
It turned out that the C approach was so bad for portability in practice that it de-facto standardized `int` as 32 bits wide.
- kazinator 4y agoThe C standard describes an int type whose minimum range is -32767 to 32767. Any programmer worth their salt knows this. If writing maximally portable code, they either stick to that assumption or else make some use of INT_MIN and INT_MAX to respect the limits. The minimum range is adequate for all sorts of common situations. Some 32 bit targets had 16 bit int! E.g. this was a configuration for the Motorola 68K family, which has 32 bit address and 32 bit data pointers. See the "-mshort" option of GCC, documented here: https://gcc.gnu.org/onlinedocs/gcc/M680x0-Options.html https://gcc.gnu.org/onlinedocs/gcc/M680x0-Options.html > It turned out that the C approach was so bad for portability in practice that it de-facto standardized `int` as 32 bits wide. And, so, Rust builds on that by renaming that to i32, to further entrench the poor practices. Of course, you will not win any popularity contest by appealing to people who know what they are doing, who are the minority.
- ssokolow 4y ago> Any programmer worth their salt knows this. Rust is one big "C and C++ have proven that 'hire better programmers' isn't a viable solution". You might as well use the same logic to argue against C and C++ restricting and complicating assembly language with a type system and the removal of unconstrained GOTO. > And, so, Rust builds on that by renaming that to i32, to further entrench the poor practices. The rationale is that a program's logic should function the same on different targets, or fail with a compile-time error if that's not feasible. THAT is why the default is to use fixed-size variables except for the `size_t` equivalent which is intended to fit any valid memory offset, and to encourage use of correct types for various applications by making it more bothersome to convert types. (eg. Does a file format use a 16-bit integer for an image dimension? Expose that in the parser's API.) > Of course, you will not win any popularity contest by appealing to people who know what they are doing, who are the minority. I dunno. I know what I'm doing, but I choose Rust over every other language because it's refreshing and de-stressing to teach the compiler to watch my back as much as possible. Everyone has bad days, and distracted days, and tired days, and, unless everything you write is closed-source hobby code, you have to deal with code other people have touched.