Rust lacunae
Rust lacunae
Posted Jun 13, 2021 14:13 UTC (Sun) by jezuch (subscriber, #52988)In reply to: Rust lacunae by ncm
Parent article: Rewriting the GNU Coreutils in Rust
Oh, and I believe that Rust's type system is way more powerful than C++'s, which is a complete mess. So the catch-up goes the other way.
Posted Jun 13, 2021 15:02 UTC (Sun)
by mathstuf (subscriber, #69389)
[Link] (2 responses)
Posted Jun 13, 2021 21:54 UTC (Sun)
by khim (subscriber, #9252)
[Link] (1 responses)
Type system of C++ is built like everything else in that language: 100 stories tall skyscraper with the foundation of quicksand. Yes, I know why, but the fact that Rust have a pretty decent type system. Not perfect but pretty good. Type system of C++ is collection of footguns. Yes, you can make your program misbehave in so many interesting ways… but does anyone finds it fun to explore all these ways when they are debugging something? Back then when C++ at least tried to be compatible with old versions it sounded justified at least, but now, when new versions of C abd C++ are designed to add new and exciting bugs into programs which were perfectly safe yesterday that “compatibility!” excuse just doesn't sound convincing. At least Linus works as good enough brake for that activity in “Kernel C”. But nobody does the same with C++. At least safe Rust doesn't try to pretend that someone may write code in 1990 which obeys rules which are not yet finalized yet in 2021. Unsafe Rust, sadly, inherits that issue because of it's LLVM foundation, but in typical program there are limited amount of unsafe rust code.
Posted Jun 24, 2021 15:24 UTC (Thu)
by nye (subscriber, #51576)
[Link]
Posted Jun 13, 2021 19:35 UTC (Sun)
by ncm (guest, #165)
[Link] (1 responses)
Or, you can look at the actual proposals to strengthen Rust's type system to be able to express more of what can now be expressed in C++ and Haskell but not in Rust.
Posted Jun 14, 2021 12:22 UTC (Mon)
by jezuch (subscriber, #52988)
[Link]
[1] https://sdleffler.github.io/RustTypeSystemTuringComplete/
Rust lacunae
Rust lacunae
size > -1
is always false
if size
is unsigned with no warnings or errors caused far more real-world problems than anything related to issues with references. The fact that uint32_t
, uint64_t
and size_t
are not distinct is seriously problematic, too.
> Rust lacunae
size > -1
is always false if size is unsigned with no warnings
$ clang++ -Weverything /tmp/test.cpp
/tmp/test.cpp:4:14: warning: result of comparison 'unsigned int' > 4294967295 is always false [-Wtautological-type-limit-compare]
if (size > -1) {
~~~~ ^ ~~
/tmp/test.cpp:4:16: warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
if (size > -1) {
~ ^~
Even if you don't like using -Weverything
because you don't want to opt in to newly added warnings, I do think that -Wsign-conversion
is something that should always be turned on for code under active development. If you have substantial legacy codebase then you will doubtless need to add a lot of explicit casts to silence false positives, but, well, that's what you asked for.
Rust lacunae
Rust lacunae