找回密码
 FreeOZ用户注册
查看: 1129|回复: 3
打印 上一主题 下一主题

Refactoring Discussion

[复制链接]
跳转到指定楼层
1#
发表于 8-9-2009 11:19:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?FreeOZ用户注册

x
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?
回复  

使用道具 举报

2#
发表于 8-9-2009 11:28:09 | 只看该作者
如果是C/C++,简单点的用正则表达式,复杂点的用lex/yacc,这样语法错误就可以统一处理。
回复  

使用道具 举报

3#
 楼主| 发表于 8-9-2009 11:33:08 | 只看该作者
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 ...
回复  

使用道具 举报

4#
 楼主| 发表于 8-9-2009 11:37:47 | 只看该作者
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用户注册

本版积分规则

小黑屋|手机版|Archiver|FreeOZ论坛

GMT+10, 8-4-2025 09:31 , Processed in 0.013291 second(s), 20 queries , Gzip On, Redis On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表