this post was submitted on 05 Aug 2024
961 points (97.5% liked)

Programmer Humor

19821 readers
817 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
961
Evolution of C (programming.dev)
submitted 4 months ago* (last edited 4 months ago) by JPDev@programming.dev to c/programmer_humor@programming.dev
 
you are viewing a single comment's thread
view the rest of the comments
[–] ZILtoid1991@lemmy.world 8 points 4 months ago (2 children)

Issue is, Rust is not a drop-in replacement for C. The memory safety features are just one part, and since Rust is also a "weakly" functional language, thus its prefered to write such code with it.

[–] sukhmel@programming.dev 6 points 4 months ago (2 children)

Anything that is drop-in replacement for C (or C++ for that matter) is going to be awful because of the same compatibility burden, imo

[–] ZILtoid1991@lemmy.world 2 points 4 months ago

D is a mostly drop-in replacement (type renaming and such needed though), and it doesn't have that issue. D even has a mode called BetterC, where the D standard library and the garbage collector is left out.

[–] fermuch@lemmy.ml 1 points 4 months ago (1 children)
[–] ZILtoid1991@lemmy.world 3 points 4 months ago (1 children)

Oh boy, Zig is just uglier C++ with memory safety, and it still has those awful header files...

[–] CanadaPlus@lemmy.sdf.org 0 points 4 months ago (1 children)

IIRC it's garbage collected, so really it's just a version of Java.

[–] qaz@lemmy.world 2 points 4 months ago* (last edited 4 months ago) (1 children)
[–] CanadaPlus@lemmy.sdf.org 1 points 4 months ago* (last edited 4 months ago)

Apparently, I do not RC. I might have been thinking of Nim. A quick search indicates it's not memory-safe, though. It has a few helpful features to keep errors under control, but that's it.

[–] CanadaPlus@lemmy.sdf.org 3 points 4 months ago (2 children)

Yeah, it's not a small change. If there was a simpler way to make C memory-safe, it would have been done decades ago. It's just a different language too, which is fair given how much younger it is.

[–] ZILtoid1991@lemmy.world 1 points 4 months ago (1 children)

D kind of did that (C pointers are still an option, alongside with the preferred dynamic arrays, which has the memory safety features), and once I've seen a C compiler fork that retroactively added D-style memory safety features, although they also very much insisted on the "const by default" mantra.

[–] CanadaPlus@lemmy.sdf.org 2 points 4 months ago

I think this is one of those things where there's no "kind of". Pointers were added for a reason, you're probably not going to implement a database very well without them. If you use them, at some scale you're inevitably going to have memory bugs. Technically, if you were to only use hardcoded printfs, C is memory safe too.

[–] ssm@lemmy.sdf.org 1 points 4 months ago* (last edited 4 months ago) (1 children)

If there was a simpler way to make C memory-safe, it would have been done decades ago.

We've had compile time sanitizers (-fsanitize=blah in gcc/clang) and runtime sanitizers (valgrind) for ages. I don't know how they stack up against rust's compile time sanitizers, but it's something.

[–] CanadaPlus@lemmy.sdf.org 1 points 4 months ago* (last edited 4 months ago)

About how an Excel spreadsheet with no formulas stacks up against a corporate accounting suite. Valgrind is how you find the bleeding once you inevitably introduce a memory bug. I don't understand all the fsanitize options, but I'm guessing they aren't a blanket solution, exactly because memory bugs have still been inevitable.

This thread is making me wonder how many people actually understand what Rust does. It rigorously prevents any form of memory error at all in normal code, and unsafe blocks, where needed, tend to be tiny. It makes C segmentation faults look just as goofy as JavaScript type errors.