You are viewing a single thread.
View all comments View context
11 points

Yeah, arguably the only answer to this question is Rust.

Java/C#/etc. are not fully compiled (you do have a compilation step, but then also an interpretation step). And while Java/C#/etc. are memory-safe in a single-threaded context, they’re not in a multi-threaded context.

permalink
report
parent
reply
8 points
*

C# has native compilation capability, thanks to Native AOT

https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/

permalink
report
parent
reply
4 points

I mean, yeah, valid point. JVM languages also have GraalVM for that purpose.

But I’m playing devil’s advocate here. 🙃

Arguably these don’t count, because they’re not the normal way of using these languages. Reflection isn’t properly supported in them, for example, so you may not be able to use certain libraries that you’d normally use.

These also still require a minimal runtime that’s baked into the binary, to handle garbage collection and such.
Personally, I enjoy fully compiled languages, because they generally don’t lock you into an ecosystem, i.e. you can use them to create a library which can be called from virtually any programming language, via the C ABI.
You cannot do that with a language that requires a (baked-in) runtime to run.

But yeah, obviously someone just specifying “compiled” probably won’t have all these expectations…

permalink
report
parent
reply
5 points

Arguably modern c++ ( aka if you don’t use raw pointers), fits all categories.

permalink
report
parent
reply
2 points

I don’t know much about C++, but how would that do memory safety in a multi-threaded context? In Rust, that’s one of the things resolved by ownership/borrowing…

Or are you saying arguably, as in you could argue the definition of the categories to be less strict, allowing C++ as well as Java/C#/etc. to match it?

permalink
report
parent
reply
6 points

Because you would be using std::shared_ptr<> rather than a raw pointer, which will automatically deallocate the memory when a shared point leaves the scope in the last place that it’s used in. Along with std::atmoic<shared_ptr> implements static functions that can let you acquire locks and behave like having a mutex.

Now this isn’t enforced at the compiler level, mostly due to backwards compatibility reasons, but if you’re writing modern c++ properly you wouldn’t run into memory safety issues. If you consider that stretching the definition then I guess I am.

Granted rust does a much better job of enforcing these things as it’s unburdened by decades of history and backwards compatibility.

permalink
report
parent
reply
1 point

Modern C++ does use references, which can also reference memory that is no longer available. Avoiding raw pointers isn’t enough to be memory safe.

permalink
report
parent
reply
4 points

How are they not memory safe in a multi-threadded context?

permalink
report
parent
reply
4 points

There’s nothing to prevent data races. I myself have fallen into the trap of using the same list from multiple threads.

permalink
report
parent
reply
10 points

I don’t think data races are generally considered a memory safety issue. And a lot of languages do not do much to prevent them but are still widely considered memory safe.

permalink
report
parent
reply
1 point

Swift fits the description too

permalink
report
parent
reply
1 point

Most people would consider it so, but it actually does not either fulfill the argument I posed there: https://forums.swift.org/t/what-language-is-more-memory-safe-swift-or-rust/31987

permalink
report
parent
reply
2 points

Swift does have data race safety as of Swift 6 with their actor-based concurrency model and are introducing noncopyable types/a more sophisticated ownership model over the next few releases

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 2.3K

    Monthly active users

  • 970

    Posts

  • 8.7K

    Comments