Jon Skeet said:
I find I need a nullable string more often than I need nulls of most
other types - Forms, Streams, Encodings etc. Personally, I don't find
it a problem at all that strings can be null - just like other
parameters etc, you need to check them in appropriate places if only
certain values are valid.
Of course, this is where something like Spec# comes in handy...
Well, I mostly do web applications and 99% of the strings I allocate is for
HTML output.
I think most asp.net devs are quite sick and tired of all them null pointer
exceptions you always get when fast-coding.
I also do a lot of import/export using XML. It's a nightmare. if a node is
missing on a xpath-expression you get the darn null again. It is so useless.
Of course we made our own XML-wrapper that never yeilds a null. Problem
solved ugly.
I agree theer are cases where you could find it useful for a nullable
string. But those cases are way far inbetween your regular use of strings.
For most applications, all them if-statements and util-methods gives bloated
code and lesser performance.
In Delphi, you have primitives, records, classes and strings. String being a
magic (and pretty smart) special type.
In .NET they wanted a simple system of value-types and reference-types and
had to cram the string in either two. Strings then wind up naturally as a
reference-type. But I think this was the wrong thing to do. I'd rather see
value-types, reference-types and magic-types. The simple dualistic approach
we got now is a pain in the arse.
Too bad they didn't come up with nullable types from scratch. That would
have saved the day. Then we could have string and string?. a cast between a
null string? to string would yeild "". That would have been pretty neat.
Guess it's too late for that now...
Happy Nulling
- Michael S