Henrik H sends us a short snippet, for a relative value of short.
We've all seen this method before, but this is a particularly good version of it:
public class CustomerController
{
public void MyAction(Customer customer)
{
// snip 125 lines
if (customer.someProperty)
_customerService.UpsertSomething(customer.Id,
customer.Code, customer.Name, customer.Address1,
customer.Address2, customer.Zip, customer.City,
customer.Country, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, false, false, null, null, null, null, null,
null, null, null, null, null, null, null, false,
false, false, false, true, false, null, null, null,
false, true, false, true, true, 0, false, false,
false, false, customer.TemplateId, false, false, false,
false, false, string.Empty, true, false, false, false,
false, false, false, false, false, true, false, false,
true, false, false, MiscEnum.Standard, false, false,
false, true, null, null, null);
else
_customerService.UpsertSomething(customer.Id,
customer.Code, customer.Name, customer.Address1,
customer.Address2, customer.Zip, customer.City,
customer.Country, null, null, null, null, null,
null, null, null, null, null, null, null, null,
null, false, false, null, null, null, null, null,
null, null, null, null, null, null, null, false,
false, false, false, true, false, null, null, null,
false, false, false, true, true, 0, false, false,
false, false, customer.TemplateId, false, false, false,
false, false, string.Empty, true, false, false, false,
false, false, false, false, true, true, false, false,
true, false, false, MiscEnum.Standard, false, false,
false, true, null, null, null);
// snip 52 lines
}
}
Welcome to the world's most annoying "spot the difference" puzzle. I've added line breaks (as each UpsertSomething
was all on one line in the original) to help you find it. Here's a hint: it's one of the boolean values. I'm sure that narrows it down for you. It means the original developed didn't need the if/else
and instead could have simply passed customer.someProperty
as a parameter.
Henrick writes:
While on a simple assignment to help a customer migrate from .NET Framework to .NET core, I encountered this code. The 3 lines are unfortunately pretty representative for the codebase

This post originally appeared on The Daily WTF.