Article 4H0VK CodeSOD: Whose Tern is it to Play?

CodeSOD: Whose Tern is it to Play?

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

Every once in awhile, someone sends us some code from a game. Now, I've never delved deep into game development, aside from making a 3D asteroids game as a final project for a class twenty years ago, but I've also read an article about how fast inverse square root works, and know that you shouldn't blow in a Nintendo cartridge, so I'm basically an expert, and I understand that under the constraints of games, some of the rules about clarity and maintainability go out the window.

But Adam S found some code that'd be just plain bad in any context:

DamageResult progress(UUID uuid, double progress, boolean auto) { return this.isLooted() ? DamageResult.ALREADY_LOOTED : this.thief == null ? this.makeProgress(uuid, progress) : this.challenger == null ? this.thief.equals(uuid) ? auto ? this.ticksSinceLastThiefHit >= this.getConfig().getLootTickRate() ? this.makeProgress(uuid, progress) : DamageResult.AUTO_NOT_YET : this.ticksSinceLastThiefHit >= this.getConfig().getClickRateCap() ? this.makeProgress(uuid, progress) : DamageResult.TOO_QUICK : this.makeChallengeProgress(uuid, progress, true) : this.thief.equals(uuid) || this.challenger.equals(uuid) ? auto ? DamageResult.NO_AUTO_CHALLENGE : (this.thief.equals(uuid) ? this.ticksSinceLastThiefHit : this.ticksSinceLastChallengerHit) >= this.getConfig().getChallengeClickRateCap() ? this.makeChallengeProgress(uuid, progress, false) : DamageResult.TOO_QUICK : DamageResult.CHALLENGE_IN_PROGRESS;}

Line breaks were added, less to make this any more readable, and more because it needs to fit on the screen somehow. The original is all in one line. The part where they nest a ternary into the conditional side of a ternary leaves me going "null ? what ? auto ?".

proget-icon.png [Advertisement] Ensure your software is built only once and then deployed consistently across environments, by packaging your applications and components. Learn how today! TheDailyWtf?d=yIl2AUoC8zAmG7yqM5uXpY
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