Here’s an example of some bizarre code I’ve seen recently. I’ve changed the variable names, but this is what the developer was doing.
Customer customer = new Customer();
customer = customers[response.CustomerKey];
The first line is completely unnecessary. If you instantiate an object, then assign the object to another instance, the first instance sticks around and eventually gets collected. However, there’s no reference to it. You can never use that instance. Here’s how it should look.
Customer customer = customers[response.CustomerKey];
I would assume that it was dirty code that should have been cleaned before checking into version control, except for the fact the lines were adjacent. For the life of me, I don’t know why anyone would create an unnecessary instance. Any ideas?