this post was submitted on 21 Jul 2025
279 points (97.6% liked)

Programmer Humor

25425 readers
992 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] m_f@discuss.online 55 points 1 week ago (19 children)

Relevant comment

I don't use Rust much, but I agree with the thrust of the article. However, I do think that the borrowchecker is the only reason Rust actually caught on. In my opinion, it's really hard for a new language to succeed unless you can point to something and say "You literally can't do this in your language"

Without something like that, I think it just would have been impossible for Rust to gain enough momentum, and also attract the sort of people that made its culture what it is.

Otherwise, IMO Rust would have ended up just like D, a language that few people have ever used, but most people who have heard of it will say "apparently it's a better safer C++, but I'm not going to switch because I can technically do all that stuff in C++"

[–] calcopiritus@lemmy.world 26 points 1 week ago (14 children)

I kinda disagree. The reason rust caught on is because it is much safer than C++ while having the same or even better performance. And in some contexts, being garbage collected means bad performance.

Before rust you could either have a fast language (C/C++) or a memory safe language (any other language. That is, languages with garbage collector). But if you required memory safety and peak performance, there wasn't any option.

Yes, the reason that rust is both memory safe and fast is because it has a borrow checker. But the borrow checker is the means, not the end.

[–] AnyOldName3@lemmy.world 9 points 1 week ago (10 children)

Garbage collection doesn't guarantee memory safety and it's perfectly possible to create a memory-safe language without garbage collection. There are plenty of garbage collectors for C++ (and until C++23, support for garbage collection was part of the standard, although no one implemented it), and languages like C# let you interact with garbage-collected objects in unsafe blocks.

[–] calcopiritus@lemmy.world 1 points 1 week ago (1 children)

How can you not have memory-safety while also having a garbage collector?

Garbage collection means that all objects live as long as you have a reference to it. Which means that you can only dereference a pointer to invalid memory if you willingly create an invalid pointer, or reinterpret the type of one pointer into another. Going out of bounds of an array counts as the first case.

If a language has garbage collection but no compiler/interpreter supports it, then the language doesn't have garbage collection.

[–] AnyOldName3@lemmy.world 1 points 1 week ago (1 children)

For a start, having a garbage collector doesn't mean its use is mandatory, but even in a language where the garbage collector is mandatory, keeping an array alive as long as any references to it exist doesn't stop you doing things like getting muddled about its length and reading/writing past the end. Mandatory garbage collection only prevents temporal memory bugs like use-after-free, not spatial memory safety bugs like buffer overruns, which need to be prevented by other mechanisms like bounds checks.

[–] calcopiritus@lemmy.world 1 points 1 week ago (2 children)

As I said, I don't consider going out of bounds of a buffer a memory safety issue. Forcing the programmer to handle an out-of-bounds case every time there is an array access can be incredibly tedious. So much that not even rust forces you to do so. And if that language has iterators, it's even less of an issue.

I consider out-of-bounds array access to same as casting a pointer to another type. Just because a language lets you do it, it doesn't mean that it is not memory safe. It is a performance feature, since checking the bounds every time is always possible (and incredibly easy to implement), but also with too big of an impact when you could just check the length once per loop instead of per loop iteration.

[–] sus@programming.dev 4 points 1 week ago* (last edited 1 week ago)

buffer overflows are critical for memory safety since they can cause silent data corruption (bad) and remote code execution (very bad). Compared to those a "clean" unhandled runtime error is far preferable in most cases.

[–] AnyOldName3@lemmy.world 0 points 1 week ago (1 children)

If you're going to change the definition of words, it's pretty easy to show that garbage collection on its own is sufficient, but it's not possible to have a useful conversation if someone's using their own personal definition of the terms being discussed. The generally accepted definition of memory safety includes deeming out-of-bounds accesses and other spatial memory safety issues unsafe.

[–] calcopiritus@lemmy.world 1 points 1 week ago (1 children)

With your definition this conversation doesn't make sense though. Since rust's direct array access doesn't perform bounds checks when building in release mode. And it doesn't require using unsafe.

[–] AnyOldName3@lemmy.world 1 points 1 week ago

That's not what Rust's documentation says. It does a compile-time bounds check if it can prove what the index might be during compilation, and a runtime bounds check if it can't. In release mode, it tries harder to prove the maximum index is below the minimum length, but it still falls back to a runtime bounds check if it can't unless you use get_unchecked, which is unsafe.

load more comments (8 replies)
load more comments (11 replies)
load more comments (15 replies)