Re: [WebIDL] enum

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