I've been working with the XMLHttpRequest object in JavaScript recently, and I couldn't help but notice that the casing of this name makes no sense. Why is 'XML' all in caps while 'Http' is not? They're both acronyms!
Surely it'd make more sense for the name to be one of the following:
- XmlHttpRequest (PascalCase, best practice for class names in JavaScript)
- xmlHttpRequest (camelCase, also common though not for classes)
- XMLHTTPRequest (caps-for-acronyms, rarely used in programming?)
I'm sure there must be some reason and I'd hate to think it's now set in stone just because no one questioned this at the time. Is there another naming convention that I'm unaware of?
2 Answers 2
Interestingly enough, Microsoft first called it IXMLHTTPRequest when it was first added to the MSXML library.
It was Mozilla that used the name XMLHttpRequest when it added the concept into Gecko, implementing the idea to mimic the MS interface. It has since become the defacto standard, tying all other implementations to Mozilla's decision.
You'd have to go spelunking in the Mozilla Bugzilla to see if you can find any reasoning for the caps change there, but I suspect that not much thought went into it and the lowercasing of the ttp part is accidental.
This is corroborated by the misspelling of the Microsoft interface in the nsIXMLHttpRequest interface definition (earliest revision in the Mozilla Mercurial repository):
Mozilla's XMLHttpRequest is modelled after Microsoft's IXMLHttpRequest object. The goal has been to make Mozilla's version match Microsoft's version as closely as possible, but there are bound to be some differences.
-
Ah I see, so it's intentional in so far as it's based on an earlier instance of the spelling. I still don't like it - but at least I can understand how it came to be. Thanks for an excellent answer.Alec– Alec2012年07月19日 09:36:04 +00:00Commented Jul 19, 2012 at 9:36
-
7Note that while XML and URL are commonly all-caps, references to lowercase http are ubiquitous in HTML. So
XMLHttpRequestmay be viewed as camel casing of the combined identifiers.hardmath– hardmath2012年07月19日 12:50:28 +00:00Commented Jul 19, 2012 at 12:50 -
2If you go all the way back to the first revision in CVS: bonsai.mozilla.org/cvsblame.cgi?file=mozilla/content/base/… It's like that. The original author was Vidur Apparao, so maybe someone can track him down (he's CTO at Agari nowadays: agari.com/team/vidur-apparao ) and ask him. Unfortunately there's nothing in bugzilla about this, back in the Netscape days they weren't great about filing bugs to track work.Ted Mielczarek– Ted Mielczarek2014年12月17日 02:26:34 +00:00Commented Dec 17, 2014 at 2:26
-
@hardmath, HTTP is not lowercase! (Use it in a sentence please?) The only time is as URL protocol which are conventionally lowercase, e.g.
http://example. But is that any different than XML which is always upper case., except when in an XML document<?xml version="1.0">?Paul Draper– Paul Draper2024年05月08日 22:55:58 +00:00Commented May 8, 2024 at 22:55
Some naming guidelines make a distinction between "short" and "long" acronyms. For instance, the coding style guide for Microsoft's .Net runtime specifies that short acronyms should be in block caps while long acronyms should only have the first letter capitalized. Their threshold for a long acronym is 3 letters, so would favor "XmlHttpRequest", however it is not unreasonable to think some people may use a similar rule with 4 characters as the threshold.
I've looked at old copies of the mozilla.org style guide, and none seem to specify anything about acronyms, but it's possible that either an older Netscape guide did, or that the developer was applying a rule he'd picked up elsewhere.
Explore related questions
See similar questions with these tags.
HttpURLConnection.HTTP_REFERERheader...