I’m having a perfectly reasonable day, improved slightly by the amount of Tina Turner I had been listening to. I’m working on an application that captures interesting conversations from Twitter, with the intention of seeding it with a great discussion between Uncle Bob and Dan North from last week.
The said conversation is withering away in Twitter’s archive and I’m hoping to complete this application swiftly before parts of the conversation become inaccessible to the API. I’m actually in the process of finishing the last bit that allows you to remove tweets from the final conversation.
In order to remove individual tweets, the full list is sent down to the client in an AJAX response. Each tweet is rendered in a <div> and has a new attribute that holds the tweet ID.
Let’s emulate the situation to demonstrate the problem:
Starting from the top, we have an object called data which has a field called id. The value of id is the numeric ID of a tweet, which we’ll be adding to the <div>. The addAttribute method finds the <div> and sets the id attribute to the value from the object.
Let’s run it and see what happens. Before we click the link, the DOM looks like:
As expected, we have our <div> and its id is still set to ‘element’. Now let’s click the link and cause the addAttribute to run. Here’s the DOM afterwards:
While being wholly entertaining, and the very good trick not withstanding, I’d like to keep my hair for a few more years. After looking into the problem, it turns out that I was (until now) blissfully unaware that:
Integers are considered reliable (numbers without a period or exponent notation) to 15 digits (9e15). Floating point numbers are considered only as reliable as possible and no more!
Ah, 15 digits – that’s how it’s done.