5 ms·
Does anyone know of languages that achieve this? I'm interested, I'm currently implementing a project in x86 assembly for this reason, and am happy to try a hi
by veltas 2y ago
Does anyone know of languages that achieve this? I'm interested, I'm currently implementing a project in x86 assembly for this reason, and am happy to try a higher level language.
- School-Cotton 2y agoRust 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.
- simonask 2y agoJust to nitpick, it's not "virtually" no UB, it's literally no UB. (Barring compiler bugs, of course.)
- School-Cotton 2y agoYou are right, thanks for the correction.
- uecker 2y agoAnd issues in the unsafe parts, which could cause UB in the safe part.
- veltas 2y agoSorry, I meant a "close to the hardware" language re parent.
- School-Cotton 2y agoDepending 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++).
- tupshin 2y agoRust is not (much?) further from the hardware than C++
- School-Cotton 2y agoC++ 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”.
- pjmlp 2y agoLike trait implementations, and trait objects.
- School-Cotton 2y agoThat’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)
- pjmlp 2y agoDoesn'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.
- School-Cotton 2y ago> Doesn't matter how common Yes it does, if your concern is “how often do I encounter code where I can’t predict or control what it actually does on the hardware”.
- pjmlp 2y agoAda, 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,...
- sebtron 2y agoZig definitely has undefined behavior https://ziglang.org/documentation/0.13.0/#Undefined-Behavior https://ziglang.org/documentation/0.13.0/#Undefined-Behavior
- pjmlp 2y agoAll 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