let’s all head back to the caves and sharpen our spears… the mastadon are on the move soon
You’re groping at my motto:
“Your code is not complete when there is nothing left to add but when there is nothing left to take away.”
- I thought .NET was supposed to help, not incite arguments like:
(foo == String.Empty) vs (foo == “”)
(By the way, the second is cleaner. If you don’t agree, you can go sit on a tack)
Why is there EVEN a String.Empty value anyway?
MS did a really good job creating pointless entries like that in .NET. What’s next, a FooBar type so that n00bs reading documentation can actually compile the examples?
I agree with ALeX, by the way. All I ever use (as a hobbyist) is C and Python.
I realize this post is 3 years old now - however it is still available on the web, and its the first time I’ve read it.
So… I would like to take issue with your “start with bevity”.
Firstly, you should never write code for the compiler, obviously. You should also never write code that “starts with brevity”. I’m one of those that will fight you tooth and nail and say that String.Empty is better, by FAR!, than “”. As I’m reading a line of code I dont have to stop and translate ‘if (someVariable != “”)’ into ‘if some variable not equal to an empty string’. Using String.Empty there just makes it easier to read.
And that’s the thing… one should always wrote code for the HUMAN READER: the next guy that comes along to maintain/tweak/etc your code - even if its you in 6 months.
The code, like a newborn babe, is blameless and innocent…
The typo in “a newborn babe” had me grinning
Great article, BTW!
There is no typo in “newborn babe”. Feel free to google for it, include the quotes.
Or perhaps if(value) vs if(value !== undefined)
One big benefit of String.Empty is that it denotes C# / .NET code. If you deal with multiple languages or want to distinguish source code from configuration via Solution wide search, you’d appreciate String.Empty.