Letting the Data Lead the Code

Abstract : Sometimes the data format used can radically simplify the code. A simple change to the way data is stored in a file can make a big difference in the code required to read it. This was made apparent recently with some Visual Basic code which would locate a list of numbers based on certain search criteria. The code was about one thousand lines and needed to be converted to C# for a new application. It was time to rethink how this could be simplified. The original data format was just a series of numbers stored in an Excel spreadsheet accessed by variable names. Through a long series of if-then-else and case statements the code determined which data to read from the file. The data-search hierarchy was in the source code. It was found that by changing the data format in a hierarchically structured way the code could be drastically simplified. After changing the data format the search function was simplified to about forty lines of code. Although this article will describe a specific data type search algorithm, it may inspire the developer to think more about the data-code design.