Closed JeffAshton closed 5 years ago
Probably; this comes from very old code that has barely changed since the first version.
Can you say more about why you raised this as an issue?
Immutability. Using the readonly properties ensures Immutability of these objects (assuming no reflection). Reduces likelihood of bugs.
Well, I agree that it makes sense to minimize such possibility, but just to be clear, they are private setters so (except for reflection) no code outside of the same class can modify them—and there is basically no code in those classes.
Even less code without the setters. :) Generally when I open a class, I let the modifiers communicate the intent. If these classes are in fact intended to be immutable, then by omitting the setters, the compiler will ensure this, instead of relying on the humans. And the less mutable classes, the less concurrency issues I have to worry about.
May I close this issue, since your question has been answered? I'll take it into account during ongoing code cleanup.
Sounds good. Just wanted to make sure you were aware of the difference.
Is there a particular reason you are using private setters still? Instead of just omitting the setter?
For example:
https://github.com/launchdarkly/dotnet-sdk-common/blob/master/src/LaunchDarkly.CommonSdk/Public/Event.cs#L51
When you omit the setter entirely, the compiler enforces that the value can only be set in the constructor, which aligns with your usage. Was this just grandfathered in?