The Daily WTF
Follow
CodeSOD: Counting it All
Today is election day in the US, and counting is on many people's minds. The code being discussed is not related to counting votes, but it's still problematic. The code is from an old application released in 2007 and references Excel's row limit of 65,536, which was increased to 1,000,000 in Excel 2007. However, the code is actually reading a CSV file, not an Excel file. The code constructs the file name twice, which is unnecessary. The real issue is how the code counts rows, which is inefficient and performs poorly on large files. The code reads the entire file into memory, splits it on newlines, and then counts the length. This approach is terrible for large files, of which there were many. Unfortunately, nobody wants to fix the code because of the "don't touch it" rule for old, legacy code. Instead, management is promising to launch a new replacement project, but for now, the code remains unfixed.