Do not check-in DEBUG specific code.

We are using .Net Remoting to interact beteeen client and back end server. I needed to call a method from services class.
For debugging purposes I decided to create the class directly. It was easier to debug without starting extra back-end process.
The code was like the following:

IMyServices services = (IMyServices)RemotingHelper.GetObject(typeof(IMyServices));
#if DEBUG
    services = new MyServices();
#endif
// Process the task
services.ProcessItems(ItemsCollection); 

During the development I checked that the method done the required processing and changed the parameter object as expected.

And I’ve checked in the code, assuming that in Release mode the application will work the same way just by instantiating proxy instead of full object.
However in Release mode changes in parameter inside calling method were not returned back.
Of course, If parameter is serializable, it is passed by value. and correct implementation will use return value

 ItemsCollection = services.ProcessItems(ItemsCollection);

But more general recommendation before check-in remove/comment-out any DEBUG specific shortcuts and test the code  as it will be in production.

Advertisements