Rust in comparison feels much less practical - glacial compile times and byzantine rules about manging memory. It may be 'safer' but that's a moot point when I find it all so unintuitive that I'm not going to be able to make anything with it anyway.
And I really question what these situations are where you can't have garbage collection in 2021. Hard real time systems, sure, but that's not what 99% of people are using rust for. Maybe people just like the challenge.
Game development, anything with a UI (GC pauses frustrate users), anything that needs high performance (scientific applications, data analysis), you name it. Ownership semantics have a side-benefit of automatic thread safety; something that is less important than memory safety (because many programs can work in one thread but almost no programs can work without allocation) but extremely valuable when needed.
C# Unity, Lua Love 2D,...
>anything with a UI (GC pauses frustrate users)
Millions of C#, Java, Python, Javascript UI apps
>anything that needs high performance (scientific applications, data analysis)
Numpy, Julia,...
Using non garbage collected languages for 99% of apps today is a waste of time, and i'm saying this as mostly an embedded developer.
Your argument also doesn't apply to GUI apps, anyway. C# and Java amount to a huge number of such apps, and they're self-hosted.
GC languages are vastly more productive that manual-memory languages, and for the vast majority of users, that is worth the performance hit.
Most projects are better off written in a GC language because the productivity benefits outweigh the performance costs.
My anecdotal, unscientific experience shows that GC is a double-edged sword that maybe makes writing simple programs slightly faster, at the expense of a much worse maintainability once the code base gets big. And non-memory resource management in GCed languages without RAII is a really huge PITA that kills all productivity gains.
GC allowed memory safety until Rust happened, and that was a big gain, but now that point is moot.
https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScrip...
Or you prefer anything written in DirectX or Metal?
Chapter 5 from The Garbage Collection Handbook.
C# allows for GC free regions with GC.TryStartNoGCRegion, manual memory management via MarshalServices, stackalloc, Span<>() and value types.
Almost forgot Unreal C++ is GC based for entities and anything Blueprint related.
https://docs.microsoft.com/en-us/windows/uwp/audio-video-cam...
https://www.embedded.com/spark-2014-why-i-am-backing-a-predi...
EDIT: Cool list of SPARK2014/Ada embedded projects: https://blog.adacore.com/tag/embedded%20development
GNAT Aux could use some help too:
https://github.com/viperproject/prusti-dev
https://www.pm.inf.ethz.ch/research/prusti.html
extern crate prusti_contracts;
use prusti_contracts::*;
#[requires(something)]
#[ensures(result >= a && result >= b)]
#[ensures(result == a || result == b)]
fn max(a: i32, b: i32) -> i32 {
if a > b {
a
} else {
b
}
}
Ada seems like a fantastic language though, and the 202x edition brought some niceties to the language.@safe works perfectly fine and exactly the same in @nogc code as in GC-enabled code.
https://dlang.org/articles/safed.html#safed-subset
> When you enter SafeD, you leave your pointers, unchecked casts and unions at the door. Memory management is provided to you courtesy of Garbage Collection.
Does D provide the necessary tooling to be able to expose a safe API for something which needs to allocate memory, without needing a GC?
Following that you will want to check for null ext. to make it actually @safe in practice and not just typed as such.
I'm aware that D has @live, a WIP attribute that mimics Rust semantics, but it's not remotely ready for production.
Those same reasons would apply for choosing C over D. They might not apply for choosing C over Rust.
Also anything i want to be very fast on limited hardware i also use C and C only.
As for any hobby programming i do on the side, C is usually my goto choice, unless i want to be very esoteric.. following along the lines of: "The enemy of art is the absence of limitations."
I've been doing it so long I could write macros in my sleep, and inline asm is a fun little exercise.
Though i absolutely agree, especially with someone newer, that could be a major road block. Might want to learn D just to be more efficient (even though I will never abandon my first love completely)
Also C++ compilers are hard too. And optimizing C compilers are hard too...
CPU fabs aren't easy, yet we're fine with that.
- More powerful metaprogramming capabilities.
- Better module and library system.
- Nicer syntax.
The problem IMO is it's just not enough to justify a total move from C++ -> D. The syntax of C++ can't really be fixed, but the other aspects can be improved without a new language.
Furthermore, many of the other downsides of C++ are still present:
- The complexity of the language, and then the sheer number of different ways of doing the same thing.
- Some pretty dark corners in the way stdlib/language feature were implemented that seemed hard to ever fix.
- The way behaviour is specified in the language is very tied to the underlying hardware: rather than explicitly describing behaviour in terms of an abstract machine, it works more in the way C++ is specified where we all know it operates on an abstract machine thanks to compiler optimizations, but the spec likes to pretend it doesn't...
And then there are problems that are introduced by D, such as the fact that a safe subset exists, but depends on GC, so there's a weird split where no "safe code" can be used in contexts where GC is unsuitable.
Contrast this to Rust, where:
- There is a true step-change in bringing safe code to all contexts, not just those where GC can be used.
- It's missing a lot of the complexity of C++. Rust is hard because it has concepts that are foreign to a lot of programmers, but the total number of features is low (compared to C++) so there are fewer surprising ways they can interact.
- Rust is a suitable replacement for C, not just C++, because it's not just adding more features.