CodeSOD: Simulated Congealing |
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.
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |