Vincent Gable’s Blog

August 15, 2008

Members Are The Devil

Filed under: Bug Bite,Design,Programming
― Vincent Gable on August 15, 2008

More and more, I am of the opinion that a member-variable is a terrible thing to have in a class. Put more sanely, a class should have as few member variables as possible.

I have squashed too many bugs in the past couple of months, where two objects had their own fields that represented the same thing .. but then got out of synch. Only one object should ever store the same value.

I guess you could say this is database-normalization, applied to general programming. And I think in that space it makes more sense.

A corollary is, never cache a value that can be calculated, without a measured performance reason.

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

Powered by WordPress