Skip to content

SA1129 : C# 10 Re-evaluation #3430

@TheBrambleShark

Description

@TheBrambleShark

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:

  1. Rescope entirely to builtin value types (prefer default(int) over new int()).
  2. Rescope entirely to builtin value types and invert preference (new int() or new() over default(int)).
  3. Retire entirely (possibly implementing 1 or 2 separately as a new rule).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions