Showing posts with label Bad code. Show all posts
Showing posts with label Bad code. Show all posts

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

Thursday, May 24, 2007

On the virtues of crap code

Sometimes you just have to wonder what people are thinking. What level of software engineering degree does it take to completely misunderstand a concept and write this very special code?

SqlConnection conn = _db.GetConnection();
SqlTransaction tx = conn.BeginTransaction();
SqlCommand cmd = this.GetCmdRemoveField(conn);
cmd.Transaction = tx;
cmd.Parameters.Add("@ID", id);
cmd.Parameters.Add("@FieldName", field);
cmd.ExecuteNonQuery();
tx.Commit();
conn.Close();
try { tx.Rollback(); }
catch { }
conn.Close();


My eyes bleed and my heart sunk as I found this code from an external development group that was developing part of the previous application I worked on.

kick it on DotNetKicks.com Shout it