编码 Katas 用于练习重构遗留代码

发布于 2024-08-04 20:07:10 字数 333 浏览 2 评论 0原文

近几个月来,我对 katas 编码非常感兴趣。我相信它们是磨练我的编程技能和提高我编写的代码质量的好方法。

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

因此,我正在寻找一些 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

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

緦唸λ蓇 2024-08-11 20:07:10

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

  1. 在 sourceforge 上找到一个旧的、小型的、未维护的开源项目
  2. 下载它,让它编译/构建/运行
  3. 阅读文档,感受一下代码
  4. 使用有效处理遗留代码中的技术来测试其中的一部分
  5. 重构该部分,也许可以修复错误并添加功能
  6. 重复步骤 4 到6

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

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

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

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

  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.

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.

时间你老了 2024-08-11 20:07:10

Emily Bache 有一个 github 存储库,其中包含一些重构 kata:Emily Bache 的重构 Kata Repo。 KataYahtzee 和 KataTennis 有多种变体需要重构。此外,她还有镀金玫瑰型的变体,它被设计为重构型。

此外,她的存储库中还有 Racing Car Katas:Racing Car Kata。 Race Car Katas 还包括很好的重构练习。

这些 kata 具有多种语言的代码:

  • C++
  • C#
  • Java
  • Javascript
  • Python
  • Ruby

Emily Bache has a github repository with some refactoring katas: Emily Bache's Refactoring Kata Repo. There are variants of KataYahtzee and KataTennis to refactor. Also, she has a variant of the Gilded Rose Kata, which was designed as a refactoring kata.

Also, she has the Racing Car Katas in her repo: Racing Car Kata. The Race Car Katas also include good exercises for refactoring.

Those kata have the code in multiple langauages:

  • C++
  • C#
  • Java
  • Javascript
  • Python
  • Ruby
小嗲 2024-08-11 20:07:10

我感觉像是死灵法师在回复这样一个旧线程,但有一件事值得补充 - Legacy Code Retreat

想法是对遗留代码进行Code Retreat,并尝试练习处理此类问题的技术,但我看不到任何可以解决问题的方法。禁止您简单地使用准备好的代码并自行练习。仅使用它来创建 Golden Master 就需要一个小时的工作,而且您还可以做更多的事情。如果你的型通常持续大约 2 小时,我想说,只要将 LCR 上通常发生的事情分成型,就可以让你做四件不同的事情。

idea 的作者 JB Rainsberger 有一个 GitHub 存储库,其中包含您要使用的简单遗留系统 Trivia Game。

根据我作为组织者/参与者的经验,人们真的很喜欢这个,并且它很有启发性地了解遗留代码中可能存在的问题以及重构可能在哪里使您误入歧途(以及如何!)。这是 Andreas Leidig 的另一个关于它的外观的描述

I feel like necromancer replying to such an old thread, but there is one thing that would make for a worthy addition - Legacy Code Retreat.

Idea is to have a Code Retreat with legacy code and try to practice the very techniques for dealing with such, but I can't see anything that would ban you from simply using the code prepared and practicing with it by yourself. Just using it for creating a Golden Master makes for an hour of work, and there's a lot more you can do. If your kata usually last around 2 hours, I'd say just by splitting what usually happens on LCR into kata gives you four different things to work on.

There's a GitHub repository by idea's author, J.B. Rainsberger, that contains a simple legacy system that you are to work with, Trivia Game.

From my experience as organizer/participant, folks really liked this and it was illuminating to see what can be a problem in a legacy code and where your refactoring can lead you astray (and how!). Here's yet another account of how it looks like, by Andreas Leidig.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文