The jQuery PeriodicalUpdater, which has been getting lots of love because of feedback and support over here, has a new feature. The “data” configuration argument now will work properly with numbers and anonymous functions. This means that you can have your periodical updater send different information across in different runs.
I’ve said before that null sucks, but now I’ve got a case in point for why mutable data sucks, too.
One of the things that made this somewhat tricky was the fact that jQuery modified the configuration arguments passed in. The configuration arguments are just a map, and jQuery uses that map’s entries as scratch space for its calculations. This is really a problem if you want to use the map over and over again (as the PeriodicalUpdater wants to), because it means that the previous version of the data is ruined. (More description of the probem in this comment). The result was that I had to clone the arguments that I passed in so that I could reuse the arguments next time!
Note that there’s no documentation about this happening—in fact, it’s purely an implementation detail. But it’s an implementation detail which leaked out and caused bugs. I think there’s a real point to Clojure’s seemingly neurotic tie to immutability. It prevents a lot of problems like this.
Related posts: