| ▲ | SideburnsOfDoom 5 hours ago | ||||||||||||||||
> The unsafe keyword is being redesigned OK, I see a lot of C# code often and over a long time. I see the "unsafe" keyword used approximately never. I'm sure that this is useful for some cases. But not everyday things for most of us. If we did use it, it would be carefully isolated in a library for a specific purpose. | |||||||||||||||||
| ▲ | tialaramex 5 hours ago | parent | next [-] | ||||||||||||||||
This moves C# to a more modern systematic understanding of what this keyword is for, but it'll remain very rare in C# the same way it's rare in Rust, and presumably in Swift. The choice of keyword "unsafe" is partly psychological. Turns out if you called this exact same feature "trusted" or whatever the programmers don't have the appropriate feelings about it. They want to write trusted code, they don't want to write unsafe code, so making them write the keyword "unsafe" provides that psychological disincentive. | |||||||||||||||||
| |||||||||||||||||
| ▲ | zmj 4 hours ago | parent | prev | next [-] | ||||||||||||||||
There are standard library APIs that let you do memory-unsafe things without the unsafe keyword (CollectionsMarshal, MemoryMarshal). They're useful, but the burden is on the caller to uphold the invariants. This proposal seems aimed at making that kind of contract more explicit and obvious. | |||||||||||||||||
| ▲ | pjmlp 5 hours ago | parent | prev | next [-] | ||||||||||||||||
Many of us use it in scenarios where others would write a blog post about a rewrite in Rust, C++ or whatever. CLR was designed to support languages like C++, yet many don't learn the knobs. | |||||||||||||||||
| |||||||||||||||||
| ▲ | Profan 3 hours ago | parent | prev | next [-] | ||||||||||||||||
In a game development context, especially where C++ interop is involved and a lot of code lives across a boundary where memory is owned by C++ but you want to avoid/minimize marshaling overhead or just generally maximize performance, the unsafe keyword is quite handy, but outside of those you can indeed probably get around by approximately never using it. There's a lot of power C# gives you if carefully curated, making a lot of cases where people previously might have seen C++ as the only option as suddenly quite viable. ... See also the somewhat arcane Unsafe.As etc APIs | |||||||||||||||||
| ▲ | Quothling 4 hours ago | parent | prev | next [-] | ||||||||||||||||
Around here C# is only really used at stagnant middle sized companies with horrible code bases. The sort where the company follow Uncle Bob religiously, while completely misunderstanding everything Uncle Bob ever said. Doesn't mean the language (and it's runtime) can't be good. | |||||||||||||||||
| |||||||||||||||||
| ▲ | smt88 4 hours ago | parent | prev [-] | ||||||||||||||||
C# is like Rust in the sense that a regular (web, desktop, etc.) developer probably won’t need unsafe, but it’s useful for lower-level work in libraries and CLI tools, especially where performance is important. | |||||||||||||||||