std.path review: update

torhu no at spam.invalid
Mon Jul 18 10:51:58 PDT 2011


On 18.07.2011 16:18, Lars T. Kyllingstad wrote:
> On Mon, 18 Jul 2011 14:23:18 +0200, torhu wrote:
>>
>>  I'd like to make a case for null as the 'nothing here' value.
>>
>>  The advantage of using null is that all possible ways of testing for
>>  'nothingness' (is, ==, as a boolean condition, empty range) will work.
>>  But if you return an empty string, you can't do 'str is null', because
>>  that will be false.  With null there's just no doubt, and no way to get
>>  the test wrong.
>>
>>  As far as I can tell by the testing I've done, you can use a null string
>>  in every way that you can use an empty string, even append to it with
>>  ~=.   The distinction between null and empty strings is significant in C
>>  and Java, but in D it's not, and the tiny difference that actually
>>  exists mainly serves to confuse people.  It doesn't help that the actual
>>  differences are largely undocumented either.
>>
>>  One difference is that a statically allocated empty string is null
>>  terminated, but I think that can be safely ignored in the case of return
>>  values.
>
> True, but the question was not whether one should use null or "" for the
> "nothing here" return value of a function.  The question was whether the
> function returning null should mean something different than it returning
> "".

I meant to imply that null and empty should not be used to mean two 
different things, sorry if I didn't make myself clear.  AFAIK, none of 
the Phobos functions that take string arguments care about the 
difference.  If the length is zero, the pointer value is ignored.  In 
light of this, I don't know what different meanings null and empty would 
or should have.


More information about the Digitalmars-d mailing list