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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: How do you deal with shit code?

5 点作者 rasulkireev将近 2 年前
Question for experienced programmers.<p>I am in the beginning of my career (3 years in, Mid Backend Engineer).<p>I just inherited a large project (52297 lines of python code) that was built by a few developers who just left the company. I&#x27;m in the process of fixing bugs (and learning about the code altogether).<p>Every time I&#x27;m working on a bug, I just want to re-write the whole thing since the approach prev. devs took feels so bad. Obviously I can&#x27;t do that, so I end up duct taping the existing thing. This is killing me.<p>So, here is the question: 1. In your engineering careers how often do you have to deal with shit code other people wrote? 2. If so, how do you deal with it? Psychologically and physically. 3. Are there any resources online that can help me structure my thoughts around this problem.<p>Thanks a ton in advance.

8 条评论

iforgotpassword将近 2 年前
So you have 3 years of working experience. How many code bases of similar size are you familiar with?<p>When working on a new code base of that size, figure out how old it is, and how the requirements changed over time. It might be more likely your don&#x27;t see the big picture of why things are done and structured the way they are. obviously, it would be great to have someone around to ask why every time your see something that doesn&#x27;t make sense or seems overly complicated or backwards. You don&#x27;t have that luxury. But try to get to know the code more.<p>Sure, you might be right and the code is just complete garbage, but I&#x27;m just reminded of how third semester CS students also know everything better as soon as they learn some pattern X and consider it the best and only way to do things. :-)
评论 #36034307 未加载
评论 #36034793 未加载
gregjor将近 2 年前
1. Shit code is in the eye of the beholder. Most programmers think code they didn&#x27;t write qualifies as shit. I see it as an opportunity. Learn it, fix it, make it better, that&#x27;s part of the job. What did you expect you&#x27;d be doing that makes this job seem so bad? A programmer who can competently work with legacy code without whining has a valuable and rare career skill, so get good at it and increase your value.<p>2. I don&#x27;t get invested psychologically in code, and certainly not physically. Get some perspective.<p>3. Martin Fowler&#x27;s book <i>Refactoring</i> has some good advice and techniques.
评论 #36038621 未加载
injb将近 2 年前
This is obligatory reading, and I would say at 3 years you&#x27;re probably exactly at that stage of your career when developers tend to be most susceptible to this mistake: <a href="https:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;2000&#x2F;04&#x2F;06&#x2F;things-you-should-never-do-part-i&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;2000&#x2F;04&#x2F;06&#x2F;things-you-should-...</a><p>The message in this is as true now as it was 23 years ago. Granted, the code in your case might not be the company&#x27;s flagship product for all I know, and maybe you should start from scratch, but definitely not until you&#x27;ve tried everything else.
评论 #36034610 未加载
评论 #36040115 未加载
bjourne将近 2 年前
&gt; This is killing me.<p>You should absolutely not continue doing something that is literally or figuratively killing you.<p>&gt; If so, how do you deal with it? Psychologically and physically.<p>Handling shitty code doesn&#x27;t affect me mentally and honestly I don&#x27;t see how it could affect anyone physically. It&#x27;s not like it causes you nausea or stomach pains, is it? However, feeling that my talents are wasted negatively affects my mood. I would not stand &quot;duct taping&quot; someone&#x27;s trash <i>unless</i> I were given the authority to refactor and fix the underlying problems with it.<p>Bottom line is that you should leave jobs that make you feel bad.<p>I will share a contrarian experience I had. I once had to maintain the tcp&#x2F;ip stack for an esoteric device running Linux. The stack was insanely complicated, with C code calling ksh scripts, etc. I was able the code&#x27;s authors why it was designed this way: Because Linux doesn&#x27;t let you assign more than one ip address to an interface. Except it does... The architect didn&#x27;t want to believe me when I told him that Linux has had this feature for over two decades. Eventually he realized I was right and apologized. So, all code is written the way it is for a reason, but that reason may not be a good reason.
alex_lav将近 2 年前
All code ends up as shit code. Misuse, poor maintenance, shifting contexts and rotating developers mean very little code stays good. It&#x27;s fine. Accepting that bad code is fine and should just be documented as an opportunity for refactor and moving on is the path to a successful career&#x2F;less frustrating life. You&#x27;ll watch code you wrote, that at the time was fine, become terrible after you move away from that area. It&#x27;s just a fact of life.<p>Also, you have 3 years experience, so you probably have very little understanding of what &quot;good&quot; and &quot;bad&quot; actually means, with respect to large software systems. Deadlines exist, priority calls need to be made, things have to be done for the sake of delivery. Not everything can be &quot;good&quot;, but lots of &quot;bad&quot; code is actually just fine.<p>&gt; (and learning about the code altogether)<p>If you&#x27;re saying this, stop saying things are bad. You don&#x27;t know what you don&#x27;t know.<p>Read this, internalize it: <a href="https:&#x2F;&#x2F;fs.blog&#x2F;chestertons-fence&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fs.blog&#x2F;chestertons-fence&#x2F;</a> By far the best resource I&#x27;ve ever found about thinking about legacy code.<p>&gt; 1. In your engineering careers how often do you have to deal with shit code other people wrote<p>It&#x27;s all shit, and most of the stuff we all write every day starts or becomes shit<p>&gt; 2. If so, how do you deal with it? Psychologically and physically.<p>Escape the trap of binary thinking and accept that code serves a purpose and if that purpose is being met, it&#x27;s fine.<p>&gt; 3. Are there any resources online that can help me structure my thoughts around this problem.<p>Linked above.
评论 #36039337 未加载
MrGuts将近 2 年前
I am about six years in on software dev career. Every so often, I&#x27;ll see something that makes me think, &quot;What fxcking animal wrote that?&quot;<p>Very often, a quick git&#x2F;blame shows my own name back to me.<p>Have patience, have mercy.
评论 #36039348 未加载
scrapheap将近 2 年前
&gt; 1. In your engineering careers how often do you have to deal with shit code other people wrote?<p>Almost as often as I have to deal with shit code I wrote :)<p>&gt; I&#x27;m in the process of fixing bugs (and learning about the code altogether).<p>This is exactly the way to deal with this situation. Until you understand the project&#x27;s architecture you can&#x27;t make an objective decision on how to improve things.<p>As you go along make sure that you&#x27;re adding in relevant tests so that when you are in a position to make an objective change you can make sure you don&#x27;t break the actual business logic of the project.
mattbgates将近 2 年前
My very first programming job was like this. The simple method is this:<p>Leave the code as is because if it ain&#x27;t broken, don&#x27;t fix it.<p>However, once you have to go into code and fix it, this is where you can re-write it, leave comments, maybe even put the old code at the bottom in a comment.<p>It&#x27;d be too much time and possible errors to fix everything, but if you can go in there and re-write some, maybe even make it more efficient, than you might be able to do it.