Redian新闻
>
Refactoring long class step by step (1)
avatar
Refactoring long class step by step (1)# Programming - 葵花宝典
g*g
1
Lately I tried to break down a long class which had 3000+ lines of code
developed by someone coz I am having a hard time maintaining it. And it's
common in everyone's project.
Here are some practical steps and tips I want to share and would welcome
any comments and suggestions. Most of them you can find more details in
refactoring books.
1. Remove unused fields and functions. If there's no references, simply
remove them unless you are providing standard API to open public.
2. Move utility functi
avatar
m*t
2
写的好, 是原创吗?

【在 g*****g 的大作中提到】
: Lately I tried to break down a long class which had 3000+ lines of code
: developed by someone coz I am having a hard time maintaining it. And it's
: common in everyone's project.
: Here are some practical steps and tips I want to share and would welcome
: any comments and suggestions. Most of them you can find more details in
: refactoring books.
: 1. Remove unused fields and functions. If there's no references, simply
: remove them unless you are providing standard API to open public.
: 2. Move utility functi

avatar
g*g
3
yep, just some thoughts for what I did last couple of days.
Somehow I felt it would be better if I just rewrite it,
but more than often you have no options.

【在 m***t 的大作中提到】
: 写的好, 是原创吗?
avatar
c*t
4
There is a conflict of philosphy in parts. The procedure described
seems to indicate that you want to create a significantly better code,
yet you are working on that piece of dead code. It might be just easier
to code new classes and just refactor some of the critical functions to
these new classes. Then you have the freedom of using patterns. Otherwise,
I would recommand to refrain from doing too much at once, such as reducing
the instance variables etc.
My procedure for dealing some crappy

【在 g*****g 的大作中提到】
: Lately I tried to break down a long class which had 3000+ lines of code
: developed by someone coz I am having a hard time maintaining it. And it's
: common in everyone's project.
: Here are some practical steps and tips I want to share and would welcome
: any comments and suggestions. Most of them you can find more details in
: refactoring books.
: 1. Remove unused fields and functions. If there's no references, simply
: remove them unless you are providing standard API to open public.
: 2. Move utility functi

avatar
g*g
5

We are talking about 3000+ lines of code here, which will take at least
2 weeks for a complete rewrite and proper unit testing. Unfortunately
I don't have that much time. For each release, we usually have to finish the
development phase in 2 months, and that usually includes adding a big new
feature and several other improvements, and I can't afford 2
weeks on one class. With a couple of days, I am able to break it down to
several small classes, remove some instance variables, break down some
l

【在 c*****t 的大作中提到】
: There is a conflict of philosphy in parts. The procedure described
: seems to indicate that you want to create a significantly better code,
: yet you are working on that piece of dead code. It might be just easier
: to code new classes and just refactor some of the critical functions to
: these new classes. Then you have the freedom of using patterns. Otherwise,
: I would recommand to refrain from doing too much at once, such as reducing
: the instance variables etc.
: My procedure for dealing some crappy

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。