CLS compliance and its impact on API design #88607
-
As of today, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It is still beneficial to utilize signed types in normal managed APIs. This is primarily because everything else in the ecosystem takes signed types and it avoids the messiness of needing to cast or handle overflow.
Many scenarios don't actually need this extra bit and you may end up "losing" it anyways when interacting with most other existing APIs, like say
Due to that, the actual proper tracking of the attribute isn't as important as it once was. However, the general concepts behind the attribute do still exist and apply in many cases. They still make a difference in how easy your APIs are to use from other existing .NET code or how easily your code can call other existing .NET code. They still make a difference as to whether the APIs can be consumed downlevel, as to whether they can be consumed from other languages (VB, F#, IronPython, etc). They still make a difference in how the BCL designs its APIs and whether we consider providing alternative overloads or ways to access the same or similar functionality. In general, you should consider the "Framework Design Guidelines". This has the general rules outlined publicly: https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/. But for which there is also a newer version of the annotated book was published a couple years back: https://www.amazon.com/Framework-Design-Guidelines-Conventions-Addison-Wesley/dp/0135896460. The book expands more on the rules, the reasonings why, and may have some updated guidance taking into account newer language features. |
Beta Was this translation helpful? Give feedback.
It is still beneficial to utilize signed types in normal managed APIs. This is primarily because everything else in the ecosystem takes signed types and it avoids the messiness of needing to cast or handle overflow.
Many scenarios don't actually need this extra bit and you may end up "losing" it anyways when interacting with most other existing APIs, like say
Span<T>
, where it only takes a signed type anyways.CLSCompliant
is missing a l…