Code masters ;)
October 26th, 2007Every coder sometimes encounters a situation when a bug must be fixed. At the begining it looks for a very easy task... but the code reveals that it might be quite tricky
Here is one of most common antipattern - hardcoding mixed with magic numbers. Please fasten your seatbelts
C#:
EditorDatabase EditorDB = new EditorDatabase();
if (UserIDTextBox.Text == "0" && LoginRoleDropDownList.SelectedValue == "11")
{
EditorDB.Save(CodeHiddenField.Value, TextGridView.Rows[rowID].Cells[5].Text,
System.Convert.ToInt32(TextGridView.Rows[rowID].Cells[10].Text), TextGridView.Rows[rowID].Cells[8].Text,
0, spr, TextGridView.Rows[rowID].Cells[11].Text).ExecuteNonQuery();
}
else
{
EditorDB.Save(CodeHiddenField.Value, TextGridView.Rows[rowID].Cells[5].Text,
System.Convert.ToInt32(TextGridView.Rows[rowID].Cells[10].Text), TextGridView.Rows[rowID].Cells[8].Text,
System.Convert.ToInt32(UserDropDownList.SelectedValue), spr, TextGridView.Rows[rowID].Cells[11].Text).ExecuteNonQuery();
}
if (UserIDTextBox.Text == "0" && LoginRoleDropDownList.SelectedValue == "11")
{
EditorDB.Save(CodeHiddenField.Value, TextGridView.Rows[rowID].Cells[5].Text,
System.Convert.ToInt32(TextGridView.Rows[rowID].Cells[10].Text), TextGridView.Rows[rowID].Cells[8].Text,
0, spr, TextGridView.Rows[rowID].Cells[11].Text).ExecuteNonQuery();
}
else
{
EditorDB.Save(CodeHiddenField.Value, TextGridView.Rows[rowID].Cells[5].Text,
System.Convert.ToInt32(TextGridView.Rows[rowID].Cells[10].Text), TextGridView.Rows[rowID].Cells[8].Text,
System.Convert.ToInt32(UserDropDownList.SelectedValue), spr, TextGridView.Rows[rowID].Cells[11].Text).ExecuteNonQuery();
}

October 26th, 2007 at 11:36 pm
Nice. The former if-clause detects root user and the latter selects normal user, I suppose
I’m wondering if manager leading this project was aware of this kind of practice.
October 26th, 2007 at 11:44 pm
Your’re right. It happens often when a “newbie” programmer sits alone for a couple of hours
Often a manager is aware of this kind of practice but it’s another problem: some kind of “don’t touch it until it works”. I’m pretty sure that anti-patterns are very common in every programming environment.
October 27th, 2007 at 8:26 am
Yes, unfortunately it’s true. When I was pointing issues like this one, I often heard “but the program for user”
Now, I know what IT analysts mean saying software maintenance is the most expansive part of programming, especially if you have to spend tens of hours fixing previous half-designed solutions.
October 27th, 2007 at 9:58 am
Are both of you trying to say that yours PM are reading the code? My isn’t and he’s saying that’s our job
October 27th, 2007 at 10:08 am
Could you tell me where’s the main RSS channel for your website? I can’t find it and it would be very useful
You have one, right?
October 27th, 2007 at 12:02 pm
Pure poetry! I guess someone needs to be instructed that there is aa “const” clause in C#
That’s of course basics among other programming and designing principles that are violated here.
October 27th, 2007 at 2:54 pm
@Andrew - here it is http://www.sirmike.org/feed/
It’s my job to supervise, but as I said - leave an apprentice alone for a couple of hours and you have got a mess ready
No, my PM does not read the code
@Xion - const in C# is a little bit “disabled” - if I can say it that way
There is also a readonly keyword.
November 6th, 2007 at 5:31 am
@ Andrew
Now, I’m not saying that PMa are supposed to reading a code. I’m just saying that sometimes it’s good PMs know about potential costs of further maintenance of such messed code.