Code masters ;)

October 26th, 2007

Every 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 :D

C#:
  1. EditorDatabase EditorDB = new EditorDatabase();
  2. if (UserIDTextBox.Text == "0" && LoginRoleDropDownList.SelectedValue == "11")
  3. {
  4.     EditorDB.Save(CodeHiddenField.Value, TextGridView.Rows[rowID].Cells[5].Text,
  5.     System.Convert.ToInt32(TextGridView.Rows[rowID].Cells[10].Text), TextGridView.Rows[rowID].Cells[8].Text,
  6.     0, spr, TextGridView.Rows[rowID].Cells[11].Text).ExecuteNonQuery();
  7. }
  8. else
  9. {
  10.     EditorDB.Save(CodeHiddenField.Value, TextGridView.Rows[rowID].Cells[5].Text,
  11.     System.Convert.ToInt32(TextGridView.Rows[rowID].Cells[10].Text), TextGridView.Rows[rowID].Cells[8].Text,
  12.     System.Convert.ToInt32(UserDropDownList.SelectedValue), spr, TextGridView.Rows[rowID].Cells[11].Text).ExecuteNonQuery();
  13. }

8 Responses to “Code masters ;)”

  1. 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.

  2. SirMike says:

    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.

  3. 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.

  4. Andrew says:

    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 ;)

  5. Andrew says:

    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?

  6. Xion says:

    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.

  7. SirMike says:

    @Andrew – here it is http://www.sirmike.org/feed/
    No, my PM does not read the code :) 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 :)

    @Xion – const in C# is a little bit “disabled” – if I can say it that way :) There is also a readonly keyword.

  8. @ 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.

Leave a Reply

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!

Powered by Rootnode