5 ms·
C# doesn't have ownership/lifetimes and the kind of safety that comes with them. Also, at the scale of Microsoft’s core global services, when you are paying fo
by dragonwriter 3y ago
C# doesn't have ownership/lifetimes and the kind of safety that comes with them.
Also, at the scale of Microsoft’s core global services, when you are paying for the processing, fast enough (or “CPU efficient enough”) isn't the same as with common apps. Even small efficiency gains are going to yield sufficient savings to be worth a fair amount of developer time.
- hgs3 3y ago> C# doesn't have ownership/lifetimes and the kind of safety that comes with them. Could you elaborate? C# has a garbage collector for tracking resources.
- lucasyvas 3y agoI think the parent post is wrong. This rewrite probably has more to do with performance, "fearless concurrency", and/or developer happiness. C# is safe.
- whimsicalism 3y agothread safe?
- jmull 3y agoIt isn't, but neither is rust. Safe rust is safe from data races, but that's just one kind of potential thread safety issue -- one of the simpler kinds. It's not nothing, but not anywhere close to thread-safe.
- Kinrany 3y agoI think GP is talking about concurrency issues that arise even in single-threaded code when simultaneous mutation from multiple sources is permitted.
- deleted 3y ago[deleted]
- CHY872 3y agoC# has a garbage collector for specifically tracking memory, but lifetimes are more broadly useful. For example, Rust lifetimes (this is also the case in C++ afaik) can be used to suitably scope the lifetimes of mutexes, to have temporary folders which are deleted when they go out of scope, to require that a connection pool is destroyed _after_ the last connection inside it is returned, etc, etc. Mostly, garbage collected language do a bad job of cleaning up objects which refer to resources held elsewhere. Java had persistent issues with direct ByteBuffers (which were wrappers around malloc (but not free!)). Locks are easily held too long. File handles are easily left open. And depending on your GC settings, that file descriptor that's holding a 10GB file around may not get cleaned up for hours. Refcounted languages can be somewhat better, but they don't avoid the bug, they just mitigate the effects.
- jmull 3y ago> C# doesn't have ownership/lifetimes and the kind of safety that comes with them. That's not really true. Like rust, C# is memory safe, although it comes at it in a very different way. "safe" rust does inherently prevent a certain kind of race condition in multi-threaded code that C# does not, thought that's more of a nice incremental improvement, not a fundamental one -- i.e. it doesn't make your multi-threaded code thread-safe, but it does prevent a one type of thread safety violation.
- k_bx 3y agoRust gives you clear semantics on when it drops a variable, so it's being used not only for memory safety but to close files, kill threads, synchronization primitives, and whatever else you want (can be implemented via Trait). Does C# have any kind of GC behaviour guarantees that are similar?
- jmull 3y agoThat's great, but not relevant to the topic of memory safety in C#, which is all I was addressing. I think you are making a point in the broader discussion of C# vs. rust, but that doesn't fit here. (And, personally, I don't care about that so have nothing to say on the topic.)
- magicalhippo 3y agoNot really. There's the IDisposable interface you can implement, and some language features around making it easy to use[2], however there's nothing preventing you from not using those language features and forgetting to call Dispose. In case you forget the GC will call Dispose but it's entirely up to the GC when that happens, so personally I wouldn't say it's similar. [1]: https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-idisposable https://learn.microsoft.com/en-us/dotnet/fundamentals/runtim... [2]: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
- SigmundA 3y ago
- krona 3y ago> C# doesn't have ownership/lifetimes and the kind of safety that comes with them. I believe .net Core has supported several forms of escape analysis for quite a while.
- charles_f 3y agoAlmost all of the services I've seen at Microsoft were built in C#