Article 5JR9T CodeSOD: Are You Active Enough?

CodeSOD: Are You Active Enough?

by
Remy Porter
from The Daily WTF on (#5JR9T)

Cornelius was working with some code where the objects might be "active" or "inactive". His code needed to do something different, depending on whether the objects were "active" or not, but fortunately, there was a handy-dandy IsActive method. Weirdly, that method required a bool parameter, but also returned a bool. Since there wasn't any useful documentation, Cornelius checked the C++ code.

 bool SomeActivatedClass::IsActive(bool& active) { active = true; return false; }

This method leaves the choice of whether or not the object IsActive up to the caller. If you check the value in the pass-by-reference parameter, it will always be true. If you check the return value, it will always be false.

This method is, truly, a work of art. It doesn't tell you, the audience, what to think about the nature of being active. It instead poses a question, and lets the caller decide. It forces us to confront our own preconceptions about an IsActive method, the nature of return values, and why we sometimes prefer reference parameters. Like films by the the great auteur, Neil Breen, it asks big questions even as it provides no answers of its own.

otter-icon.png [Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today! TheDailyWtf?d=yIl2AUoC8zA_rgklOz7KAE
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