Home All Groups Group Topic Archive Search About
Author
19 Apr 2006 2:33 PM
cj
What is string.empty used for?

I can't say: if string.empty then
I have to use:  if string = "" then

which is ok, I just want to know what .empty is for.

Author
19 Apr 2006 2:42 PM
Herfried K. Wagner [MVP]
"cj" <cj@nospam.nospam> schrieb:
> What is string.empty used for?
>
> I can't say: if string.empty then
> I have to use:  if string = "" then
>
> which is ok, I just want to know what .empty is for.

\\\
If x = String.Empty Then
    ...
End If
///

is semantically equivalent to

\\\
If x = "" Then
    ...
End If
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
19 Apr 2006 2:44 PM
Cor Ligthert [MVP]
CJ,

There are endless methods to tell that a string exist however does not
contain any character.

One of those is string.empy another one string="" and string=nothing
although that initializes.

In this newsgroup is once taken the string="" for the string without any
character.

However I would not botter to much. The only dangerous one can be the
string=nothing, because that test as well on a string that was in advance no
string (Is Nothing)

I hope this helps,

Cor

Show quoteHide quote
"cj" <cj@nospam.nospam> schreef in bericht
news:uMG6x47YGHA.3444@TK2MSFTNGP05.phx.gbl...
> What is string.empty used for?
>
> I can't say: if string.empty then
> I have to use:  if string = "" then
>
> which is ok, I just want to know what .empty is for.
Author
19 Apr 2006 2:54 PM
Clive Dixon
Use String.Empty to initialise strings to zero-length.

Dim s As String
s = String.Empty

To check whether a string is zero length, check the Length property.

If s.Length = 0 Then
    '...
End If

http://www.gotdotnet.com/team/fxcop/Docs/Rules/Performance/TestForEmptyStringsUsingStringLength.html


--
======================
Clive Dixon
Digita Ltd. (www.digita.com)
Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:uMG6x47YGHA.3444@TK2MSFTNGP05.phx.gbl...
> What is string.empty used for?
>
> I can't say: if string.empty then
> I have to use:  if string = "" then
>
> which is ok, I just want to know what .empty is for.
Author
19 Apr 2006 2:57 PM
Mitchell S. Honnert
To add on what Herfried and Cor have already said, I prefer the use of
String.Empty to "".  Yes, they're syntactically correct, but the few extra
keystrokes are worth the added clarity.  Is there a space in there that I
can't see becuase of the IDE's font setting?  Is one of the double quotes
really two single quotes?  Better to avoid the potential for confusion and
just use String.Empty.

- Mitchell S. Honnert


Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:uMG6x47YGHA.3444@TK2MSFTNGP05.phx.gbl...
> What is string.empty used for?
>
> I can't say: if string.empty then
> I have to use:  if string = "" then
>
> which is ok, I just want to know what .empty is for.
Author
19 Apr 2006 5:58 PM
cj
Well, I see I typed my question a bit off again.  When I posted
   if string.empty

I meant it to be interpreted
   if mystring.empty

which I assumed would return a True or False and it doesn't.
I didn't expect for anyone to think I meant using it like
   if mystring = string.empty

But ok, I see what .empty is all about now.  And I don't like it.
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.  Heck I was confusing in my post.  But then that's just my
opinion. :)

Thanks to everyone for explaining .empty to me!


Mitchell S. Honnert wrote:
Show quoteHide quote
> To add on what Herfried and Cor have already said, I prefer the use of
> String.Empty to "".  Yes, they're syntactically correct, but the few extra
> keystrokes are worth the added clarity.  Is there a space in there that I
> can't see becuase of the IDE's font setting?  Is one of the double quotes
> really two single quotes?  Better to avoid the potential for confusion and
> just use String.Empty.
>
>  - Mitchell S. Honnert
>
>
> "cj" <cj@nospam.nospam> wrote in message
> news:uMG6x47YGHA.3444@TK2MSFTNGP05.phx.gbl...
>> What is string.empty used for?
>>
>> I can't say: if string.empty then
>> I have to use:  if string = "" then
>>
>> which is ok, I just want to know what .empty is for.
>
>
Author
19 Apr 2006 6:24 PM
Herfried K. Wagner [MVP]
"cj" <cj@nospam.nospam> schrieb:
> Well, I see I typed my question a bit off again.  When I posted
>   if string.empty
>
> I meant it to be interpreted
>   if mystring.empty
>
> which I assumed would return a True or False and it doesn't.
> I didn't expect for anyone to think I meant using it like
>   if mystring = string.empty

That's because 'String.Empty' is shared.

> But ok, I see what .empty is all about now.  And I don't like it.

Dito.

> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
20 Apr 2006 11:56 AM
Phill W.
Herfried K. Wagner [MVP] wrote:
> "cj" <cj@nospam.nospam> schrieb:
.. . .
>> 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.
>
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).

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.
Author
20 Apr 2006 12:27 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> schrieb:
>>> 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.
>>
> 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).
>
> 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?

