XMLHttpRequest function. I don’t normally spend a great deal of time doing
web development, but as part of a project at work I’ve been using the Google
Maps API to develop a web application to visualise some mapping data.
Something started to bug me; it struck me that the “XMLHttpRequest” function is named pretty badly. Let’s split the name into chunks and look at each part.
This first part of the function name is kind of… wrong. When one sends an
async request from the browser, the request can be any type of document. The
response could be XML, but the response could equally be JSON, an integer, a
binary structure, an image, and so on. The
XML in the name is entirely
irrelevant to the logic of the function!
is not relevant in the name! This has been realised to some extent; the term
asynchronous interactions with JSON, but this term hasn’t really enjoyed
widespread usage - most people still refer to async requests as “AJAX”.
My gripe with this isn’t so much that
HTTP is in the function name - the
problem is with how it is capitalised. Why, oh why, if the acronym
fully capitalised in the first part of the function name, do you then go on to
butcher the capitalisation of
HTTP and treat it as if it were some half-baked
The function should either be named with:
- a camel-cased
XMLis even necessary in the first place, that is - hint: it isn’t)
- a fully capitalised “HTTP”, or
- no capitalisation at all!
I don’t actually know if
HTTP is actually necessary in the name either.
XMLHttpRequest is a web technology, the
HTTP in the name
seems fairly redundant.
Hooray! The only sensible part of the function name! No problems here.
So, what would I do instead?
Personally, I’d consider some alternative names - maybe one of these:
XMLHTTPRequest- A bit of a pain to type, but at least capitalisation is consistent. Also wrong.
XmlHttpRequest- Doesn’t look as nice, but easier to type - and still wrong.
HttpRequest- Great! Clear and unambiguous, not misleading. Consistent capitalisation too!
Request- Clear, unambiguous, and super concise. (Yay, less typing!)
My personal favourite alternative would be
- it isn’t misleading, and there’s no unnecessary waffle in the name
- it’s easier to remember and quicker to type
- it’s shorter, so there will be fewer bytes in JS files (faster load times!)
- there will be less murderous rage from me, every time I have to type it.
That was stressful, I’d better leave it there.