Friday, May 30, 2008

Another point of defensive programming

Another point of defensive programming that I need to work on is not drilling too deep into an object. "object.relation.group_of_attributes.value" is bad code. Any time something changes inside, you have to change code in multiple other locations.

I've often used the excuse, "But requiring accessors reduces my flexibility." But now I realize that that kind of flexibility leads to very fragile code, makes testing impossible because you have hundreds of possible failure modes and prevents you from installing any central code to deal with those failure modes.

Shame on me.

No comments: