Re: Checking for A Blank String



Tom,

"Tom Leylan" <tleylan@xxxxxxxxxx> schrieb:
Let me ask others to consider that "time-to-type" shouldn't be a major consideration when developing applications. Yes if you are in a typing contest but no if you are trying to write robust software for a living.

Why should using 'Len' be "less robust" (whatever that means)? The behavior of 'Len' is well-known to anybody using BASIC for years and it's documented too. Additionally, 'Len' is a 1st class citizen in VB. 'Len' feels much more natural in VB than the "low-level" method 'IsNullOrEmpty', especially because the term/keyword 'null' is not used in VB.

The reason one would choose a "complicated" solution if we honestly consider typing IsNullOrEmpty complicated is to gain plainness and transparency. There is nothing about a function named Len() which suggests that it is testing for Null values and code which disguises what is happening is among the worst kinds of code.

Well, that's the common behavior of almost all functions contained in the 'Strings' module.

Trying to avoid the use of VB's intrinsic functions is like trying to use a screwdriver to screw in a nail although there is a hammer in the toolbox for the reason that "a screwdriver is a more professional tool than a hammer."

Using "plain", "simple", "obvious" and "easy-to-understand" as criteria let each developer ask him/herself what does IsNullOrEmpty() test for and what is it's return value. If you find it hard to figure out based upon it's name then by all means choose Len().

I doubt that any VB developer using the full repertoire available in the VB "toolbox" will have problems to understand what 'Len' is doing. I also believe that I can expect such knowledge from someone claming to know VB.

I'd also be interested to know which "certain scenarios" throw exceptions I didn't see it mentioned in the docs. Which exception does it throw?

Read on here:

DANGER ! String.IsNullOrEmpty can lead to runtime Null exceptions !!
<URL:http://msmvps.com/blogs/bill/archive/2006/04/04/89234.aspx>

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

.



Relevant Pages

  • Re: usercontrol with readonly property that can be set at design t
    ... time via the designer, the exception worked wonderfully. ... If the developer tried to set the value elsewhere in code, ... Public Property WizardPageNumber() As Integer ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Advantage over VB ?
    ... sensitivity a slight annoyance, but quickly adapted. ... are a multi-language .NET developer you would probably favor the inverse. ... world that VB.NET is a "toy" language and/or that it is not for "serious" ... In VB.NET you ahve to catch the exception to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: NullPointerException
    ... > are insufficient to prevent NullPointerExceptions. ... The API user wouldn't know or care. ... include the types of exception something throws. ... but I think that where the developer might neglect to read ...
    (comp.lang.java.programmer)
  • Re: ASP.NET Exception Handling
    ... You can introduce a hidden input control for passing error messages from ... server to client. ... Software Developer & Consultant ... I would like to ask you an opinion of ASP.NET exception handling ...
    (microsoft.public.dotnet.framework.aspnet)
  • Soap problem with p2p provider not found
    ... I get an exception saying something like Provider not found for this ... he gets the same error message I get. ... The developer who developed the example re-verified that his code ... worked using the same jars which are not working for me. ...
    (comp.lang.java.programmer)

Loading