A week ago I was reviewing some code to add a little bit of new functionality. That was the project that I have been managing for about 6 months. I knew that there was ugly and hard to maintain code there, because of the very short time to implement all the features. In some way I was prepared to find misuses of the .NET framework, dangerous constructions and magic numbers through the code. But I was not prepared to find the following.
In one of the forms there is a grid that shows all rows from a table in the database. I assumed that in order to show a new row I only need to add it in the database table. Needless to say when I did add the row it did not show up in the grid. Well I was stumped. How was this possible? The grid was supposed to show all rows from the table. Somehow the newly added row did not make it on the screen.
There were two possible choices. First – not all the rows were read from the database. This was very easy to track using the wonderful SQL Profiler. If you ever have to deal with application that uses MS SQL and you are debugging some data related issue my advice is: always start debugging data with the SQL Profiler first. That’s not the case with Oracle but that’s another story. So I found that all my rows including the new one are actually returned to the client. Second choice – the grid was not showing all the rows because one or another reason. After half an hour digging through various properties and custom xml of the third party grid control I found out the problem. Because of the nature of the data there were two types of data in this particular data table. The ones with ID below zero were system rows and were not supposed to be showed in the grid. On the contrary side the rows with ID above zero are expected to show up. You may think that I have created my new rows with ID below zero, but you are wrong. The grid actually used a filer to display only the meaningful rows, but instead to filter the rows out by ID, it was filtering them by name. For example: Filter = “([Name] = ‘john’) OR ([Name] = ‘mike’)”. I felt a little bit helpless.
In all the efforts, endless code reviews and test cases to deliver quality code, nothing can help you better than the willingness and the experience of the developer to produce quality and easy to maintain code.