My company inherited an application from India contractors. More or less, the application was 130,000 lines of spaghetti code: 100% of the application logic embedded in the forms, apart from forms the app contained 5 classes which held the entire state of the app in public static variables, and a grand total of zero unit tests. You know, standard quality code you get from the lowest offshore bidder.
The application was notoriously slow. After investigating the code, I encountered large regions of code that appeared to do precisely nothing. One method I found manipulated a string in the following way:
- Read a string from a textbox.
- Replace all of the newlines with pipes instead. This was implemented by iterating through each char, adding each char to stringbuilder one by one.
- Split the pipe delimited string into an array.
- Iterate through each element in the array, appending each line to a stringbuilder.
- Assigning the stringbuilder's text back to the textbox.
The string that went into the method was exactly the same string that came out. No transformation of the string had taken place at all. The transformation was spread out across 2 or 3 methods for a total of 30 lines of code.
Additionally, a search for an element in a collection required a linear search, regardless of more efficient methods. If you needed to find an item with two properties, you had one for loop nested in another; for three properties, you had three nested for loops. Each search was O(n^p), where n is the number of items in a list, and p is the number of properties to compare.
If I remember correctly, there were 3 programmers working unsupervised on the project for about a year, and together they pushed out 130,000 lines of buggy code. I never confirmed it, but I believe those programmers were required to meet some unreasonably high quota, such as 200 lines of code per day.
To make a long story short, my company took over the project and continued development on the application in house. The application was so bad that it wasn't even refactorable, it just had to be rewritten. Every checkin saw the sourcecode drop by 5, 10, or occcasionally 20 kb at a time. Simply be removing repetitive, redudant, and useless loops, we increased the applications speed 300%.
After 12 months of re-writing the application, the linecount dropped to 36,000 or so lines of code, and the app runs at about 5x the speed of the original.