FreeOZ论坛

标题: Refactoring Discussion [打印本页]

作者: key    时间: 8-9-2009 11:19
标题: Refactoring Discussion
I'm currently working on some legacy Java code and need to
do some refactoring on it.

That is a string parsing task. The original program treats
the input message step by step, in another word, word by word.
When some formatting errors occur, the program tries to log
the problem.

What I want to do is extracting all logging code from the source,
because there are too many trivial statements for logging.
And I want to normalize these logs.

How can I do that?
作者: coredump    时间: 8-9-2009 11:28
如果是C/C++,简单点的用正则表达式,复杂点的用lex/yacc,这样语法错误就可以统一处理。
作者: key    时间: 8-9-2009 11:33
Logging type:

1. warning, continue
2. error, stop there and return true
3. error, stop and return false

I'm going to introduce a ParsingException and ParsingErrorMessage.

ParsingErrorMessage is a class working as a Linked List,
which has the following fields:
1. The original message
2. The current substring
3. The message type ( error or warning or others )
4. The position
5. The error/warning message to log

When an error occurs, I throw a ParsingException and catch it somewhere.

原帖由 key 于 8-9-2009 11:19 发表
I'm currently working on some legacy Java code and need to
do some refactoring on it.

That is a string parsing task. The original program treats
the input message step by step, in another word, w ...

作者: key    时间: 8-9-2009 11:37
I think I will finally introduce regex into it.
However, because the programmer of the old project
was familiar with regex, I believe there could
be something here not suitable to use regex.
I'll discuss this with him later when he has time.

What I'm thinking is:
1. normalizing the output message.
2. reducing trivial code.
3. having a better structure or processing flow.
4. extracting some reusable components and applying some OOP philosophies.

原帖由 coredump 于 8-9-2009 11:28 发表
如果是C/C++,简单点的用正则表达式,复杂点的用lex/yacc,这样语法错误就可以统一处理。





欢迎光临 FreeOZ论坛 (https://www.freeoz.org/ibbs/) Powered by Discuz! X3.2