The situation: I have a large log file, parts of which I have to parse for specific information and reformat that infomation for visualization.
Now there are expressions that have very similar appearances. They differ only in description, and, more importantly, in a unique message identifier #.
Would it be better to write a method to get each message's information separately and call that method separately, or write one method with a switch statement, checking the message # and acting appropriately? The former would obviously yield more code, but it would perhaps be more legible afterwards. The latter would probably cause the exact opposite. What should I go for?
Well, for one thing, I have no experience with database handling, and for another, the log files are supplied externally, and I do not know who will use my program with which file (in theory).
But I kept the functions separate, because it is more than likely that someone else will have to work on or with my code.
If there is a chance that the number of # identifiers will increase, try and make your code as modular as possible, making it easier to extend the # identifiers.
There are two ways that spring to mind. Either a switch statement, calling out to separate methods for each ident (keeps the methods small), all in a single class, or a generic abstract ident class that has a derived class for each specific identifier. The second option I would suggest as being the more elegant solution.
Well, the problem is, to create a file containing values to be read by another program to create trend curves, I'm forced to execute every method each time a new line is being evaluated (other methods that are entirely dependent on occurrence of the critical strings are actually called by a switch statement, but I streamlined that one as far as possible, to have the least likely identifiers at the bottom). So I guess I'm creating a lot of overhead, but I can't see how to do it differently (at the moment, and my internship will be over tomorrow, so this will have to do).
Again, thanks for the help :) I really love this site and its fora for their friendliness (user- and otherwise).