C
cody
There should be a way to mark methods without sideeffects with a special
Attribute so that the compiler can recognize them and is able to issue a
warning:
public class string
{
[NoSideEffect()] // alternatively we could name it
[RequireUseReturnValue()]
public string Trim()
{
//...
}
}
this would be especially useful for immutable classes like string. A common
mistake is that you do:
myString.TrimEnd(',', ' ');
and as an effect, nothing happens since we forgot to assign the newly
created string.
Attribute so that the compiler can recognize them and is able to issue a
warning:
public class string
{
[NoSideEffect()] // alternatively we could name it
[RequireUseReturnValue()]
public string Trim()
{
//...
}
}
this would be especially useful for immutable classes like string. A common
mistake is that you do:
myString.TrimEnd(',', ' ');
and as an effect, nothing happens since we forgot to assign the newly
created string.