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.

5 Comments:

Blogger kevinprehiem37646855 said...

This comment has been removed by a blog administrator.

August 17, 2005 at 7:18:00 PM PDT  
Blogger alessandra3najee said...

This comment has been removed by a blog administrator.

September 24, 2005 at 1:38:00 AM PDT  
Blogger eddflynn94910304 said...

This comment has been removed by a blog administrator.

October 12, 2005 at 11:23:00 PM PDT  
Blogger edharolds03511961 said...

This comment has been removed by a blog administrator.

December 18, 2005 at 4:26:00 AM PST  
Blogger louisfisher7048 said...

This comment has been removed by a blog administrator.

December 28, 2005 at 10:02:00 AM PST  

Post a Comment

<< Home