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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Refactoring: How do I even start?

29 点作者 thclark大约 10 年前

11 条评论

a_bonobo大约 10 年前
I can only recommend Feathers&#x27; Working Effectively With Legacy Code, which far expands on OP&#x27;s themes, notably OP is missing tests - how can you improve on existing code when you don&#x27;t even know that it works like it says it works?<p>In some cases it shows its age (especially when it comes to rolling your own mock testing, most languages have automated frameworks for that now), but it&#x27;s still a great overview of the techniques you can employ.
michaelvkpdx大约 10 年前
All professional programmers should continually read Martin Fowler&#x27;s &quot;Refactoring&quot;, in the same way English professors read Shakespeare.<p>&quot;Refactoring&quot; does not mean &quot;previous programmer was an idiot&quot;. Often, the understanding of the problem and the way the code is used change over time. Refactoring is a way of bringing the out-of-control weeds back into healthy symbiosis with the larger garden of code.<p>I stopped telling clients a long time ago that I&#x27;m &quot;refactoring&quot; and instead I just add some extra time to all tasks to account for refactoring on legacy code.
zerohp大约 10 年前
I know this code is just an example, but it seems like it&#x27;s entirely backwards. The &quot;bad&quot; code at the beginning is immediately clear in what it&#x27;s doing, but the refactored code is significantly longer and hard to understand.
crdoconnor大约 10 年前
He missed step #1: write some tests that will provide feedback if you broke something, or assurance that you didn&#x27;t.
评论 #9305056 未加载
评论 #9311321 未加载
mbesto大约 10 年前
Sandi Metz talk &quot;All the Little Things&quot;[0] is amazing for understanding the general concepts around refactoring OOP code. It&#x27;s ruby centric, but the concepts are applicable to all OOP languages. The most interesting part is the fact that during the refactoring process you should actually increase the amount of code and complexity to eventually consolidate and aggregate it down. This as opposed to simply trying to delete&#x2F;mutate code.<p>[0] - <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>
pmr_大约 10 年前
<p><pre><code> if( masterList[z].list2 != NULL &amp;&amp; masterList[z].list2.length() &gt; 0 ) { for( Integer y = 0; y &lt; masterList[z].list2.length(); y++ ) </code></pre> The if-statement is a good summary of what is wrong with Java. The author doesn&#x27;t even notice that the second argument of &amp;&amp; is redundant and keeps it in the &quot;refactored&quot; version as well...
评论 #9304579 未加载
评论 #9304843 未加载
评论 #9304614 未加载
评论 #9304816 未加载
limeyx大约 10 年前
#1 If there are existing test cases - Run them - make sure they pass - make sure it looks like they have good coverage<p>#2 if there are no good test cases, write them and go to #1
pnathan大约 10 年前
Worth noting: some shops will summarily reject on code review any refactor that isn&#x27;t part of the ticket&#x2F;issue.
评论 #9304847 未加载
g8gggu89大约 10 年前
Why does he keep using Integer instead of int? And why use Object everywhere instead of generics?
OJFord大约 10 年前
I&#x27;m so frustrated by the minimum width, that I&#x27;m commenting instead of reading.
TeMPOraL大约 10 年前
&lt;&lt;So-Called &quot;Programmer&quot;&gt;&gt; is the name of the blog; the title of submitted post is &quot;Refactoring: How do I even start?&quot;. Could mods change this please?
评论 #9304569 未加载
评论 #9304745 未加载