Article 4AJ75 CodeSOD: Offensively Defensive Offense

CodeSOD: Offensively Defensive Offense

by
Remy Porter
from The Daily WTF on (#4AJ75)

Sometimes, the best defense is a good offense. Other times, the best offense is a good defense. And if you're not sure which is which, you'll never be a true strategic mastermind.

Tina's co-worker understands that this is true for defensive programming. Always, always, always catch exceptions. That's a good defense.

Project getProject() { Project projectToReturn = null; try { projectToReturn = new Project(); } catch (Exception e) { Logger.log("could not instantiate Project") } return projectToReturn;}

The good offense is not actually doing anything useful with the exception and returning a null. Now the calling code needs to also go on the defense to make sure that they handle that null appropriately.

otter-icon.png [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today! TheDailyWtf?d=yIl2AUoC8zArfoeucCZXAE
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