Does Rust have any benefits at all over C that is written memory safe?
Does Rust have any benefits at all over C that is written memory safe?
Falling into your wing while paragliding is called 'gift wrapping' and turns you into a dirt torpedo pic.twitter.com/oQFKsVISkI
— Mental Videos (@MentalVids) March 15, 2023
Couldn't get into Rust. People say it's a beautiful fusion of old and new. But maybe it's the new stuff that is the problem. If anything the more I use C the more I appreciate it. I'll admit that crates.io is a cool site. It would be cooler if you didn't have to make a GitHub account (gross).
Rust doesn't have memory safety and claims of memory safety in Rust are just security theater. If you are doing anything interesting or useful in Rust it just ends up in an unsafe block anyways. Rust's memory safety is the equivalent of refactoring your C code to put all potentially "unsafe" code at the bottom of the file and then sticking a comment above it that says "Unsafe code goes here". It is just a label and pretending it is anything other than a label is pure cope.
That being said, if Rust manages to remove unsafe blocks from code entirely that would be useful, but until then it is just a downgraded C that makes huge binaries for no good reason.
> 1% of your application is unsafe, so it might as well all be
There has got to be something in the water here. Its insane the number of C programmer who have never written a C program with more than 2 files.
It has most of the benefits (and many of the drawbacks) of C++, for a start. It's way more expressive. Generics alone go a long way.
You also get unified tooling with a standard build system and so on. Neither C nor C++ has that.
You get more aggressive restrict-style aliasing optimizations by default.
If you don't trust Rust, check out C++ first.
You can't have read much Rust code, if any. Unsafe blocks are used for data structure implementations and FFI and not many other things.
Check out https://github.com/rust-lang/regex for example. Very little unsafe code in the interesting parts. Or check out https://github.com/rustls/rustls, no unsafe code at all.
>Unsafe blocks are used for data structure implementations and FFI and not many other things.
I was reading about someone who was trying to implement a garbage-collected scripting language in Rust (that is, the scripting language was GCed, and the implementation of all that was in Rust). Apparently it was really awful to do it, and rather slow too. There was a detailed reason why and it was subtle; something to do with being unable to use a concurrent mark/sweep algorithm even with unsafe code, and very difficult to make a system of memory arenas work either (because unsafe mode doesn't in any way disable the aggressiveness of the borrow checker, leading to some awful bugs). The headline was that you're far better off using Zig for that sort of task.
Be aware that I cannot confirm these statements. It was just an amusing thing I read. (I mostly prefer plain old C or a much higher level language.)
I saw that same post. They might have just as many problems writing it in Zig if they aren't paranoid about optimization. Half the reason the borrow checker is so anal about your code is to keep LLVM from fucking everything up.
If you hand-optimize all your code, obviously you don't need a high level language for that.
post sauce.
https://zackoverflow.dev/writing/unsafe-rust-vs-zig/
Also, the HN thread https://news.ycombinator.com/item?id=35058176
>zackoverflow.dev
was he participating on some cringe domain name contest?
>>Also, the HN thread https://news.ycombinator.com/item?id=35058176
> Rust is the inverse of Perl: It makes the easy stuff hard.
>
> Writing basic data structures isn't a niche, esoteric edge case. There may be a crate that "solves" what you're trying to do. But does it rely on the stdlib (i.e., is it unusable for systems programming)? Is it implemented making gratuitous copies of data everywhere? Does it have a hideous interface which will then pollute all of your interfaces? Does it rely on 'unstable' features?
>
> Then, there's the 'community.' It seems to consist solely of extremely online people who get a dopamine hit from both telling people they're doing things wrong and creating the most complex solutions possible. They do this under a thin veneer of forced niceness, but it's not nice at all.
that's a very nice summary.
sounds like haskell on the community part
i get same vibe from the "modern c++" community as well.
it's libre software, send a patch if you care.
>C that is written memory safe?
that doesn't exist
proper sum types and pattern matching
C cannot be written memory safe.
>side boob
not memory safe
no nulls
no exceptions
just these 2 make it better than 99% of languages. to add one more, exhaustive match statements
multiple return values
lambdas
generics
>multiple return values
you can return struct
>lambdas
pointless in non oop language
>generics
c11 has all the generics you would possibly need without it getting a bloated pile of garbo
return values
>you can return struct
This is such a bad solution that everybody chooses to use pointer arguments instead.
>pointless in non oop language
No.
>This is such a bad solution that everybody chooses to use pointer arguments instead.
noone uses it because it is less optimal from hardware standpoint as any language that allows it.
Where did you get that idea? You're not going to get better assembly out of this by using out parameters. Return values can use registers if they're small enough, pointers have to touch memory.
And of course if it gets inlined it's all moot, and a lot of functions will be, particularly the ones where the calling convention makes up a big part of the overall performance.
The number one reason people choose one or the other is convenience. C doesn't make compound return values convenient at all, so people don't use them.
>Return values can use registers if they're small enough, pointers have to touch memory.
Sort of. If code that uses pointers gets inlined, it can converted from using pointers into not doing so. LLVM's pretty good at that sort of trick, and I'm pretty sure that both Clang and Rustc will make some use of it.
>pointless in non oop language
do cniles really?
>do cniles really?
Some fools are just full of shit. I'd love lambdas in C, and I understand that doing it well is trickier than it looks at first glance.
>I'd love lambdas in C, and I understand that doing it well is trickier than it looks at first glance.
if you want non-capturing lambda, then just write a static function.
if you want capturing lambda, then just NO. because capturing lambda will need either hidden pointers inserted by the compiler (which will ruin the function signature - thus making it incompatible to use as a function pointer such as qsort argument) or will require executable stack: https://nullprogram.com/blog/2019/11/15/
adding defer/lambda's to C can easily turn out to be the biggest mistake since VLAs.
>C that is written memory safe?
C code is completely memory safe if it contains no bugs, does not use array indexing or pointers, does not use signed integers, does not read from uninitialized variables, and does not perform IO
I hope Rust takes over the world already and becomes as commonplace as a refrigerator so I don't have to hear about it anymore.
>rust creates a 12mb file for a fucking hello world
into le trash it goes
Good, it filters the poor.
reimu sideboob rape
cargo is much more helpful than g++, clang, or gcc
this is the only advantage rust has, C++ tooling is dreadful.
>cmake
>premake
>conan
>vcpkg
Like seriously
>cmake
>premake
>conan
>vcpkg
We don't need all that mess, just put all the GCC flags you need in a script.
>package manager is more helpful than compiler
this is your average rust tranny
rust lacks too many features and doesn't give the kind of freedom that i expect in a systems language. it's just a toy project for trannies and cucks
I just use C++23 with modules and concepts.
>C++23 with modules
>modules
no you don't, not for any non-trivial project
yes I do, modules has been here since C++20. The only thing to come is std as modules
there are no modules without compiler and build system support, and compiler support is non-existent unless you are on msvc (which is still shit)
STL is single handily carrying C++, gnu devs got nothing on him. Microsoft is actually the leading compiler for C++ now kek.
std as modules is soon in msvc as well.
all reasons why c++ is a dying language, the writing is on the wall
it’s more that gnu trannys have been lazy since C++98 was a thing for such a long time before the C++11 and new C++ release schedule ragnarok
well i'm not using a proprietary compiler or anything that microsoft touches, so if the gnu trannies don't want to implement features then c++ is dead for me
they want to implement it, but they have no funds so they are taking a long time. Such is life in communist lands
>I refuse to use better software because it doesn't have a guhnoo loicense
freetard moment
>its hard to know what a C function does
write a comment at the top explaining what it does
>C doesnt have all my data structures
its not supposed to
>its hard to write safe C code
check argc, think about null terminators, and use strncpy
>strncpy
Doesn't write a null terminator if it truncates
Interesting read: man 7 string_copying
>interesting read:
>man 7 string_copying
no it's not interesting at all. it's written by an amature who took over the linux-manpage project after Michael Kerrisk stepped down.
this is the type of shit that retard is writing: https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=7d5c5fd9846d4a1f2ce0fd5503e56caa2087eafc
if (src[strlen(src)] != ' ') raise(SIGSEGV);
>Don't crash on invalid input.
no fucking shit, that check was going to get optimized out by gcc/clang anyways cause it's UB.
just keep track of your string lenght and use memcpy. making copying a couple bytes of memory seem more complicated that it is, is part of the problem.
soft skin, feminine penis, programming socks, femboy milk etc.
Containment language for the trannies.