Thanks Heather, and thanks Gary for the implementation of
CmdUtils.parserVersion in 0.5. :)
There's a few reasons we decided to go the CmdUtils.parserVersion
route. The other solution we considered was requiring the <LINK REL>
tag on the HTML page to specify the version of the parser a feed was
written for, e.g.:
<LINK REL="commands" VERSION="1" HREF="foo-parser1.js"/>
<LINK REL="commands" VERSION="2" HREF="foo-parser2.js"/>
These are the reasons we didn't go the above route:
* Because Ubiquity doesn't currently support modules or any other
kind of code-sharing system, requiring command authors to provide
completely separate feeds for different parser versions would probably
require them to copy-and-paste common code between the two feeds,
which violates DRY [1].
* There's currently a bug in Ubiquity whereby after subscribing to a
command feed, Ubiquity never checks the HTML page that contains the
<LINK REL> tag again; it only checks the .js file pointed to by the
<LINK REL> tag for updates. This bug, in addition to Ubiquity's
general architecture surrounding command feeds, means that actually
implementing the VERSION attribute would require a lot of
implementation effort to work smoothly.
* By default, github and other services that host command feeds
would have to change their behavior if we went the VERSION route.
* Python's standard library uses top-level "if" statements that
examine static conditions that won't change throughout the process
lifetime (e.g., the host OS) to define functions differently depending
on the conditions. Actually changing the parser version in ubiquity
requires a restart, so examining CmdUtils.parserVersion satisfies the
same kind of criteria. In other words, although it's not super-
elegant, it's something that's done in lots of production code out
there and there's nothing really "wrong" with it.
* The "VERSION" attribute isn't valid HTML. Firefox would be able
to read it and work with it, but it'd interfere with folks who run
their code through HTML validators and such. We also considered using
the "REV" attribute, which we thought would be short for "revision",
but that's actually not what it's intended to be used for in the HTML
specificaiton.
* To respond to Timofei's concern, the Herd will be able to figure
out which feeds are parser1 vs. parser2 using the
CmdUtils.parserVersion method. This is because, in order to figure
out what commands a feed has, the Herd actually executes the feed in a
restricted sandbox environment. Figuring out what commands a hybrid
feed provides to parser 1 and parser 2 will just involve evaluating
the code twice: once with CmdUtils.parserVersion set to 1, and again
with CmdUtils.parserVersion set to 2.
I hope this clarifies things for everyone, let us know if you have any
other questions though! :)
- Atul
[1]
http://en.wikipedia.org/wiki/Don%27t_repeat_yourself