W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2012

[IndexedDB] Numeric constants vs enumerated strings

From: Odin Hørthe Omdal <odinho@opera.com>
Date: Wed, 22 Feb 2012 13:57:36 +0100
To: "public-webapps@w3.org" <public-webapps@w3.org>
Message-ID: <op.v92zma2e49xobu@odinho.eng.oslo.osa>
I propose that we change the numeric constants to enumerated strings in  
the IndexedDB spec.

Reasoning is echoing the reasoning that came up for WebRTC:
<http://lists.w3.org/Archives/Public/public-script-coord/2012JanMar/0166.html>

I'll just shamelessy quote Tobie Langel  
<http://lists.w3.org/Archives/Public/public-script-coord/2012JanMar/0168.html>:

> Anne van Kesteren saying:
>> Unless there are strong ties to certain legacy APIs I would suggest  
>> using
>> strings. They are easier for developers to author, easier for developers
>> to maintain, easier in the future to extend, and have practically no
>> drawbacks.
>
>> I second that. Authors barely ever used the defined constants (for good
>> reason, some implementations were missing them) preferring to use  
>> integers
>> directly.
>>
>> Instead of seeing the verbose but descriptive:
>>
>>     if (node.nodeType == Node.ELEMENT_NODE) { ... }
>>
>> one came across the following more often than not:
>>
>>     if (node.nodeType == 1) { ... }
>>
>> to which:
>>     if (node.nodeType ==  "element") { ... }
>>
>> should be preferred.
>>
>> Constants would only have practical benefits over strings if they were
>> defined in the global scope, as in:
>>
>>     if (node.nodeType == NODE_ELEMENT_NODE) { ... }
>>
>> as typos would be caught early on (undeclared variables throw
>> ReferenceErrors).


So. What do you think? :-)
>
-- 
Odin Hørthe Omdal · Core QA, Opera Software · http://opera.com /
Received on Wednesday, 22 February 2012 12:58:11 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:50 GMT