Article 1H4ZV CodeSOD: Simulated Congealing

CodeSOD: Simulated Congealing

by
Remy Porter
from The Daily WTF on (#1H4ZV)

Simulated Annealing is a class of algorithms from moving through a search space to find a solution, balancing "good enough" results against a computational budget.

John L has a co-worker that has taken this logic and applied it to writing code. Whenever code needs to change, he "randomly" changes the function in small increments until it works. The result is code that looks like this:

 private void handleDoubleClickTreeNode(object sender, FormTreeNodeArgs e) { if ( e.FormTreeNode.FormElement != null) { AddScoreElement(e.FormTreeNode.FormElement); } else if (e.FormTreeNode.FormElement == null) { if (e.FormTreeNode != null) { if (!string.IsNullOrEmpty(e.FormTreeNode.Name)) { AddScoreElement(e.FormTreeNode.Name); } } } }

This code does work, but some of the conditionals make it clear that it works more through an accident than any intentional design.

otter-icon.png [Advertisement] Infrastructure as Code built from the start with first-class Windows functionality and an intuitive, visual user interface. Download Otter today! TheDailyWtf?d=yIl2AUoC8zAYLANmzD7fkc
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