IMO no.

> Is "ldstr" so much slower than "ldsfld" that "String.Empty" really is
> worth all the extra typing?

IMO no.

> <advocate owner="devil" >
> Is String.Empty really so much more readible than ""?

IMO no.

However, it's true that the 'ldsfld' instruction is slightly faster than the
'ldstr' instruction.  I don't see any reason for the VB compiler not to emit
'ldsfld' + 'String.Empty' instead of 'ldstr' for "", as both are
semantically equivalent and thus no problem could arise.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
20 Apr 2006 4:49 PM
Mitchell S. Honnert
>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

Show quoteHide quote
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message
news:e27spj$gjh$1@yarrow.open.ac.uk...
> Herfried K. Wagner [MVP] wrote:
>> "cj" <cj@nospam.nospam> schrieb:
> . . .
>>> 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.
>>
> 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).
>
> 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.
Author
20 Apr 2006 6:56 PM
cj
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:
Show quoteHide quote
>> 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@o-p-e-n-.-a-c-.-u-k> wrote in message
> news:e27spj$gjh$1@yarrow.open.ac.uk...
>> Herfried K. Wagner [MVP] wrote:
>>> "cj" <cj@nospam.nospam> schrieb:
>> . . .
>>>> 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.
>>>
>> 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).
>>
>> 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.
>
>
Author
20 Apr 2006 9:17 PM
Mitchell S. Honnert
> For me, nothing shouts empty string like ""
What do these shout to you?
"''
'"'
''"

They all look like "", but they're not.  Again, this issue is rather
trivial, but it's enough to push me to use String.Empty.

> 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.
I personally don't think that VB is getting either more complex or cryptic.
Sure, it may have been difficult for VB6 developers to transition to VB.NET,
but this isn't the proper measure of the complexity of a programming
language.  I've always contended that VB.NET would be much easier than VB6
to teach a person who is completely new to programming.  VB.NET, along with
the .NET Framework, may make VB *richer*, but because of the regularization
of the language and the thought put into the design of the Framework, VB is
actually less complex, not more.

As for being cryptic, I don't think even C# people would deny that their
language of choice is cryptic.  (It's a point of pride.)  Whereas VB will
use a word or series of words, C# will use a punctuation mark or other
single-character symbol.  In other words, more cryptic.  Bringing it back to
our discussion, trying googling "" and see what you get.  Now try
"String.Empty".  The reason that you will frequently see posts to the
languages.csharp ng asking what this or that punctuation mark means is that
the person either tried to google the punctuation mark and got a zillion
result or didn't bother googling it in the first place because they knew
they'd get a zillion results.

Remember, eschew obfuscation.  :-)

- Mitchell S. Honnert


Show quoteHide quote
"cj" <cj@nospam.nospam> wrote in message
news:%23T3rhwKZGHA.1016@TK2MSFTNGP03.phx.gbl...
> 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@o-p-e-n-.-a-c-.-u-k> wrote in message
>> news:e27spj$gjh$1@yarrow.open.ac.uk...
>>> Herfried K. Wagner [MVP] wrote:
>>>> "cj" <cj@nospam.nospam> schrieb:
>>> . . .
>>>>> 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.
>>>>
>>> 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).
>>>
>>> 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.
>>
Author
21 Apr 2006 6:39 AM
Cor Ligthert [MVP]
Mitchell,

Simple question, What do you do if you have to set a single quote in a
string.

"'" you have than in my idea the same problem. Therefore I think that your
solution is strict personal. Nothing wrong with it, that is what makes VBNet
a better "language". You are not hold to one word, just like any other true
language beside AFAIK languages as Latin.

Just my thought,

Cor

Show quoteHide quote
"Mitchell S. Honnert" <n***@REMhonnertOVE.com> schreef in bericht
news:OAaKb$LZGHA.1180@TK2MSFTNGP03.phx.gbl...
>> For me, nothing shouts empty string like ""
> What do these shout to you?
> "''
> '"'
> ''"
>
> They all look like "", but they're not.  Again, this issue is rather
> trivial, but it's enough to push me to use String.Empty.
>
>> 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.
> I personally don't think that VB is getting either more complex or
> cryptic. Sure, it may have been difficult for VB6 developers to transition
> to VB.NET, but this isn't the proper measure of the complexity of a
> programming language.  I've always contended that VB.NET would be much
> easier than VB6 to teach a person who is completely new to programming.
> VB.NET, along with the .NET Framework, may make VB *richer*, but because
> of the regularization of the language and the thought put into the design
> of the Framework, VB is actually less complex, not more.
>
> As for being cryptic, I don't think even C# people would deny that their
> language of choice is cryptic.  (It's a point of pride.)  Whereas VB will
> use a word or series of words, C# will use a punctuation mark or other
> single-character symbol.  In other words, more cryptic.  Bringing it back
> to our discussion, trying googling "" and see what you get.  Now try
> "String.Empty".  The reason that you will frequently see posts to the
> languages.csharp ng asking what this or that punctuation mark means is
> that the person either tried to google the punctuation mark and got a
> zillion result or didn't bother googling it in the first place because
> they knew they'd get a zillion results.
>
> Remember, eschew obfuscation.  :-)
>
> - Mitchell S. Honnert
>
>
> "cj" <cj@nospam.nospam> wrote in message
> news:%23T3rhwKZGHA.1016@TK2MSFTNGP03.phx.gbl...
>> 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@o-p-e-n-.-a-c-.-u-k> wrote in message
>>> news:e27spj$gjh$1@yarrow.open.ac.uk...
>>>> Herfried K. Wagner [MVP] wrote:
>>>>> "cj" <cj@nospam.nospam> schrieb:
>>>> . . .
>>>>>> 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.
>>>>>
>>>> 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).
>>>>
>>>> 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.
>>>
>
Author
21 Apr 2006 2:13 PM
Mitchell S. Honnert
>Therefore I think that your solution is strict personal.
I believe that what you are saying is that the use of String.Empty is a
personal preference for me?  If so, you're exactly right.  I have some
objective justification for my use of String.Empty, but nothing so important
that it can't be reasonably overridden by personal preference.

- Mitchell S. Honnert

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:OerAN4QZGHA.3400@TK2MSFTNGP02.phx.gbl...
> Mitchell,
>
> Simple question, What do you do if you have to set a single quote in a
> string.
>
> "'" you have than in my idea the same problem. Therefore I think that your
> solution is strict personal. Nothing wrong with it, that is what makes
> VBNet a better "language". You are not hold to one word, just like any
> other true language beside AFAIK languages as Latin.
>
> Just my thought,
>
> Cor
>
> "Mitchell S. Honnert" <n***@REMhonnertOVE.com> schreef in bericht
> news:OAaKb$LZGHA.1180@TK2MSFTNGP03.phx.gbl...
>>> For me, nothing shouts empty string like ""
>> What do these shout to you?
>> "''
>> '"'
>> ''"
>>
>> They all look like "", but they're not.  Again, this issue is rather
>> trivial, but it's enough to push me to use String.Empty.
>>
>>> 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.
>> I personally don't think that VB is getting either more complex or
>> cryptic. Sure, it may have been difficult for VB6 developers to
>> transition to VB.NET, but this isn't the proper measure of the complexity
>> of a programming language.  I've always contended that VB.NET would be
>> much easier than VB6 to teach a person who is completely new to
>> programming. VB.NET, along with the .NET Framework, may make VB *richer*,
>> but because of the regularization of the language and the thought put
>> into the design of the Framework, VB is actually less complex, not more.
>>
>> As for being cryptic, I don't think even C# people would deny that their
>> language of choice is cryptic.  (It's a point of pride.)  Whereas VB will
>> use a word or series of words, C# will use a punctuation mark or other
>> single-character symbol.  In other words, more cryptic.  Bringing it back
>> to our discussion, trying googling "" and see what you get.  Now try
>> "String.Empty".  The reason that you will frequently see posts to the
>> languages.csharp ng asking what this or that punctuation mark means is
>> that the person either tried to google the punctuation mark and got a
>> zillion result or didn't bother googling it in the first place because
>> they knew they'd get a zillion results.
>>
>> Remember, eschew obfuscation.  :-)
>>
>> - Mitchell S. Honnert
>>
>>
>> "cj" <cj@nospam.nospam> wrote in message
>> news:%23T3rhwKZGHA.1016@TK2MSFTNGP03.phx.gbl...
>>> 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@o-p-e-n-.-a-c-.-u-k> wrote in message
>>>> news:e27spj$gjh$1@yarrow.open.ac.uk...
>>>>> Herfried K. Wagner [MVP] wrote:
>>>>>> "cj" <cj@nospam.nospam> schrieb:
>>>>> . . .
>>>>>>> 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.
>>>>>>
>>>>> 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).
>>>>>
>>>>> 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.
>>>>
>>
>
>
Author
21 Apr 2006 9:49 AM
Herfried K. Wagner [MVP]
"Mitchell S. Honnert" <n***@REMhonnertOVE.com> schrieb:
>> For me, nothing shouts empty string like ""
> What do these shout to you?
> "''
> '"'
> ''"
>
> They all look like "", but they're not.  Again, this issue is rather
> trivial, but it's enough to push me to use String.Empty.

Mhm...  There is a clear difference between them when shown in VS' standard
text-editor font...  I don't see such a huge problem that would cause me not
to use "" any more.

Just my 2 Euro cents...

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>