A
academic
Sounds like the last word to me
Thanks
Thanks
Herfried K. Wagner said:I believe it strongly depends on the situation. IMO it's not a good idea
to propose "initialize strings with an empty string" as a general rule.
However, it still may make sense in some cases.
academic said:Sounds like the last word to me
academic said:Sounds like the last word to me
Thanks
CMM said:What is the benefit of an uninitialized string? Why is it not a "good
idea?" I mean...
Questions:
1) Are there situations where <Nothing> actually *means* something in
your code and your algorithms other than <Empty>?
2) Or are you just relying on VB's intrinsic functions (Len, Left, Mid,
etc) and "coercion" to safely deal with the string?
3) Is it for performance or memory reasons?
m.posseth said:it is considered good coding practice to initialize string values
with a empty string value
dim x as string =""
or
dim x as string=string.empty
academic said:Why isn't it a good practice?
1) Nothing = Nothing. You're right in assuming that nothing is allocated.
A string initializes to Nothing by default. This leads to bugs...
m.posseth said:well i am confused now
Francesco and Giuseppe are verry clear in there book, that both are
even good
"" and string.empty
however from a developers perspective i would use "" as it is
faster to write as string.empty
untill i heard from CMM that the IL produces different code for
string.empty or ""
strange .....
CMM said:So why do *you* treat them as if they were?
You really have to justify why you say "...it's not a good idea to
'initialize strings with an empty string' as a general rule." Why isn't it
a good idea? I mean, 99% of the time, I expect my strings to be Empty not
Nothing.
Why not declare them as Empty rather than have VB *coerce* the value???
Cor Ligthert said:I did not read the whole message just curious where CMM and you where
disussing about.
However I would never compare a database with computer memory.
In a database means a Null field, really nothing which means than as well
no disk space.
CMM said:While the IL does produce different code, I don't think it very much
matters in terms of performance in most situations.
Cor Ligthert said:A "" pases a string with one charachter ""
It means no value, although what constraints it has to fullfil if there is a'NULL' in a database means "unknown value". This behavior can be
replicated inside VB.NET in different ways ('Nothing' references,
'Nullable(Of String)').
Exact I typed it, saw what bs I wrote, wanted to correct it, could notA "" pases a string with one charachter ""
I think you wanted to type "with zero characters" as strings in VB are not
null-terminated.
CMM said:The performance differences aren't really noticeable but there IS a
difference!
In the IL:
("") compiles to ldstr "" --- Which means, LoadString, Look it up ("it"
being the char array) in the string table, create a new reference to the
existing string.