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. 14 2308
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
"cj" <cj@nospam.nospam> schreef in bericht
news:uM**************@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.
"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/>
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/...ingLength.html
--
======================
Clive Dixon
Digita Ltd. ( www.digita.com)
"cj" <cj@nospam.nospam> wrote in message
news:uM**************@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.
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:uM**************@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.
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: 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:uM**************@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.
"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/>
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.
"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/>
>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:e2**********@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.
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:e2**********@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.
> 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:%2****************@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:e2**********@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.
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" <ne**@REMhonnertOVE.com> schreef in bericht
news:OA**************@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:%2****************@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:e2**********@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.
"Mitchell S. Honnert" <ne**@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/>
>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
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oe**************@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" <ne**@REMhonnertOVE.com> schreef in bericht news:OA**************@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:%2****************@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:e2**********@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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Cyrus D. |
last post by:
Hi guys,
What's the best way to test for an empty form value ? I am doing it like
this now:
$test = $_POST;
if(strlen($test) < 1)
// it is empty !
Maybe I can just go:
|
by: Mikko Ohtamaa |
last post by:
From XML specification:
The
representation of an empty element is either a start-tag immediately
followed by an end-tag, or an empty-element tag.
(This means that <foo></foo> is equal to...
|
by: Ramiro Barbosa, Jr. |
last post by:
All,
In regards to the call below, I was wondering why is it that the
'szMessage' receiving buffer results in an empty one, but by printing
'ret' it indicates the number of bytes I am indeed...
|
by: Stefan Weiss |
last post by:
Hi.
(this is somewhat similar to yesterday's thread about empty links)
I noticed that Tidy issues warnings whenever it encounters empty
tags, and strips those tags if cleanup was requested....
|
by: Andreas Palm |
last post by:
I have a dataset that has DBNull in certain columns, now when I write
out this one to XML, I only get the columns as elements that do have
data in it. However I do need also the empty colums as...
|
by: Dan Bass |
last post by:
which one do you use and why?
MyString == null || MyString == ""
vs
MyString == null || MyString.Length == 0
|
by: Søren M. Olesen |
last post by:
Hi
Can someone tell me how to implement something similar to String.Empty ??
Given a class called myValue
Public class myValue
private id as integer
private value as string
end class
|
by: Bob Stearns |
last post by:
I thought that the given expression was always TRUE if "not_there"
wasn't among the keys (or subscripts if you will) of $_SESSION.
Below find a dump of $_SESSION, a small snippet of code and the...
|
by: anonieko |
last post by:
In the past I always used "" everywhere for empty string in my code
without a problem.
Now, do you think I should use String.Empty instead of "" (at all
times) ?
Let me know your thoughts.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |