New PeriodicalUpdater Feature, and, Mutable Data Sucks: A Case in Point

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:

  1. null Sucks: A Case in Point
  2. Updated GORM Labs and JQuery PeriodicalUpdater
  3. JQuery PeriodicalUpdater Updated Again
  4. JQuery PeriodicalUpdater (AJAX long polling/server polling)
  5. Feature or Bug, You Decide: Argument Reordering in Groovy
This entry was posted in Open Source, Programming Language Punditry. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • http://getfsohum.selfip.com Sohum
  • http://www.smokejumperit.com Robert Fischer

    Yes, I’m very aware. You may want to check out the blog posts under “Most Popular Posts” in the left sidebar of this blog, because functional programming evangelism and discussion is one of the main themes around here. Part of the reason I’m bringing these cases to the attention of the readers is to help people get why I am so hung up on functional programming.

    One of the things that surprised me back at the last JavaOne is how far Clojure gets with immutability and dynamic typing. I’ve advocated before that static typing and functional programming go hand-in-hand (see the Functional Programming, Typing, and Closures post for more on that), but Clojure’s making me re-think that somewhat. It’s amazing how far they get with just immutability.

  • http://getfsohum.selfip.com Sohum

    Ah, apologies, I’m a new reader :)

  • Categories