Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SA1122: Rule to prefer string.Empty over "" is missing justification #81

Open
rillig opened this issue Aug 7, 2016 · 2 comments
Open

Comments

@rillig
Copy link

rillig commented Aug 7, 2016

https://github.com/Visual-Stylecop/Visual-StyleCop/wiki/SA1122 currently says:

This will cause the compiler to embed an empty string into the compiled code.

The rule SA1122 is in the Readability category, therefore it should not matter what code is generated by the compiler. Furthermore, when using string.Empty instead of "", the compiler embeds a reference to string.Empty into the compiled code. I didn't check it, but it feels like that takes more bytes in the resulting binary.

The C# language specification says:

Each string literal does not necessarily result in a new string instance. When two or more string literals that are equivalent according to the string equality operator (§7.10.7) appear in the same program, these string literals refer to the same string instance.

This sounds like an argument in favor of using string literals directly.

All in all, what is missing is a convincing argument why using string literals is bad.

@yariker
Copy link

yariker commented Jun 27, 2017

Another argument against this rule is that using string.Empty instead of "" inevitably leads to a mixture of styles, because you can't put string.Empty inside of an attribute, constant initializer or default parameter.

@MisinformedDNA
Copy link

I would suggest turning this off, by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants