- From: Tab Atkins Jr. <jackalmage@gmail.com>
- Date: Tue, 20 Dec 2011 14:54:07 -0800
- To: Harald Alvestrand <harald@alvestrand.no>
- Cc: public-webrtc@w3.org, hta@google.com
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. 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. ~TJ
Received on Tuesday, 20 December 2011 22:55:06 UTC