Re: Is there a difference between passing "" and passing Nothing to a Windows API ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



helps simplifying code. BTW: I consider the rule "always assign an empty
string to string variables" lazy because it prevents the developer from
seeing potential problems.

I don't disagree.... my rule isn't to always initialize a string to Empty.
It's to always initialize it to something when I declare it. I try to
declare objects when I need them. You wouldn't see a bunch of Dim's that
don't initialize anything at the top my methods. That's VB.Classic
mentality. VB.NET's Dim is a whole new creature.

Anyhow, please describe "potential problems?" Like what? Give an example.

--
-C. Moya
www.cmoya.com
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@xxxxxx> wrote in message
news:OngtH9OMGHA.3276@xxxxxxxxxxxxxxxxxxxxxxx
"CMM" <cmm@xxxxxxxxxx> schrieb:
I won't trade correctness for simplicity. Assigning "" to strings by
default, just to avoid NullReferenceExceptions, feels like a hack that
will just hide the actual problem.

Using VB's type emptystring type coercion is more of a hack. The actual
problem is that a string should mean something unless you really need it
not to. You don't have to initialize it to "" or String.Empty. You can
initialize it when you NEED it as so: Dim s As String = SomeMethod().
What's wrong with that?
... AND even better.... declare it inside blocks (If, Loops, etc) so it
goes out of scope at the end of the block. Man, this is just programming
101.

If VB developer's are still putting dozens of Dim's at the top of their
methods, boy, that doesn't bode well for the future of this platform. Dim
in VB.NET is not the same ol' VB.Classic Dim. They're missing out on the
whole point.

Exceptions can be good things if
they help you find errors during development, suppressing them is
taking the easy way out.

Initializing string is not suppressing an exception. Using Len(str)
insetad of str.Length *IS* suppressing it.

I use 'Len' et al. to /intentionally/ suppress the exceptions if this is
semantically correct (samples given in previous posts).

Fact is, pretty much the entire programming world has settled on the
notion that this is good practice. In C++ it's practically a law. In C#
it's just a darn good practice. It's only in VB where developers feel
free to be super-lazy and write horribly and hard to maintain code if
they so wished where this seems to be tolerated.

In VB.NET people write 'If Len(s) > 0 Then' instead of 'if (s != null &&
s.Length > 0)' for example. I don't think this is a sign of laziness,
instead I consider it an important high-level programming feature which
helps simplifying code. BTW: I consider the rule "always assign an empty
string to string variables" lazy because it prevents the developer from
seeing potential problems.

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


.



Relevant Pages

  • Re: UserControl und ShouldSerializeXXXX - Problem
    ... Public Property Developer as String ... Immer noch das gleiche Verhalten (Das NewUserControl ... Der Reset Befehl im Property Editor stellt den Standardwert ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Multivalue fields
    ... multivalued I have to change database design. ... Are there any new (string handling) functions in VB that will allow ... I am a long time pick developer, and I also a access developer ... In fact today the reason why developers are so crazy about xml is ...
    (microsoft.public.access.formscoding)
  • Re: Multivalue fields
    ... actually I am implementing a report for Access database. ... multivalued I have to change database design. ... Are there any new (string handling) functions in VB that will allow ... I am a long time pick developer, and I also a access developer ...
    (microsoft.public.access.formscoding)
  • Re: Multivalue fields
    ... Are there any new (string handling) functions in VB that will allow ... I am a long time pick developer, and I also a access developer ... In fact today the reason why developers are so crazy about xml is ... As you can see the above is a very poor, and un-normalized design. ...
    (microsoft.public.access.formscoding)
  • Re: Multivalue fields
    ... Are there any new (string handling) functions in VB that will allow ... I am a long time pick developer, and I also a access developer ... In fact today the reason why developers are so crazy about xml is this exact ... As you can see the above is a very poor, and un-normalized design. ...
    (microsoft.public.access.formscoding)