Re: .empty
- From: cj <cj@xxxxxxxxxxxxx>
- Date: Thu, 20 Apr 2006 14:56:28 -0400
For me, nothing shouts empty string like "". It's the most obvious and readable way of denoting an empty string. My use of it has nothing to do with typing extra keystrokes. I suspect some others feel the same way.
And IMHO C# is not that different from VB any more. It's all getting more cryptic and it's all beginning to take more typing--hummm, worst of both worlds. But they're both doing more things now days like interfacing with more databases and with the web and all this makes things more complicated.
Mitchell S. Honnert wrote:
.Is String.Empty really so much more readible than ""?More readable enough that it's worth the few extra keystrokes, yes. I personally don't get the near obsession some programmers have with saving a few keystrokes. As a percentage of all overall development, the time it takes to actually type the code is small. Besides, in most cases, you write the code once, but it's read dozens of time. So, even if you take three extra seconds to type a more explicit reference (be it String.Empty or anything else), you more than make up for the "investment" of the single write during the multiple reads.
Is this a big deal? Not really. I happen to prefer String.Empty to "" because I believe the former to be a bit more clear and that's enough for me. What I find interesting, though, is that this discussion seems to paralel in a way the arguments of C# vs. VB.NET. C# people love that fact that they save a few keystrokes with their cryptic language. I prefer to type a bit extra and have my code more easilly understood by more people. Sure, if you know C#, then you know what weird combination of punctuation marks you have to create to get the functionality you need, but is this in-built obfuscation really worth the relatively small savings in keystrokes? I prefer VB.NET, so obviously I don't think so. To me, it's like driving ten miles out of your way to save a penny per gallon on gas.
I'm not trying to start another C# vs. VB.NET holy flame war here. It's just that the principle of "" vs String.Empty reminded me of some of the same points, albeit on a much smaller scale.
- Mitchell S. Honnert
"Phill W." <p-.-a-.-w-a-r-d@xxxxxxxxxxxxxxxxxxx> wrote in message news:e27spj$gjh$1@xxxxxxxxxxxxxxxxxxxxHerfried K. Wagner [MVP] wrote:"cj" <cj@xxxxxxxxxxxxx> schrieb:. . .Wouldn't that be nice - from the little I understand of I.L.Code, the compiler does come up with something a bit different in each case (not surprisingly).mystring = "" has been around for ages now an is obvious beyond any doubt to me so I surely don't think saying mystring = string.empty is any better.Full ACK. I wonder why the VB compiler doesn't emit 'String.Empty' for empty-string literals.
Given ...
If s1 = String.Empty Then
... the ILCode produced looks like:
IL_0001: ldloc.0
IL_0002: ldsfld string [mscorlib]System.String::Empty
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.VisualBasic]
...CompilerServices.StringType::StrCmp( string, string, bool )
But if you use the "old-fashioned" ...
If s1 = "" Then
... the compiler produces this instead:
IL_0001: ldloc.0
IL_0002: ldstr ""
IL_0007: ldc.i4.0
IL_0008: call int32 [Microsoft.VisualBasic]
...CompilerServices.StringType::StrCmp( string, string, bool )
So does it really matter?
Is "ldstr" so much slower than "ldsfld" that "String.Empty" really is worth all the extra typing?
<advocate owner="devil" >
Is String.Empty really so much more readible than ""?
Regards,
Phill W.
- Follow-Ups:
- Re: .empty
- From: Mitchell S. Honnert
- Re: .empty
- References:
- .empty
- From: cj
- Re: .empty
- From: Mitchell S. Honnert
- Re: .empty
- From: cj
- Re: .empty
- From: Herfried K. Wagner [MVP]
- Re: .empty
- From: Phill W.
- Re: .empty
- From: Mitchell S. Honnert
- .empty
- Prev by Date: Re: Multi-line comments
- Next by Date: Re: FTP with SSL
- Previous by thread: Re: .empty
- Next by thread: Re: .empty
- Index(es):
Relevant Pages
|