Question on Style

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?

Thanks in advance for any help :)
Most often, it depends on preference, much like using for loops and while loops. If you'd rather have unreadable, efficient code, choose the latter.

I go for readibility, so my programs are hugemongous. But, as I said, it's all preference.
If you have a log file, wouldn't it be better to put this into a database and query it for the information you require?

I go for readibility, so my programs are hugemongous. But, as I said, it's all preference.

250k+ lines is a large program :P Anything less than 10k is Small. But then scale is really perspective.
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.

Thank you for your answers :)
To me, large is 100+ lines, but then I just started 3 months ago.

You're welcome, toshiro. Glad to help.
Last edited on
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.

Hope this helps
Last edited on
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).
Topic archived. No new replies allowed.