Hacker News new | ask | show | jobs
by umanwizard 613 days ago
Rust for example has virtually no UB (edit: no UB) in the safe subset, and it’s rare in most applications to have to use unsafe.
2 comments

Just to nitpick, it's not "virtually" no UB, it's literally no UB.

(Barring compiler bugs, of course.)

And issues in the unsafe parts, which could cause UB in the safe part.
You are right, thanks for the correction.
Sorry, I meant a "close to the hardware" language re parent.
Depending on what you mean exactly I think Rust can be considered pretty close to the hardware. I.e. there's usually an obvious straightforward translation of each line of source code to an implementation in assembly language (which may not be what's actually emitted in practice due to optimizations, but the same is true in C).

There are of course some higher-level features like trait-based generics, so it's not really as close to the machine as C, but it's a lot closer to C IMO than something like Java (or even C++).

Ada, Modula-2 (both available on GCC), D (available on its reference implementation, GCC and LLVM), Swift, Object Pascal (Free Pascal, Delphi, Oxygen), Oberon variants (Oberon, Oberon-2, Oberon-07, Active Oberon, Component Pascal), Zig, Nim, Odin,...
All systems programming languages have undefined behaviour, the golden question is how much.

Also it wasn't what the parent asked for, and I quote: "close to the hardware" language

Rust is not (much?) further from the hardware than C++
C++ is further than rust in my opinion. Vtables that support inheritance, as well as stack unwinding for exceptions, are pretty complicated and totally implicit in C++. Okay rust also technically has unwinding for panics to be fair but it’s rather unusual in practice for programmers to use panics to mean anything other than “crash the program now”.
Like trait implementations, and trait objects.
That’s fair, trait objects do cause a table to be generated, but they don’t support inheritance and subjectively I think they’re used less often than the OOP features of c++ that lead to vtable-based dynamic dispatch. (Traits are extremely common in rust, but dyn trait objects somewhat less so)
Doesn't matter how common, the feature is there, and although we aren't yet that far, might even differ across implementations.

Also trait inheritance exists, enforced via trait bounds, what Rust doesn't support is class inheritance.