Tuesday, April 28, 2009

Comments are the true revealer of a bad coder

Comments that are in the code of the application that you have inherited maintenance of can sometimes very quickly reflect the quality of the codebase. In this case there is obviously a bit of confusion around the subtlety and use of the cast, as and is C# operators. Yes, there is also a grammatical error. And no, I have not removed any code from inside the if block - that is all there was.

if (payment is CreditCardPaymentDto)
// For some reason casting this outside the if statement throws and exception
CreditCardPaymentDto creditPayment = (CreditCardPaymentDto)payment;

kick it on DotNetKicks.com Shout it