TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Refactoring: How do I even start?

29 pointsby thclarkabout 10 years ago

11 comments

a_bonoboabout 10 years ago
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.
michaelvkpdxabout 10 years ago
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.
zerohpabout 10 years ago
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.
crdoconnorabout 10 years ago
He missed step #1: write some tests that will provide feedback if you broke something, or assurance that you didn&#x27;t.
评论 #9305056 未加载
评论 #9311321 未加载
mbestoabout 10 years ago
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_about 10 years ago
<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 未加载
limeyxabout 10 years ago
#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
pnathanabout 10 years ago
Worth noting: some shops will summarily reject on code review any refactor that isn&#x27;t part of the ticket&#x2F;issue.
评论 #9304847 未加载
g8gggu89about 10 years ago
Why does he keep using Integer instead of int? And why use Object everywhere instead of generics?
OJFordabout 10 years ago
I&#x27;m so frustrated by the minimum width, that I&#x27;m commenting instead of reading.
TeMPOraLabout 10 years ago
&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 未加载