Don’t rely on default values

I was creating a mobile app this morning which made heavy use of AJAX calls, heavy enough that caching was necessary to reduce server load.

I use the jQuery $.ajax() method so often that I rarely consider what would happen if one of the default values for a parameter changes in a future release.

For instance, in my current app, I depend on the fact that regular (not jsonp or script) $.ajax() calls will be cached, and providing the cache: true parameter is just adding needless lines lines to my code.

But, what happens if, in a future release, jQuery decides to make cache default to false? Well, my server will certainly see a lot more load! Not to mention the slower response times seen by users.

While it isn't likely that jQuery would make such a change (at least without making it painfully clear in their change logs), this might make you think about other areas of your code which do rely on default values, client or server-side.

Why follow me on Twitter?

  • I tweet about new technologies, services or libraries I find interesting
  • Yeah, sometimes I'll post a pet-peeve or rant about something trivial
  • If I discover something that made my web development life easier, I share it
  • I'll shout out any handy tip that I think might be useful to other devs

Tagged .

Updated: 2012-10-20

Phil LaNasa follow us in feedly