5 ms·
> What kind of solution would you propose to folks like your boss? Rewrite it in C#. It’s safer than Rust, because VM. Both standard and third party libraries
by Const-me 3y ago
> What kind of solution would you propose to folks like your boss?
Rewrite it in C#. It’s safer than Rust, because VM. Both standard and third party libraries are often way better. With modern versions of the language, GC allocations are avoidable if that’s what needed for performance reasons. C interop is equally simple.
- pjmlp 3y agoNot necessarily VM, depending on how it gets deployed.
- tuna74 3y agoCould you expand on how to avoid using GC in C#?
- pjmlp 3y agoValue types (structs), stack allocated arrays, spans, native memory allocation, arenas. You can also enable the warnings/errors that complain about missing using declarations for class and structs with the Dispose pattern.
- Const-me 3y agoDon’t create new objects, instead use stack and/or unmanaged heap. This reduces the expressive power of the language, for example LINQ from the standard library is probably out because based on the delegates which require memory allocations. Still, the language is very usable even without GC allocations. For example, that library re-implements a subset of ffmpeg for Raspberry Pi4 running 32-bit Linux, with no memory allocations in runtime: https://github.com/Const-me/Vrmac/tree/master/VrmacVideo https://github.com/Const-me/Vrmac/tree/master/VrmacVideo
- dequan 3y agoC# is not more safe than Rust is and falls to prevent null pointer exceptions and modified collection exceptions.
- Const-me 3y ago> C# is not more safe than Rust By design, Rust requires unsafe code to implement any non-trivial data structures (except trivial POD types). This applies to both Rust standard library, and third-party crates. The issue is not a theory, security bugs actually happened in reality. Here’s an example about the Rust standard library: https://shnatsel.medium.com/how-rusts-standard-library-was-vulnerable-for-years-and-nobody-noticed-aebf0503c3d6 https://shnatsel.medium.com/how-rusts-standard-library-was-v... By contrast, thanks to the VM and the GC, C# allows to implement very complicated data structures without any unsafe code or unmanaged interop. The standard library is also implemented in idiomatic memory-safe subset of the language. For example, here’s the hash map: https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs https://source.dot.net/#System.Private.CoreLib/src/libraries... > falls to prevent null pointer exceptions and modified collection exceptions Yes indeed, but these exceptions are very unlikely to cause security bugs in the software.
- dequan 3y agoThe entire JIT, garbage collector and most of the C#'s VM are all implemented in C++. This has caused various issues in the past which are exploitable from managed code. The amount of unsafe code used to implement C# vastly outweighs the amount in Rust's standard library.
- Const-me 3y ago> The amount of unsafe code used to implement C# vastly outweighs the amount in Rust's standard library. According to bing.com chat, https://github.com/dotnet/runtime https://github.com/dotnet/runtime has 3.5M LOC, and https://github.com/rust-lang/rust https://github.com/rust-lang/rust has 6M LOC. The right panel of https://github.com/dotnet/runtime https://github.com/dotnet/runtime says 80% of the .NET runtime is written in C#. This makes me wonder, do you happen to have a link for your “vastly outweighs” statement?
- dequan 3y ago