On Saturday, 8 July 2017 at 23:12:15 UTC, Jonathan M Davis wrote:
On Saturday, July 8, 2017 5:16:51 PM MDT kdevel via Digitalmars-d-learn wrote:

[...]

IMHO, if you want to check for empty, then you should use the empty property or check length directly, since those are clear about your intent, whereas with

My starting point wasn't to check for emptiness but the question if I can use the additional two states (string var is null or !is null) of a string variable to indicate if a value is absent.

If you understand all of this, it is perfectly possible to write code which treats null arrays as distinct from empty arrays. However, it's _very_ easy to get into a situation where you have an empty array rather than a null one.

My case was: I get a null one from

   "".decodeComponent

where I did not expect it. (cf. my corrected example in my post "13 hours ago", i.e Saturday, 08 July 2017, 23:12:20 +00:00).

Pretty much as soon as you do anything to a null array other than pass it around or compare it, trusting that it's still null can get error-prone.

It's the other way round. I was assuming that it is still not null (My example in my first post was wrong).

[...]

Personally, I think that it can make sense to have a function explicitly return null to indicate something, but beyond that, I'd actually consider using std.typecons.Nullable to make the whole thing clear, even if it is a bit dumb to have to wrap a nullable type in a Nullable to treat it as null.

You hit the nail on the head.

Stefan

Reply via email to