W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2009

Re: [WebIDL] enum

From: Ian Hickson <ian@hixie.ch>
Date: Tue, 24 Nov 2009 12:32:38 +0000 (UTC)
To: Marcin Hanclik <Marcin.Hanclik@access-company.com>
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <Pine.LNX.4.62.0911241230430.9450@hixie.dreamhostps.com>
On Mon, 16 Nov 2009, Marcin Hanclik wrote:
> 
> To facilitate the comprehension of the interfaces specified in WebIDL, I think we need to have some way of specifying enumerated values.
> At present we define constants and associate them with the attributes in the prose.
> E.g. in HTML5 we have:
> 
>   const unsigned short NETWORK_EMPTY = 0;
>   const unsigned short NETWORK_IDLE = 1;
>   const unsigned short NETWORK_LOADING = 2;
>   const unsigned short NETWORK_NO_SOURCE = 3;
>   readonly attribute unsigned short networkState;
> 
> media . networkState
> Returns the current state of network activity for the element, from the codes in the list below.
> 
> To ease the process of comprehension of the interfaces, we could have e.g.
>   [EnumFor=networkState]
>   const unsigned short NETWORK_EMPTY = 0;
>   [EnumFor=networkState]
>   const unsigned short NETWORK_IDLE = 1;
>   [EnumFor=networkState]
>   const unsigned short NETWORK_LOADING = 2;
>   [EnumFor=networkState]
>   const unsigned short NETWORK_NO_SOURCE = 3;
> 
>   readonly attribute unsigned short networkState;
> 
> Alternatively WebIDL could have the "enum" keyword with some specific syntax.
> The realization of this functionality does not, however, matter as much as the need to have it specified.

Purely from a human-readability perspective, I find the current terse text 
with the constant immediately before the attribute, possibly annotated 
with a comment, to be clearer than having [EnumFor=...] before each 
constant. The latter is a lot harder to read, at least as written above.

I'd be even happier to have a real enum, though, so that type-checked 
languages could get real type checking there. It would have to translate 
to constants in JS of course.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Tuesday, 24 November 2009 12:33:14 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:02 UTC