Hello,
SA1129 as many of you know is a rule that has the developer prefer default(T) over new T() for value types. Historically, these were functionally equivalent and the former was preferred to avoid confusion and to make code consistent.
With C# 10, developers are allowed to create parameterless constructors for their structs, which means that these two forms are no longer (necessarily) equivalent.
As such, it is likely time to re-evaluate this rule and discuss whether to rescope or to retire this rule entirely.
I personally see three possibilities:
- Rescope entirely to builtin value types (prefer
default(int) over new int()).
- Rescope entirely to builtin value types and invert preference (
new int() or new() over default(int)).
- Retire entirely (possibly implementing 1 or 2 separately as a new rule).
Hello,
SA1129 as many of you know is a rule that has the developer prefer
default(T)overnew T()for value types. Historically, these were functionally equivalent and the former was preferred to avoid confusion and to make code consistent.With C# 10, developers are allowed to create parameterless constructors for their structs, which means that these two forms are no longer (necessarily) equivalent.
As such, it is likely time to re-evaluate this rule and discuss whether to rescope or to retire this rule entirely.
I personally see three possibilities:
default(int)overnew int()).new int()ornew()overdefault(int)).