I saw some code recently that made me think “that person has lost their mind”; it was a class with a public enumeration in it with 15,000 (yes fifteen thousand) members. I noticed it when using resharper; mostly it takes a few seconds to open a solution when it works through all the files, but in this case it gets hung up for minutes. My first reaction is that this was mad, but I did at least try to understand why they had done it.
The enumerations were clearly imported in bulk from some external file (they were Bloomberg terminal commands). My first reaction is that this was not code, it was a database, and should be stored in a database. Any claim that the enumeration could be used for Intellisense is clearly rubbish as there are so many members that you need to know the thing you are looking for, thus eliminating the purpose of having the enumeration prompt you with the right options. I’m not really sure what it is good for. Of course, as soon as things go anywhere but in code, then we are in some sort of late-bound, text-based nightmare when we are just tossing strings around and hope we have the right string and we won’t know until runtime whether things will work. So, damned if you do, and damned if you don’t.
Obviously all the members aren’t used, but maybe having them all in one place is useful, so where should they be? In a relational database? Seems a little excessive to put them in a database as a) the data isn’t really relational, it is just a list and b) all the other features of a relational database – shared access, powerful query and update language, centralised management – don’t really seem that useful. The really key feature of a database is that it stores data. What is data? Well, one way to look at it is that it isn’t logic. If the logic is the same for all the inputs then the inputs are data. So these commands aren’t really data, as they all do different things that mean we get different results.
So if it is not data, what is it and where else could it be. In an XML file? Is that list of commands “config” for my program? I have some logic and I want to issue a certain command and so I store the command in a config file. Of course, normally one would store only the commands that you needed, and tightly bind the config file to the logic so we’d be more hopeful that we wouldn’t get run time errors when logic and config didn’t connect.
In general, I’d say that we have some sort of hierarchy that goes from code to config to database. We expect that order to work for size and changeability. If the enumeration of 15,000 is huge but never changes is it code or database? I don’t know but it is definitely a hack.