Article 6D8RC CodeSOD: The Set Up

CodeSOD: The Set Up

by
Remy Porter
from The Daily WTF on (#6D8RC)

My heretical opinion on object-oriented programming is that I don't like getters and setters. They're often trivial boilerplate (boilerplate is a code smell), or they're hiding behavior where behavior probably doesn't belong.

Yes, yes, I understand the importance of encapsulation, but in a lot of ways, trivial getters/setters break encapsulation. void setFoo(T foo) { this.foo = foo; } does nothing to protect foo against unauthorized modifications.

So while I understand encapsulation, I don't think I understand it as well as the Senior Engineer responsible for today's anonymous submission. Because they certainly fixed the encapsulation issues with setters:

public void setStatus() { this.status = status;}

This Java setter method guarantees that I can't alter the status property of this object to an incorrect value, because I can't alter it at all. status and this.status are referring to the same value.

Our anonymous submitter adds:

IDE tooling showed that this function was called from nowhere in the codebase. It took no parameters and returned nothing. But what did it do? There is no documentation, comments nor unit tests. It would, however require documentation and regression tests were I to remove it, at which point I quietly ignored it and moved on. To another company in fact.
An insider has since informed me that the project has been shelved. Whatever this.status is now, it will forever be unknown.

otter-icon.png [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments