Andy McKay

Jun 30, 2006

Don't use properties


Was helping a person on irc the other day. The problem was they were including a string into a template. The string was coming from a property on an object, that property was being acquired through acquisition. The code was something like this:

So the what’s the problem here?

  • What's the chance you will remember in 6 months what getSectionText is? Go away for a day then try to remember (ok, perhaps I'm just getting old). But you'll never remember that is a property on an object and there is no easy way of finding that out.
  • There is no easy way to change it.
  • There is no easy way to list them all - short of waking up every object and examining it.
  • You could conceivably get hit by security when someone workflows the object with the property for you (admittedly perhaps less of a concern).

In this case I prefer a Python script that searches the objects location and returns a value. Here’s an example that I pulled from Enfold Systems that displays a different image on the top of every folder.


Next we add this into the skin. In this case this is called getSectionImage and the template reads:

Not the worlds most sophisticated peice of code but…

  • It's easy to remember, when looking in our templates and I spot the line getSectionImage, its easy for me to look in the skin and remember there is a script called getSectionImage even now two years later.
  • I can easily see what all the images are and alter them.
  • Never any security to worry about.

The only real problem you have is that for complicated requirements, that script can get complicated, but that’s true of properties too.