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