Why JavaScript I/O is so awkward

I remember well, the first moment I found out that you couldn’t just make an HTTP request from a bit of JavaScript code in the browser.

The ideal

  • It’s something I had become accustomed to as being a simple procedure call:
  • That line of code returns the XML contents of my feed, in UserTalk, the language built into Frontier.
  • The interpreter makes the procedure call, and when it returns, the variable xmltext contains the contents of the feed. When hello is called, it can depend on xmltext having been set and processed.
  • It never occurred to me that any language could work any other way.

How it works in JavaScript

  • The equivalent code in JavaScript looks something like this:
  • Looks pretty similar, until you realize that the hello call will execute before xmltext is processed. How do you wait for the text to be read? Good question! There isn’t really a good answer.
  • This means that some things are impossibly difficult to do in the browser that could be done in another language that imho worked more reasonably.

Why this is surprising

  • When you think about it, the whole mission of the browser is to read data over HTTP in multiple simultaneous threads! That this isn’t trivially simple in the scripting language for the web, JavaScript, is costing us an enormous amount of time and money.
  • Unless I’m missing something obvious, which is why I’m writing this post (but I don’t think I am).

About Dave Winer

Dave Winer, 54, pioneered the development of weblogs, syndication (RSS), podcasting, outlining, and web content management software; former contributing editor at Wired Magazine, research fellow at Harvard Law School, entrepreneur, and investor in web media companies. A native New Yorker, he received a Master's in Computer Science from the University of Wisconsin, a Bachelor's in Mathematics from Tulane University and currently lives in Berkeley, California.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s