Wednesday, April 20, 2005

No brain-dead accessor functions

I know this is a controversial one that many people disagree with me about, but I don't believe in using accessor functions that simply return a field/variable, or set a field/variable. I see it as a pointless excercise in object-oriented programming that serves to complicate things and barely makes anything easier.

My primary reason for hating these is that it makes for harder debugging of code that contains them. With MULTI, you can click on a field that's used within the code and it will print out the value. You cannot, however, click on a accessor function and have it print out the value of the field it accesses.

Another reason for not liking these is that I'd like to think of functions/methods as simplifying a block of code either for ease of reading, or so it can be used by more than one caller. So when I see a function/method call, it implies that something useful is going to go on when it is called. Therefore, if I'm debugging code I don't know like the back of my hand, I may look at the function or at least guess its purpose by its name. An accessor function, then, is simply a distraction as I have to think about it long enough to determine that it's not really doing anything.


Post a Comment

<< Home