This syntax regarding null checking baffles me

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Jan 7 22:42:40 UTC 2021


On Thursday, January 7, 2021 8:55:52 AM MST Max Haughton via Digitalmars-d 
wrote:
> On Thursday, 7 January 2021 at 15:37:44 UTC, Dukc wrote:
> > On Thursday, 7 January 2021 at 04:57:55 UTC, 12345swordy wrote:
> >> if (c !is null) Why?????
> >>
> >> Would it be simpler to type
> >>
> >> if (c is not null)
> >
> > Saves 3 character per use, I guess. And keeps one operator in
> > one keyword. Matter of taste, and whoever designed this
> > obviously had to pick something.
>
> I don't think not is reserved anywhere else so it would mean
> adding a new terminal to the grammar too, and d already has a lot.

That and using ! is more consistent with what the C family of languages
typically does. C-derived languages don't typically try to make sentences
like "is not" would do. Having is and !is is also more consistent with ==
and !=. "is not" wouldn't really fit the rest of the language.

Ultimately, how you feel about it probably comes down primarily to taste and
what you're used to, but I'm sure that Walter would have wanted to avoid
adding an extra keyword just for this. So, I would have expected him to
reject "is not" on that basis, but my guess is that he never even considered
it. Once he'd decided on is, !is was probably simply the obvious choice
given the other operators that D has and Walter's C/C++ background.

- Jonathan M Davis





More information about the Digitalmars-d mailing list