Wednesday, September 24, 2014

Commas and semicolons

Typical in HTTP/MIME standards is that items in a list are separated by a comma. That makes sense. But then when we want to add some attributes to those list items,  SOMEONE decided that it would be a good idea to use a semicolon, like this:

application/json;q=0.9, application/javascript;q=0.5, text/javascript;q=0.5, text/plain;q=0.2, */*;q=0.1


Which is very unnatural, because according to regular written syntax, the semicolons separate parts that have commas in them, not the other way around.

Since the previous syntax already used comma to separate items, it wouldn't make sense to change it because that would break existing software (not that existing software would have been able to match text/javascript;q=0.5 to a file type if it was using an exact match anyway).

It would have been better to use a different attribute separator though. Maybe pipe | or question mark ? would have been fine, or maybe a colon : which of course is completely different than a semicolon.

A colon would be very natural because colons are used to separate a sentence or list which clarifies the first sentence. For example "I like natural colors: blue, green, and brown".  Similarly, the item attributes clarify the item itself.  So this could have been:

application/json:q=0.9, application/javascript:q=0.5, text/javascript:q=0.5, text/plain:q=0.2, */*:q=0.1