TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Is There a LeetCode for Refactoring?

15 点作者 remolacha超过 4 年前
I’m looking for some samples of realistic messy code (preferably with some sample well-refactored solutions) so I can practice refactoring legacy code, applying functional programming principles, etc. Anyone know of a resource for something like this?

6 条评论

dave_sid超过 4 年前
Most code bases in most companies.
评论 #24477507 未加载
评论 #24477505 未加载
chrisbrauns超过 4 年前
I don&#x27;t have a full &#x27;LeetCode&#x27; style example, but the Gilded Rose Kata teaches me something every time I try it.<p>Original Kata: <a href="https:&#x2F;&#x2F;iamnotmyself.com&#x2F;2011&#x2F;02&#x2F;14&#x2F;refactor-this-the-gilded-rose-kata&#x2F;" rel="nofollow">https:&#x2F;&#x2F;iamnotmyself.com&#x2F;2011&#x2F;02&#x2F;14&#x2F;refactor-this-the-gilded...</a> Sandi Metz&#x27;s Take: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=8bZh5LMaSmE" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=8bZh5LMaSmE</a>
tucif超过 4 年前
If having the solutions is not a must, you could take a dive in trending oss repos. (<a href="https:&#x2F;&#x2F;github.com&#x2F;trending" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;trending</a>)<p>I’d say to look for high coverage pieces, so that you prove your refactor is not breaking things.<p>Then ask for code review, maybe in something like <a href="https:&#x2F;&#x2F;codereview.stackexchange.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;codereview.stackexchange.com&#x2F;</a>
typedef_struct超过 4 年前
Your own code from 6 months ago usually works.
miguendes超过 4 年前
I was thinking about this a couple of weeks ago. The difference would be in the format. I am considering creating a repo with refactoring katas. The most difficult part is to come up with examples that show up in real codebases.
shoo超过 4 年前
there isn&#x27;t a single way to refactor code, code can be refactored in many different directions to pursue many different objectives.<p>Here&#x27;s a few arbitrary ideas:<p>* Scrape_it is an arbitrary python project that shows up in google search for &quot;pypi scrape&quot; [1]. Looking at the code, it doesn&#x27;t appear to have any automated tests. Goal: write a single unit test for the example of usage shown in the readme. The unit test should work without any dependency on : network access to remote websites or other services running locally, the current time, data files in the filesystem. Refactor by making minimal safe changes to the code as&#x2F;if required in order to write a unit test.<p>* scipy&#x27;s vendored copy of the useful L-BFGS-B optimisation algorithm [2] has a bunch of calls to a timer(ttime) subroutine, but the timer(ttime) subroutine was patched so it doesn&#x27;t do anything. But there&#x27;s still many calls to timer(ttime) throughout the lbfgsb.f code. Goal: simplify the code by identifying if any remaining variables and code related to cpu timing within lbfgsb.f can be safely removed without changing the behaviour of the algorithm. If it can be safely removed, remove it. Tricky: demonstrate with some degree of confidence that your change is safe and doesn&#x27;t break behaviour!<p>* fixCache, featured on HN a few days ago [3], includes a rule to decide if a git commit is a &quot;fix commit&quot; based on user-supplied keyboards identified in the commit message. Goal: modify fixCache to make this functionality more flexible, so a user can still configure fixCache to use the current behaviour, but can also optionally configure fixCache to call a custom user-defined javascript function that can decide if a commit is a &quot;fix commit&quot; or not using all information available about the commit (e.g. which files were touched, the contents of the changes to those files, etc) instead of a list of keywords. Refactor as&#x2F;if necessary to implement this feature.<p>Further reading: <a href="https:&#x2F;&#x2F;testing.googleblog.com&#x2F;2008&#x2F;07&#x2F;how-to-write-3v1l-untestable-code.html" rel="nofollow">https:&#x2F;&#x2F;testing.googleblog.com&#x2F;2008&#x2F;07&#x2F;how-to-write-3v1l-unt...</a> , Michael Feathers&#x27; book &quot;working effectively with legacy code&quot;: <a href="https:&#x2F;&#x2F;ptgmedia.pearsoncmg.com&#x2F;images&#x2F;9780131177055&#x2F;samplepages&#x2F;0131177052.pdf" rel="nofollow">https:&#x2F;&#x2F;ptgmedia.pearsoncmg.com&#x2F;images&#x2F;9780131177055&#x2F;samplep...</a><p>[1] <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;scrape-it&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;scrape-it&#x2F;</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;scipy&#x2F;scipy&#x2F;tree&#x2F;f865e9ed01be30c52f2b3841795aa2d8f5fa3d86&#x2F;scipy&#x2F;optimize&#x2F;lbfgsb_src" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;scipy&#x2F;scipy&#x2F;tree&#x2F;f865e9ed01be30c52f2b3841...</a> [3] <a href="https:&#x2F;&#x2F;github.com&#x2F;aavshr&#x2F;fixCache" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;aavshr&#x2F;fixCache</a>