如何重组一个Delphi单元10000行没有文件? [英] How to refactor a Delphi unit with 10000 lines with no documentation?

查看:122
本文介绍了如何重组一个Delphi单元10000行没有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被分配了重构Delphi单元的任务。哇。 10000行代码,没有文档,吨的复制和粘贴代码。



有许多方法可以复制和粘贴,可以重构,无论如何我全部丢失那些行,我有接口部分,我可以找到我的方式,但一般来说,你们建议如何处理这种任务?



谢谢。 p>

解决方案


  1. 由Micheal Feathers自己创建一个使用旧版代码 。它具有各种技术,用于安全地重构代码,使其在测试框架下运行。例子主要是Java和C ++,但应该很容易找出。

  2. 安装第三方重构工具(或多个),如CodeRush for Delphi(可悲的是不再开发) Castalia或ModelMaker代码浏览器。 Delphi有一些内置的重构支持,但是根据我的经验,它的局限性很大,往往会阻碍非常大的代码库。

  3. 购买Simian的副本。它不直接支持Object Pascal,但它的纯文本解析器工作得很好。如果有足够的人要求对Object Pascal的支持,我肯定会添加它。我没有找到任何其他代码重复检测工具,如Simian一样。

我还建议书签 http://www.refactoring.com/catalog/ http: //www.industriallogic.com/xp/refactoring/catalog.html



RobertBob叔叔Martin等人获得了敏捷软件工艺手册(Clean Code:A Handbook of Agile Software Craftsmanship)的副本也不会受到伤害al。很容易识别错误的代码。在写好代码的时候很难知道。



谨慎的一点:专注于重构你需要工作的代码。它很容易启动兔子洞,并结束花费几个月重构与手头任务没有立即相关的代码。



并保存自己一些麻烦。不要尝试修复代码并重新构造它。 Refactor 第一个,然后修复错误或添加新功能。请记住,重构正在修改而不改变外部行为



抵制尝试完全重写的冲动。我学会了很难的方式,满足用户要求的肮脏的代码比干净的代码更好。尴尬的代码总是可以逐步改进,直到其值得骄傲。


I have been assigned the task to refactor a Delphi unit. Wow. 10000 lines of code, no documentation, tons of copy and paste code.

THere are many methods made with copy and paste that could be refactored, anyway I am lost in all those lines, I have the interface section where I can "find my way", but in general what do yuo suggest for tackling this kind of task?

Thanks.

解决方案

  1. Get yourself a copy of Working Effectively with Legacy Code by Micheal Feathers. It has all kinds of techniques for safely refactoring code to get it running under a test framework. Examples are mostly in Java and C++ but should be easy enough to figure out.
  2. Install a third-party refactoring tool (or multiple) such as CodeRush for Delphi(sadly no longer developed), Castalia or ModelMaker Code Explorer. Delphi has some refactoring support built in but in my experience it is too limited and tends to choke on very large code bases.
  3. Buy a copy of Simian. It doesn't have direct support for Object Pascal but its plain text parser works well enough. If enough people request support for Object Pascal I'm sure they'd add it. I haven't found any other code duplication detection tool as capable as Simian.

I would also recommend bookmarking http://www.refactoring.com/catalog/ and http://www.industriallogic.com/xp/refactoring/catalog.html.

It also wouldn't hurt to get a copy of Clean Code: A Handbook of Agile Software Craftsmanship by Robert "Uncle Bob" Martin et al. It's easy to recognize bad code. It's much harder know when you're writing good code.

A word of caution: Focus on refactoring the code you need to work on. Its easy to start down the rabbit hole and wind up spending months refactoring code that wasn't immediately relevant to the task at hand.

And save your self some trouble. Don't try to "fix" code and refactor it at the same time. Refactor first, then fix bugs or add that new feature. Remember, refactoring is modifying without changing external behavior.

Resist the urge to attempt a complete rewrite. I learned the hard way that crappy code that meets the user's requirements is preferable to clean code that doesn't. Crappy code can always be incrementally improved until its something to be proud of.

这篇关于如何重组一个Delphi单元10000行没有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