4 ms·
Echoed my thoughts pretty closely here. My thinking has always been "it's a language and a runtime". I found your bullet points interesting and realized it's
by mdip 5y ago
Echoed my thoughts pretty closely here. My thinking has always been "it's a language and a runtime". I found your bullet points interesting and realized it's been a really long time since I've done any serious systems programming...
1) You mention there's a workaround -- I can't recall exactly what it is but I think an attribute added to the array can be used to force this behavior -- that's a language limitation, for sure, in that there's effectively no way using language syntax to declare that (and no way for the compiler to verify that)
2) The latest version of the language blurs the lines here in a few ways -- using ref types allows one to "directly operate on values in an array" without resorting to unsafe.
I think there's really two things to consider in these cases: (1) Can C# handle the requirement at all? (2) Can C# handle it in a way that is compiler verified, or runtime verified without the use of `unsafe`?
The answer to the first question, in my years of working with the language, have always been "Yes". Ultimately, I can find an attribute or fall back to unsafe and do what I need to do without the compiler's help, but the frequency with which I've needed to do so has been "very close to never"[0]. The answer to the second question is often "Yes", too, especially in the most recent versions. The few cases where I have had to drop to `unsafe` for a performance critical piece of code, I have been able to replace with ReadOnlySpan/Span in every case I've encountered, for example.
[0] But I don't write systems software in C#