Everything old is new again

I was very recently asked to apply some updates to a project that I had last touched back in June 29th, 2012 (the project’s original start was May 7th of 2012). It has been running happily ever since. But as all things, there was a request to add a new feature to satisfy customers.

However many things have changed in Dart since that script was first deployed. Significant library and language changes. Looking at the source I immediately realised that I would need to rewrite the application from scratch based on the old source code rather than simply trying to update the source directly. Since the script was running fine in the past there had never been a need to continually apply updates as they occurred in the language or libraries. I just left it run.

A day and a half later or so, I have reached parity with the old sources and am ready to start adding the new functionality. I decided before doing that I would document some of the changes to the source that I encountered with this project. Please note that this is a very small script by most reasonable standards and it does not do anything very fancy. The change I document will in no way be all inclusive to any updates that others may do, but only reflects the items I ran into personally on this one projects. Additionally, the project itself is not an open source project but rather something to address a specific need for the company, as such I cannot provide specific examples or source, but I can provide the gist of things.

No packages!
So the first thing I noticed, at least reflecting back on it now, is that there was no packages. No Package layout conventions, no pubspec.yaml file, nothing. Now normally you wouldn’t have those included anyways in a deployed application, however I could also see there the code was commented out from using the Google Code hosted dart.js file. I downloaded a local copy of dart.js around February of this year for the project.
Dart.js filesize
The dart.js file which was used in the project (as mentioned, a copy from around February) was around 8.2KB in size. The current one provided by the Browser package weighs in at 1.5KB. Not a major factor with the old version but still an interesting comparison to see.
Library, Import and Source
First thing that I noticed when opening the original project was the #library('myProject'); declarations. Followed of course by #import('dart:html'); Now of course, gone are the hash signs, gone are the strings for library definitions, and of course the #source() tags are gone altogether, replaced with the part and part of declarations.
$dom_xxxx methods and properties
Another big item that popped out at me as I looked through my original sources, were the calls to the underlying dart:dom library. In particular one property I had to make use of was $dom_scrollTop as it’s equivalent wasn’t yet available in dart:html directly.
window.setTimeout()
At the time I wrote the original code, the Timer class wasn’t yet completed, and was primarily used for server-side timers. On the client side it was still really using the window.setTimeout and window.setInterval. Timers and Futures provide a much nicer way of delaying things now.
Durations!
Speaking of the Timeouts, all those calls in my original code were based on number of milliseconds to call the timeout. Now we have the Duration class to the rescue. Duration’s constructor with optional parameters makes life easy.
XMLHttpRequest
In particular, using the XMLHttpRequest.get constructor, was prevalent throughout the old code. This constructor takes a URL and a callback which will receive the completed XMLHttpRequest object. The current HttpRequest class, with it’s static methods like getString to provide a nice Future-based API for the most common functions.
DateTime replaces Date
While maintaining much of the original functionality, the DateTime class has replaced the old Date class. The now named constructor still functions much the same. However it apperas that the DateTime.weekday property is currently a 1-based index, whereas the old API appeared to be 0-based index.
StringBuffer updates
The good old StringBuffer class is still around, but it’s API has seen a few updates. In particular it’s less List like, and now more in line with the StringSink interface. Simply put, my .add() calls are now .write() calls.
List APIs
A few subtle changes also exist in the List class. For the most part in my code it was the change of some methods to be properties/getters, such as the isEmpty property.
Cascades!
At first I thought the absence of cascades from my old source was related to my programming style at that time, but a quick search revealed that cascades were not generally available until after I had completed this project. I know it took me a little while to get used to using cascades when they were initially released but I love them now!

This list was just a few of the many many changes that have happened as Dart has matured in the last year and some. I left off a couple of more recent changes such as querySelector as I’ve already covered it briefly and is a very recent change. Additionally, I would like to compare file output sizes but I don’t believe the old Javascript output had been minified, but the new one is so I don’t know that it would make for a fair comparison. The non-minified version is actually slightly larger than the old version of code, but this may also be due to a few structural changes I made to the sources to prepare for adding the new requested feature.

It’s been a fun look at the past of Dart, and I may do so again eventually for server side code if I get an opportunity to look at my Dart-based MUD. The source of which is still available in my GitHub Repository. Warning! It’s not pretty!

This entry was posted in Dart and tagged . Bookmark the permalink.

Have Something To Add?

Loading Facebook Comments ...
Loading Disqus Comments ...