- From: <bugzilla@jessica.w3.org>
- Date: Tue, 22 Nov 2011 01:47:50 +0000
- To: public-script-coord@w3.org
http://www.w3.org/Bugs/Public/show_bug.cgi?id=14878 --- Comment #9 from Aryeh Gregor <ayg@aryeh.name> 2011-11-22 01:47:48 UTC --- (In reply to comment #3) > (In reply to comment #0) > > You always want to use string literals instead. > > Is this referring to string literals assigned to const properties, or are you > simply saying that const was a bad idea, and in general shouldn't be used > anymore in future APIs? Specifically, a number of APIs use numeric constants instead of string literals. This is the right way to do things in C, but it's wrong for JavaScript. It's much longer to type, because you need to qualify everything -- like Node.ELEMENT_NODE instead of "element". On the other hand, in JS there are no advantages. In C people do it because they want to optimize their data structures and using a char** or such when you could use a char is insane, but in JS it's much more natural to just use strings or objects or such. > There are certainly some advantages to having numerical constants, especially > for APIs that can have overlapping state (like compareDocumentPosition, or > mouseevent.buttons) and use a number as a bit mask. Bit arithmetic is unfamiliar to the average casual scripter, although of course professional programmers should be familiar with it. It would be much easier for authors if compareDocumentPosition returned a dictionary: if (node1.compareDocumentPosition(node2) & Node.DOCUMENT_POSITION_PRECEDING) vs. if (node1.compareDocumentPosition(node2).preceding) (Although really .precedes() would be best; we already have contains().) MouseEvent.buttons would be better as a dictionary too. Again, it's the difference between e.buttons.right vs. e.buttons & 2 (DOM 3 Events apparently doesn't even define numeric constants here? o_O). > I think this "problem" might be better solved by some WebIDL recommended best > practices for const, rather than flagging all const properties as "legacy" (do > not use). That's only the case if there are any cases people can come up with where we should actually be using const. If not, renaming to legacyconst is a good idea to hammer home the point. We have too many new APIs that are making the same mistakes as old ones -- we should really be learning from them, and WebIDL is one of the few things that web spec writers are almost certainly going to have to use. -- Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
Received on Tuesday, 22 November 2011 01:48:02 UTC