As someone who’s had to do a LOT of maintenance over the years, I strongly disagree with this.
It’s true that you should keep the COMPLEXITY of the system to a minimum. But using String.Empty does not increase the complexity of the code at all: it’s the same decision point either way.
Keeping the code “small” does not mean sacrificing maintainability by using meaningless abbreviated variable and function names, for instance.
In terms of maintainability, String.Empty rules out two distinct classes of bug.
- “Fill in the gaps later”. A lot of programmers start out peppering their code with “” and fill in the contents later. Yes, you think you’re too smart to do that. Newsflash: not everyone who alters your code is going to be as smart as you or do things your way.
Using String.Empty tells the suspicious maintenance programmer, “yes, I really meant that to be an empty string”. And an experienced maintenance programmer is always suspicious.
- The difference between “” and " ". If you’re in a hurry, it’s easy to overlook the difference between those two statements, and that’s another source of bugs.
Why do I get the impression that a lot of people giving advice on how to write maintainable code have never had to actually maintain old code? If you haven’t accumulated several years maintenance experience, in several different companies, with code that’s been through several different generations of programmers; you probably don’t know what the real sources of confusion are.