4 ms·
You might want to check out Ada, D, and OCaml too. Ada is as safe as Rust and lower-level but very fast and very mature. It gets a bit of a bad rap for being u
by PeCaN 11y ago
You might want to check out Ada, D, and OCaml too.
Ada is as safe as Rust and lower-level but very fast and very mature. It gets a bit of a bad rap for being ugly, but after a couple hours the Pascal-ish syntax is not any uglier than C. The type system is much less expressive than Rust's, however, which makes a lot of things more awkward. What you lose in conciseness you make up for in performance and readability. Ada does require you to be extremely explicit about everything, which many people do not like. Still, if you're looking for a language around the abstraction level of C but safe and easily auditable, Ada is a quite well-designed language.
D is basically C++25. There's still some undefined behavior, but you hit it much less often. Also it has excellent metaprogramming support. It is not as safe as Rust, but a little safer than C++. Overall it's a very pleasant language if you're a C programmer and want something higher-level.
OCaml also has a syntax that many people find unpleasant at first. Personally I got over that pretty fast and now fine ML syntaxes beautiful. OCaml is essentially garbage-collected Rust with prettier syntax. It has predictable performance (in the sense of being fairly easy to predict what the compiler will generate—the GC will make actual runtime performance a little unpredictable, but isn't bad; probably because OCaml programs tend to involve much less GC pressure than Java or C#).
I don't think Go should be lumped in with those languages though. It is not very safe (it has a terrible error-handling mechanism and doesn't isolate unsafe code particularly well), it has a large runtime and slow generated code, it offers piss-poor abstractions, etc. If Go becomes the next popular systems language, language design will be set back another 30 years.
- steveklabnik 11y agoHow is Ada lower-level than Rust? I don't really know Ada. I'm also interested in the performance comparison, we're usually neck and neck with C and C++ already.
- alricb 11y agoIt's pretty low level: you can specify the layout of a record in detail, for instance: http://www.ada-auth.org/standards/12rm/html/RM-13-5-1.html http://www.ada-auth.org/standards/12rm/html/RM-13-5-1.html It also has support for hardware interrupts and real time programming.
- steveklabnik 11y agoInteresting, thanks. We give you the ability to control layout as well, but it might not be as convenient as that.
- PeCaN 11y agoI am not as familiar with Rust as I would like, but it seems like a relatively high-level language, akin to OCaml without garbage collection. When programming Ada my thought process is relatively close to C (but with proper modules and generics). From what little Rust I've used, it was more like an ML—specifically more usage of higher-order functions and discriminated unions (which Ada supports, but is 100x less convenient than ML, but still 10x better than C's struct { enum { } what; union { } val; }; pattern). In general, memory management is more manual in Ada than in Rust as well. Actually, Ada is technically less safe than Rust since you can use Ada.Unchecked_Deallocate to circumvent the accessibility checker and Ada doesn't have an equivalent of the unsafe { } block. But you almost always use RAII and memory pools and Unchecked_Deallocate for C types gets hidden in a RAII wrapper. Additionally, fat pointers are opt-in (though roughly as inconvenient as thin pointers), which can be useful for very low-level code. I believe Rust's pointers are always fat? Also I went ahead and checked Rust performance again. I didn't realize you'd gotten so fast. Ada, like FORTRAN, does not allow pointer aliasing by default (there's an ‘aliased’ type qualifier though), so theoretically it can generate faster-than-C. Embarrassingly I don't actually know how alias analysis works in Rust, so maybe you have this advantage too.
- steveklabnik 11y agoIt's interesting, there's a weird dual-character to it. Some people see it like you do, some people see it as a low-level language with some extra features. :) One thing that you may not realize, talking about HOF and such: LLVM is very good at compiling them down. If you use a closure that doesn't actually close over anything, it will get turned into a regular old function, for example. Which means it can be inlined... Rust pointers are not always fat. Slices are, but &T is a regular old pointer, as far as the assembly goes. &mut T automatically gets `restrict` applied to it, basically, we do a lot of aliasing stuff as well. Thanks for elaborating :) I should spend some time with Ada.
- johnbender 11y agoLambda lifting!