W3C home > Mailing lists > Public > public-media-annotation@w3.org > October 2009

afterthought about the API

From: Pierre-Antoine <pierre-antoine.champin@liris.cnrs.fr>
Date: Tue, 20 Oct 2009 15:03:52 +0200
Message-ID: <4ADDB538.6010004@liris.cnrs.fr>
To: "public-media-annotation@w3.org" <public-media-annotation@w3.org>
Hi all,

last week, we discussed about return values; I asked why use exception 
rather than null values when no value is available.

Chris's answer was that an exception can carry the *reason* why there 
was no value. I guess the rationale is that reasons could be sth like:
  - property has no value in source
  - property is not specified in source
  - property is not supported by source format
  - value of the property could not be converted to the return datatype

I think this argument makes sense: it is useful to know the reason why 
there is no value.

However, I keep thinking that

   c = md.creator;
   if (c != null) {

is much easier to write and read than

   try {
     c = md.creator;
   catch (err) {
     if (err.name != "NoValue") { throw err; }

so I think (again) that for easing the simple cases, we should strick to 
a null value.

I guess the NoValue.message feature could be replace by somethinh like a 
getDiagnoss() method retrieving the reason for the absence of value. For 
example :

   c = md.creator;
   if (c == null) {
   } else {

Received on Tuesday, 20 October 2009 13:04:29 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:24:37 UTC