W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2010

Re: [webIDL] nullable interface types

From: Dimitry Golubovsky <golubovsky@gmail.com>
Date: Thu, 28 Jan 2010 14:19:37 -0500
Message-ID: <bcba51a1001281119q4bb353d2nc7f06e9c25401e1a@mail.gmail.com>
To: Dominique Hazael-Massieux <dom@w3.org>
Cc: public-script-coord@w3.org

Deep IMHO, from the stronger typing standpoint, nullable types are
good. They are like Maybe in Haskell where a value that can contain
"failure" (null) is distinct from value that cannot fail. One has to
perform some action to convert the former to the latter, reasonably
providing a substitute for null (or avoiding some action if the value
happens to be null). Then, if an operation/method accepts a value that
is ensured at the type level not to be null, multiple checks for null
are not necessary: the code becomes simpler.

Dominique Hazael-Massieux <dom@w3.org> wrote:

> Arguably, this is something that can be fixed in the Contacts API, but
> before submitting the bug report, I was wondering what was the rationale
> for forbidding the use of "?" on interface types; in particular:
> • why interface types include the null value?

They should not. An operation that possibly fails has to return
nullable type e. g. getElementById could be

Element?  getElementById(in DOMString elementId);

declaring that it may return no element (fail).

Dimitry Golubovsky

Anywhere on the Web
Received on Thursday, 28 January 2010 19:20:12 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:02 UTC