Re: Checking for A Blank String
- From: "Herfried K. Wagner [MVP]" <hirf-spam-me-here@xxxxxx>
- Date: Sat, 10 Mar 2007 19:50:53 +0100
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/>
.
- Follow-Ups:
- Re: Checking for A Blank String
- From: Göran Andersson
- Re: Checking for A Blank String
- From: Tom Leylan
- Re: Checking for A Blank String
- References:
- Re: Checking for A Blank String
- From: Herfried K. Wagner [MVP]
- Re: Checking for A Blank String
- From: \(O\)enone
- Re: Checking for A Blank String
- From: Göran Andersson
- Re: Checking for A Blank String
- From: Herfried K. Wagner [MVP]
- Re: Checking for A Blank String
- From: Göran Andersson
- Re: Checking for A Blank String
- From: \(O\)enone
- Re: Checking for A Blank String
- From: Göran Andersson
- Re: Checking for A Blank String
- From: Herfried K. Wagner [MVP]
- Re: Checking for A Blank String
- From: Tom Leylan
- Re: Checking for A Blank String
- Prev by Date: Re: Checking for A Blank String
- Next by Date: Re: Binary To ASCII?
- Previous by thread: Re: Checking for A Blank String
- Next by thread: Re: Checking for A Blank String
- Index(es):
Relevant Pages
|
Loading