this post was submitted on 27 Oct 2024
54 points (96.6% liked)
Rust
6128 readers
35 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
That is interesting and I didn't know C# had anything like that. I saw another article recently saying at some point we were likely to see Rust get garbage collection.
Would you have a link to that? I know there are many third-party garbage collectors for Rust, but if there’s something semi-official being proposed or prototyped I’d be most curious :)
It's not official or semi-official, it was just someone (a well known Haskell guru if that matters) speculating in a blog post.
https://chrisdone.com/posts/rust/
So someone that is not involved in rust at all and does not seem to like the language thinks it will get a GC at some point? That is not a very credible source for such a statement. Rust is very unlikely to see an official GC anytime soon if ever. There are zero signs it will ever get one. There was a lot of serious talk about it before 1.0 days - but never made it into the language. Similar to green threads which was a feature of the language pre 1.0 days but dropped before the 1.0 release. Rust really wants to have a no required runtime and leans heavy on the zero-cost abstractions for things. Which a GC would impose on the language.
It sounds like he uses Rust and has some issues with it. IDK about green threads but Ada has had tasks (implemented in gnat with posix threads) from the beginning. If you pin a CPU core to a task and don't use gc in it, that can handle your realtime stuff. Or these days, it's becoming more common to use an fpga for cycle level timing control.
Note that traditional Forth cooperative multitaskers used a few hundred bytes of code or even less. This stuff doesn't have to be bloaty.
Added: I've also seen a Boehm-style conservative GC in a few hundred lines of Forth. Using something like that in Rust could work nicely for lots of things.
Anyway, you can have a soft realtime gc with pauses in the low milliseconds (Erlang has that). That's OOMs lower than most internet ping times, so plenty fast enough for web servers. Which are all full of JS bloat now regardless.
You could do a lot of things. Rust had a gc and it was removed so they have already explored this area and are very unlikely to do so again unless there is a big need for it that libraries cannot solve. Which I have not seen anyone that actually uses the language a lot see the need for.
Not like how async was talked about - that required a lot if discussion and tests in libraries before it was added to the language. GC does not have anywhere near as many people pushing for it, the only noise I see is people on the outside thinking it would be nice with no details on how it might work in the language.
The reason is the vast majority of places use c# to avoid this stuff. So performance is often not the first priority
The complexity it adds takes away from the readability and maintainability. Which is often the priority.
But in a hot path where you need optimization these are a good send as previously you had to use raw pointers and completely side step all the safety of the language.
I would say 90% of c# developers will never touch these. It's more for library and framework writers.
I believe most of these features are driven by what the Microsoft Devs need to write asp.net and EF.
Yeah I had thought that C# was basically Microsoft's version of Java, GC'd throughout. But it's fine, I'm not particularly more excited by it now than I was before (i.e. unexcited). I'm not even excited by Rust, but maybe I'm missing something. I think it's fine to use GC for most things, and program carefully in a non-allocating style when you have to, using verification tools as well.
A classic: http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html
There are quite a few places where a GC is just not acceptable. Anything that requires precise timing for one. This includes kernel development, a lot of embedded systems, gaming, high frequency trading and even latency critical web servers. Though you are right that a lot of places a GC is fine to have. But IMO rust adds more than just fast and safe code without a GC - lots of people come to the language for those but stay for the rest of the features it has to offer.
IMO a big one is the enum support it has and how they can hold values. This opens up a lot of patterns that are just nice to use and one of the biggest things I miss when using other languages. Built with that are Options and Results which are amazing for representing missing values and errors (which is nicer than coding with exceptions IMO). And generally they whole type system leads you towards thinking about the state things can be in and accounting for those states which tends to make it easier to write software with fewer issues in production.
It has always had structs. They are often used for interop but can be used to avoid allocations and they are memory safe out the box, which nice.
Both languages are really great in my opinion. But very different use cases generally.