Unrewarded Persistence

Boy, do I really want to love this technique. I mean, who wouldn't prefer this:

[PersistField(Location = PersistLocation.Session)]
public bool IsLoggedIn;

Over this:

public bool IsLoggedIn
{
get
{
return Convert.ToBoolean(Session["IsLoggedIn"]);
}
set
{
Session["IsLoggedIn"] = value;
}
}

It's so elegant and so concise. But it operates through reflection and reflection has a bad rap for being hoggy. Can you imagine checking every property for the attribute on load and then checking to see if they've changed at on unload? Talk about a tax on resources.

This beautiful snippet trades readability for performance and I think the bargain isn't worth it. The time it takes to write out the getters and setters of a property is a one-time deal. The decoration method outlined above makes the code easier to read and easier to describe, but at the expense of perennial runtime delays.

It's just not worth it.

About this Entry

This page contains a single entry by bbrown published on October 9, 2007 2:30 AM.

Scalping Ain't Easy was the previous entry in this blog.

Atlas Shrugged and Me is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Feedback to