top | item 37957286

(no title)

tryfinally | 2 years ago

It’s an extraordinary feature that is only intended for optimization of edge cases. Making the feature verbose and somewhat ugly to use seems like an intentional choice. This way if a beginner comes across this “confusing/weird looking” code they can look up the attribute and see what it does, whereas a more convenient/native syntax would be less recognizable and noticeable. This is similar to the idea that you should make ugly APIs ugly to use (to avoid giving users a false sense of security).

discuss

order

nick_|2 years ago

But we can already do `Span<int> ints = stackalloc int[5];` without using `unsafe`. The array size doesn't even have to be const in that example. They could have just made an optimization when a const is supplied for locals, and then use the existing fixed array syntax for members.

It seems to me the budget for C# lang dev is way down. This seems like it was implemented this way so they didn't have to change many internals.

pjmlp|2 years ago

Swift, Nim , D and others are able to offer similar capabilities without being such a hack, rather a proper designed language feature.