Sometimes you don't want behavior with your data

April 19, 2009

I have heard it said that objects are data combined with behavior, which as a snappy summary strikes me as pretty useful; something like it has certainly guided me in structuring my programs. (Although I am nowhere nearly as strongly object-oriented as is popular these days; I still have at least a foot in the procedural programming camp.)

It is also a sensible notion, in the abstract; since data by itself is useless, so you might as well bundle it together with the code that understands it and call them one thing. (You usually can't manipulate the data without understanding it, so you just put all of the code that understands the data into one place. Phrased this way, one may begin to see some exceptions.)

However, I've come to realize that sometimes this is wrong; sometimes you actively want data without behavior dragged along with it, so you want pure data, not objects. The obvious case is (data) persistence, where I think that you are significantly better off if you do not try to tightly bind data and behavior when you save and restore the data. Here the important thing is usually the data, and you do want to be able to get at it without the behavior intervening.

(I think that part of this is because the behavior may change over time in various ways without the data itself changing.)

(This is probably obvious to experienced OO people, but I learned programming in the pre-OO days so I am still sort of feeling my way through all of this.)

Written on 19 April 2009.
« What users see as benefits from sysadmins
Why pickle is not a good way to save your data »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sun Apr 19 00:27:57 2009
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.