Skip to content

Determine Libraries strategy for using the readonly members annotation #1718

@tannergooding

Description

@tannergooding

C# 8 has added a new feature called "readonly members". This feature allows you to indicate that an individual method on a non-readonly struct is itself "readonly" (i.e. that the method does not mutate the state of the instance).

Edit

We need to define a strategy for if/how/when/where this feature should be used across the .NET Libraries. Originally, the intent of this issue was to take a pass over the libraries and annotate methods on non-readonly structs which do not and will never mutate the state of the instance. It was noted that there are a number of these methods in the System.Numerics namespace which users also may try to pass around as in. However, after such a pass was taken by @hrrrrustic in #46675, we realized that we need to be more strategic about this effort.

Some of the aspects that need to be considered are:

  1. For every API touched, we have to evaluate it through the lens of whether we'd ever want to allow mutation to occur -- it would be a breaking change to remove readonly later. For example, adding caching to a readonly method later would be a breaking change.
  2. How we quantify the value that readonly provides across different areas relative to that possibility
  3. If we can define and document API design guidance to follow both with these PRs and for all APIs going forward

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-MetaenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions