编码 Katas 以练习遗留代码的重构 [英] Coding Katas for practicing the refactoring of legacy code

查看:36
本文介绍了编码 Katas 以练习遗留代码的重构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几个月我对编写 katas 非常感兴趣.我相信它们是磨练我的编程技能和提高我在工作中编写的代码质量的好方法.

I've gotten quite interested in coding katas in recent months. I believe they are a great way to hone my programming skills and improve the quality of the code I write on the job.

有很多地方可以找到 Katas.喜欢..

There are numerous places where Katas can be found. like..

http://codekata.pragprog.com/

http://schuchert.wikispaces.com/Katas

http://www.codingdojo.org/

我发现这些是 Katas 的优秀存储库……我对其中一些的尝试获得了巨大的回报.

I've found these to be excellent repositories of Katas... my attempts at some of them have been been immensely rewarding.

然而,我觉得迄今为止我看到的所有 Kata 都有一个不足之处.他们似乎都不允许我练习重构糟糕的代码.第一次学习如何编写干净的代码很棒……但是在我目前的工作中,我没有太多机会编写新代码.相反,我经常与遗留代码作斗争,并试图找出如何重构模块、消除依赖和减少耦合.

However, I feel that all the Kata's I've seen so far have one short coming. None of them seem to allow me to practice refactoring bad code. It's great learning how to write clean code the first time around...but in my current job, I don't have too many opportunities to write new code. Rather I'm often battling against legacy code and trying to figure out how to refactor modules, eliminate dependencies, and reduce coupling.

因此,我正在寻找一些 Katas,我可以用它们来磨练我重构遗留代码并将其转化为干净代码的技能.

As such, I'm on the look out for a couple Katas that I can use to hone my skills of refactoring legacy code and turning it into clean code.

有人知道已经存在的吗?我知道我在工作时得到了很多练习……但我想磨练我的技能,以便我能够快速了解​​如何在类中分解依赖项并分离关注点做得太多了.

Does anyone know of any that already exist? I know I get a lot of practice at it while I'm at work...but I'd like to hone my skills to the point where I'm able to quickly see how to break apart dependencies and separate concerns in classes that do far too much.

推荐答案

我不知道有哪个网站可以直接对它们进行编目,但我偶尔使用的一种策略是:

I don't know of a site that catalogs them directly, but one strategy that I've used on occasion is this:

  1. 在 sourceforge 上找到一个旧的、小型的、无人维护的开源项目
  2. 下载它,让它编译/构建/运行
  3. 阅读文档,感受代码
  4. 使用有效地使用遗留代码中的技术来测试其中的一部分
  5. 重构那部分,可能会在此过程中修复错误并添加功能
  6. 重复第 4 步到第 6 步
  1. Find an old, small, unmaintained open source project on sourceforge
  2. Download it, get it to compile/build/run
  3. Read the documentation, get a feel for the code
  4. Use the techniques in Working Effectively with Legacy Code to get a piece of it under test
  5. Refactor that piece, perhaps fixing bugs and adding features along the way
  6. Repeat steps 4 through 6

当你发现一个特别具有挑战性的部分时,扔掉你的工作并重复几次以加强你的技能.

When you find a part that was especially challenging, throw away your work and repeat it a couple times to reinforce your skills.

这不仅练习重构,还练习其他技能,例如代码阅读、测试和处理构建过程.

This doesn't just practice refactoring, but other skills like code reading, testing, and dealing with build processes.

最难的问题是找到一个你有足够兴趣继续工作的项目.我上一个工作是一个用于遗传编程的 python 库,而目前我正在工作的是一个 IRC 库,用于遗传编程爪哇.

The hardest problem is finding a project that you're interested enough in to keep working in. The last one I worked on was a python library for genetic programming, and the current one I'm working on is a IRC library for Java.

这篇关于编码 Katas 以练习遗留代码的重构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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