Re: Remove numeric constants from WebRTC

On 12/20/2011 11:54 PM, Tab Atkins Jr. wrote:
> On Sat, Dec 17, 2011 at 1:30 AM, Harald Alvestrand<harald@alvestrand.no>  wrote:
>> On 12/16/2011 11:44 PM, Tab Atkins Jr. wrote:
>>> WebRTC currently defines numeric constants on a few of its interfaces
>>> (specifically, MediaStream and PeerConnection).  These are verboten in new
>>> JS APIs, as now noted in the WebIDL spec
>>> <http://dev.w3.org/2006/webapi/WebIDL/#idl-constants>.  Instead, the
>>> appropriate properties should simply contain strings.
>> Tab,
>>
>> can you point to the main arguments behind this decision, and where the
>> consensus was recorded?
>> As someone who comes from different programming languages, the decision to
>> move from a mechanism that makes verification and misspelling difficult
>> because of Javascript's strange language rules (misspelled variables are
>> created automagically, but it's easy for a programmer to see the intent) to
>> making it impossible (because a string is not constrained at all, and there
>> are no syntactical constructs for telling the programmer about the intended
>> permitted values) seems to me like a bizarre decision.
>>
>> The justifications don't seem to have made it into the WebIDL spec.
>>
>> I note that the change was added to the WebIDL specification after the Last
>> Call, and are still only in the editor's version, not the stable version, so
>> presumably it occured as a result of Last Call discussion.
> Yes, this change occurred as a part of LC discussion.  Quite a bit of
> things are being tweaked or fixed as a result of LC. ^_^
>
> There was no official resolution about this, as it's a style/design
> thing, not an actual change in the spec.
So (formalistically) how do observers know that this was the conclusion?
I'd be happy to be pointed at an email in the archive of the WG saying 
"as WG chair, I conclude that this discussion resulted in....."
>    However, I can quickly list
> the reasons why the decision was made:
>
> 1. Constants are more verbose than strings of the same name, as you
> must repeat the name of the interface as well.
> 2. Numeric constants can be passed in two ways to a function, and the
> bad way (as integers) is much shorter, and thus often more attractive.
> 3. Constants don't buy you anything over strings - strings can be interned, etc.
>
> In general, experience shows that people usually forgo the named
> constant and just use the numbers instead, which is the worst outcome
> possible, as it makes the code very difficult to read and understand.
> Since using strings instead has no real downsides, and avoids all of
> the downsides of numeric constants, they are now the preferred way to
> handle this sort of thing.
I see the logic. The lack of enums in the language hurts again.
I still miss the ability to document (for programmers) in WebIDL what 
the permitted values are; is there a comment convention for doing that 
at the moment?

                 Harald

Received on Wednesday, 21 December 2011 03:49:04 UTC