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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A Million Lines of Bad Code

175 点作者 var_explained大约 10 年前

31 条评论

swalsh大约 10 年前
I recently read the book &quot;How to Win Friends &amp; Influence People&quot;, bad title great book. My main take away from this is I&#x27;ve been talking to people really badly for the last 27 years. I wish I had read this book in middle school.<p>But this blog reminded me of some of the concepts from the book, its far more productive to give positive encouragement than to give negative feedback, and just adding a complement isn&#x27;t enough if you follow it with a &quot;but&quot;.<p>&quot;Hey pretty cool program! Its a great start. I bet we can make it run faster if we changed the way files are imported to something like this... nice work&quot;<p>will get better results then this<p>&quot;Hey pretty cool program, but you&#x27;re reading in files wrong&quot;<p>which even that is better than this<p>&quot;You&#x27;re reading in files completely wrong, try googling for a better solution&quot; which unfortunately among engineers seems to be the most common reply.
评论 #9396935 未加载
评论 #9396908 未加载
评论 #9397009 未加载
评论 #9397036 未加载
评论 #9397554 未加载
评论 #9397025 未加载
评论 #9400198 未加载
评论 #9397125 未加载
评论 #9397033 未加载
评论 #9397013 未加载
评论 #9397031 未加载
评论 #9397110 未加载
评论 #9398987 未加载
评论 #9396939 未加载
评论 #9397028 未加载
cubano大约 10 年前
If only my clients and recent bosses would consider refactoring a valid billing line item...<p>I can only imagine sending an invoice today to my three top clients with &quot;5 Hours Refactoring Bad Code That is Working But Could Be Better Looking....$400&quot;.<p>There is just no way I would get paid.<p>Unfortunately, I have interests outside of working on code that mostly preclude me from sitting for hours happily breaking-and-then-refixing code that is currently working ok and that I cannot bill on.<p>Hell, just keeping up to date with the unreal pace of change that is occurring in software right now is almost a full-time job in itself, much less fixing old stuff that is going to go away soon anyway.
评论 #9397749 未加载
评论 #9397772 未加载
评论 #9397231 未加载
tatterdemalion大约 10 年前
&gt; So I wrote a Perl script that read in the file, combined it, and printed it out as a single line. Then I had my Java program call the Perl script through the command line, capture the printed output, and save that as the string.<p>When I first started (in Python), I didn&#x27;t understand what a function was, but I wanted my program to react differently depending on user input, and had some conception that I should be breaking my program up into files by purpose. So what I did to get it working was this: I named each file &quot;$cmd.py&quot;, then I concatted the user&#x27;s input with &quot;.py&quot;, opened &amp; read the file with the associated name, and ran the resulting string through exec() !!<p>I came to this result incrementally by googling different aspects of the problem that I didn&#x27;t know how to describe properly. If someone had been a jerk to me about it then, I probably would&#x27;ve been really self-conscious about it. But no one was a jerk, so I&#x27;m not ashamed: what I did is ridiculous and funny &amp; I&#x27;m glad to be able to laugh about it now.
评论 #9398824 未加载
ereyes01大约 10 年前
I agree that mean-spirited feedback is not helpful&#x2F;constructive. I can see how that would discourage someone who is new to programming. In fact, &quot;feedback&quot; is probably not even the correct name for that... maybe &quot;bullying&quot;.<p>However, I have to disagree with the notion of having to write a lot of shitty code to learn to write good code. Granted, that is one way to learn, but not nearly the most effective way to learn.<p>For years, when I started my career, I wrote lots of shitty code. I feel badly about having done this because I unwittingly caused quite a bit of havoc in the products I was working on, and even pissed off a few customers along the way. Writing shitty code can have really bad effects on a team and on a product.<p>Fortunately for me, I eventually ended up working in an extremely talented team. They were not only talented at programming, but also highly skilled at teaching others good programming. Their method was simple- they accepted nothing that failed to meet their high (and documented) standards of readability and testing, but were extremely thorough in spending time showing you what you did wrong. They were never demeaning and always constructive- they always had a high level optimism in every new-comer&#x27;s potential. Given enough time, it was clear that some new team members weren&#x27;t going to work out, but those who had it in them to patiently improve their skills flourished and enjoyed very successful stints with this team.<p>After a rough first few days on the team, I heeded their warnings and agreed to check my misplaced ego at the door. Then, and after a couple of months of embarrassing ineffectiveness, I gradually became a better programmer and went on to become a great team member. I&#x27;m really grateful for the patience these guys had with me and the other noobs. They really made a difference in my career and in the career of my peers!
评论 #9397880 未加载
JoeAltmaier大约 10 年前
Not quite right. All the code I wrote last year looks bad to me; naieve, clumsy, artless. Because I have learned so much since then. It never gets any better. Not because I don&#x27;t get better; because I DO get better.<p>I&#x27;ve been writing code since 1976.
评论 #9397296 未加载
jackreichert大约 10 年前
More important than good code is shipped code.<p>I&#x27;d say about half my bad code is due to inexperience, what the post is referring to. As time goes on it DOES get better, especially since -- like most of you -- I&#x27;m constantly reading and trying to improve my skills.<p>The other half of my bad code is due to time constraint. This is either because a quick hack is needed, or the proper planning time is not allocated to do a proper job.<p>This leads me back to my initial statement. Sometimes you just need to get the job done. If you&#x27;re not good enough to do it right, but you hack it and it works, that&#x27;s good enough for now.<p>This is how systems get built poorly and bloat up, but there are deadlines and requirements that need to be met, and if you never ship, you&#x27;ll never get the budget to rebuild that old system you allowed to get unwieldy. It&#x27;s a constant struggle to balance quality, functionality, and deadlines.
评论 #9398907 未加载
dap大约 10 年前
There are some useful ideas here, and public shaming per se probably isn&#x27;t the answer. But publicly talking about bad code, and the properties of code that makes it bad, is an important way to socialize what makes good code, plus the meta fact that code quality is important.<p>To the extent that the aphorism about writing bad code is true, I think it&#x27;s just another way of saying that people&#x27;s code improves with their coding experience. I really don&#x27;t think you need to write bad code _in order_ to learn to write good code. It&#x27;s hard to know for sure, but I think the most positive influence on my code quality was _reading_ lots of very good code, not having written bad code. (It&#x27;s the same with my writing, too.)<p>[Edited for clarity, ironically.]
angersock大约 10 年前
I think this is reasonable, but at the same time, <i>please</i> get those million lines out of your system on somebody else&#x27;s project.<p>If that can&#x27;t be done, if you can&#x27;t spend your free time honing your abilities, then accept helpful feedback from other more experienced developers. Don&#x27;t just accept feedback--assume your code is garbage, and ask how you can make it better. If the answer eventually becomes &quot;it&#x27;s good enough for business purposes&quot;, then find out why that is, and learn from <i>that</i>.<p>Communication is hard, and explaining why a codebase is just wrong can be as difficult as explaining to somebody why you find them abrasive.<p>At the same time, it&#x27;s the job of senior engineers to make the effort and <i>try</i>.<p>Sadly, in a startup environment, it&#x27;s usually smarter business-wise in the short-term just to sack the inexperienced developers or railroad them into simpler work that they can&#x27;t screw up, and kick the can down the line.
alarge大约 10 年前
I&#x27;m not a real fan of assigning a context-independent global value label like &quot;good&quot; or &quot;bad&quot; to code. While there probably are examples of truly &quot;bad in all respects, in any context&quot; code, the vast majority of code that I&#x27;ve seen tends to fit more into &quot;&lt;this attribute&gt; of the code could&#x2F;should probably be improved when using it in &lt;this context&gt;&quot;.<p>I find that viewing (and discussing) code this way has a lot of benefits:<p><pre><code> * It is really hard for a single global negative value judgement made about code to not be taken personally by the person who wrote it (e.g., &quot;your code sucks&quot; == &quot;you suck&quot;). This is much easier to avoid when talking about attributes of a thing, since (a) it comes across as more objective than subjective, (b) gives plenty of opportunities for acknowledging aspects of the code that _don&#x27;t_ suck, and (c) lends itself to much more of a &quot;give and take&quot; discussion. * It gives you the opportunity to talk about &quot;figures of merit&quot; and trade-offs that are the reality of engineering, but rarely taught in schools (e.g., readability&#x2F;development cost&#x2F;flexibility vs. performance, etc.) * It gives you a framework for explaining why things like idiomatic style, &quot;principle of least astonishment&quot;, and general elegance actually contribute to code quality (and aren&#x27;t just excuses for subjective attacks).</code></pre>
Zelphyr大约 10 年前
Code is art and every artist wants to go back and redo their bad works[1]. But the best thing to do is learn and move on to create better art.<p>1: <a href="https:&#x2F;&#x2F;www.yahoo.com&#x2F;movies&#x2F;bp&#x2F;steven-spielberg-finally-admits-walkie-talkies-were-mistake-142746809.html" rel="nofollow">https:&#x2F;&#x2F;www.yahoo.com&#x2F;movies&#x2F;bp&#x2F;steven-spielberg-finally-adm...</a>
autoreleasepool大约 10 年前
I don&#x27;t see anything wrong with the &quot;mean-spirited&quot; humor in the XKCD comic. The cartoon is funny. It&#x27;s <i>supposed</i> to be a joke. Anyways, it&#x27;s not like those remarks are directed at anyone in particular -- just a fictional stick figure. I don&#x27;t have any ethical qualms about laughing at his expense.
评论 #9397423 未加载
kstenerud大约 10 年前
I kept some of my original bad C, asm, and REXX code back from my high school days after I finally moved on from BASIC in 1991. I pull it out from time to time for a quick chuckle.
ianstallings大约 10 年前
You have to have thick skin in the programming industry. Because you&#x27;re surrounded by what might be the world&#x27;s worst communicators, programmers. We can tell the machine exactly what to do, but our social IQs tend to suffer on the whole.
评论 #9396894 未加载
评论 #9397090 未加载
评论 #9398198 未加载
dvirsky大约 10 年前
I have here some 10 year old C++ code I&#x27;ve written lying around. It&#x27;s pretty terrible style-wise, but not as bad as I imagine it to be without looking at it.<p>But the main point is that it worked in production for years. I would have written it much better today, and it will probably work faster and be easier to maintain. But it would also probably take longer to develop (though less time to debug and stabilize) - and ultimately, it would do the same work in production.<p>I&#x27;m not saying that improving your coding style and skills is not important. Just that we need to keep our eye on the ball - which is delivering working software, not code.
hnal943大约 10 年前
There&#x27;s a difference between practice and mere repetition. You wouldn&#x27;t get any better at speaking Russian if you just spoke gibberish, even if you did it for 10 years. You need to know what improvement looks like.
kctess5大约 10 年前
1000000 lines of bad code is a bit of an exaggeration. Many (most?) programmers never write that much code in their entire careers. I&#x27;ve heard 10000 LOC as a milestone for REALLY learning a language (once you&#x27;re familiar with programming in general), I&#x27;d say it&#x27;s on that order of magnitude for writing non-terrible code in general.
评论 #9397159 未加载
评论 #9396963 未加载
stuff4ben大约 10 年前
I&#x27;d hate to see my old VB4 code I wrote back in the day. I&#x27;m sure I did worse, except at the time I thought I was a rock-star. Of course it was the late 90&#x27;s and everyone who had a compsci degree was a bad-ass developer no matter what language you used or how many bad lines of code you wrote.
naiyt大约 10 年前
I remember reading some advice like this around the time I started programming. It was something along the lines of &quot;every dev has XXXXX lines of bad code in them, so write a lot of code to get them done with!&quot;. (I think it was from Joel Spolsky, IIRC.) It helped motivate me to just write a ton of code, even early on when I didn&#x27;t really know what I was doing. Just writing a bunch of code without worrying too much about if it&#x27;s &quot;right&quot; or not is really important, at least early on.<p>I think I write better code now because I spent so much time just writing stuff early on, and learning from my mistakes. That, along with some good mentors helped me so much more than the people that merely criticize you because of your code. I definitely agree with this article.
based2大约 10 年前
Why not use Findbugs[1] by default, it is now well integrated in major IDEs?<p>[1] <a href="http:&#x2F;&#x2F;findbugs.sourceforge.net&#x2F;" rel="nofollow">http:&#x2F;&#x2F;findbugs.sourceforge.net&#x2F;</a> [2] <a href="http:&#x2F;&#x2F;softwarerecs.stackexchange.com&#x2F;questions&#x2F;2902&#x2F;static-code-analysis-integrated-with-github" rel="nofollow">http:&#x2F;&#x2F;softwarerecs.stackexchange.com&#x2F;questions&#x2F;2902&#x2F;static-...</a> [3] <a href="https:&#x2F;&#x2F;github.com&#x2F;LMAX-Exchange&#x2F;freud" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;LMAX-Exchange&#x2F;freud</a> [4] <a href="http:&#x2F;&#x2F;spoon.gforge.inria.fr&#x2F;" rel="nofollow">http:&#x2F;&#x2F;spoon.gforge.inria.fr&#x2F;</a>
everyone大约 10 年前
The xkcd thing is just one webcomic, I reckon it is just a joke and probably Randall Munroe did not consider its implications or think it would be taken seriously. Though xkcd is really popular and probably is relatively influential (especially in programming circles) That being said, I totally agree with this article. Also &#x27;read a style guide&#x27; is one of the worst possible suggestions I could think of. Style is just style. Its one of the least important things I could think of. It depends on your work situation but in many cases why not just go with whatever style you are happy with personally and makes sense to you.
steakejjs大约 10 年前
What if you are an experienced engineer talking to another experienced engineer ?<p>Seems to me if someone writes bad code when they SHOULD be writing good code, code-shaming might be in order.<p>I&#x27;m all for being nice and understanding. Everyone programs at a different level and I may not write code that is as good as I think, but some code is just obviously bad...and constructive criticism (if willing to be accepted) might help
serve_yay大约 10 年前
Yeah, you shouldn&#x27;t shame people because their code is bad. But the other side of that is when someone says your code is bad you don&#x27;t take it personally. There is more than one way to not be a nice person.<p>Just think, if everything is pretty good and isn&#x27;t <i>that</i> bad and doesn&#x27;t need <i>that</i> much improvement, why should anything ever get any better, ever?
halosghost大约 10 年前
This times a million. I love helping people to learn C, for example. And the thing I do most other than basic instruction is helping to keep their spirits up and reminding them that refactoring is the most important part of coding.
killertypo大约 10 年前
one of my first projects as a consultant fresh out of college was HORRIBLY coded by my standards today. Sometimes I still fire it up and it still works (which fills me with pride); however, perusing the code hurts my eyes and I often wonder what was going through my mind.
eduadecastro大约 10 年前
Shouldn&#x27;t the compiler recognize this as an append instead of copying every time?
评论 #9399278 未加载
tanglesome大约 10 年前
That&#x27;s all true, but the cartoon is still funny!
moron4hire大约 10 年前
This is why my handle is &quot;moron4hire&quot;. It&#x27;s supposed to be a daily reminder to myself that I&#x27;m not that hot.
eonw大约 10 年前
good read, thanks for posting.
michaelochurch大约 10 年前
Bad code is a great wedge for business people to get programmers obsessed with individual relative ranking and prevent any sort of collective action.<p>I certainly had jobs in the past where I got <i>angry</i> over bad code when, in fact, I should have been bad at the businessmen making me use the bad code (instead of putting time on the calendar to write things properly) and setting the deadlines that caused the bad code.<p>For sure, there are some sloppy, borderline-unethical engineers who write shitty fast code to get promoted away from the maintenance messes they generate... and there are definitely some incompetent engineers. For the most part, though, bad code is a symptom of bad leadership rather than bad programmers. Under a tight enough deadline, everyone&#x27;s code will be shit.<p>And, of course, it goes without saying that the proper response to bad code isn&#x27;t to flip out on the person, but to teach him how to do it better. One of the reasons why I like using high-productivity languages like Haskell rather than Java is that it selects for people who genuinely want to improve.
woliveirajr大约 10 年前
Thought his was talking about win95 or win98...
评论 #9396893 未加载
ExpiredLink大约 10 年前
&gt; <i>Building a string with a series of concatenations like this is extremely inefficient</i><p>No. Not in Java since 1999 or so.
评论 #9397105 未加载
评论 #9397185 未加载
评论 #9396936 未加载