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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How terrible code gets written by sane people

197 点作者 SarasaNews超过 8 年前

26 条评论

JamesBarney超过 8 年前
I like the article but I found the implied solution a little humorous.<p>Just hire devs who are great coders, great communicators, stubborn enough to push back against upper management, good hearted enough to sacrificed their own KPIs to focus on the success of their project, and massochistic enough to stick it out at an obviously poorly run project.<p>Good luck<p>Side note, for 15 years of experience the project doesn&#x27;t seem that bad by a long shot. I only have ~7 years of experience and have seen some far worse code. I was just recently on a project that has some methods that take 8 call backs(project was greenfielded in Jan 2016) before that I was on a project where the development team copy and paste the source for the last web page every time they needed a new one, but not delete the initialization code that fetched the data from.the database. So the 18th screen they worked on had 26,000 lines of code and took 5 minutes to load. And every button click triggered a reload. So, add a new widget and boom, wait 5 minutes for a screen refresh.
评论 #13681182 未加载
评论 #13681981 未加载
评论 #13681592 未加载
评论 #13683458 未加载
dahart超过 8 年前
It feels like people are focusing on bad conditions and unreasonable deadlines, and not the idea that in the real world smart people under execellent conditions do this very, very frequently.<p>I&#x27;ve worked for long periods of time in 3 codebases that were over 2 million loc in my career, all had great conditions, all had very smart people. Those are not huge codebases by any standard, and yet all 3 had people talking about ground up rewrites. All 3 had people complaining about every single example the author used. Two of them undertook the ground up rewrite estimating one year. Both admitted to having made a huge mistake 3-5 years later.<p>My theory is that <i>all</i> software eventually becomes difficult to maintain and full of warts, regardless of smartness, regardless of conditions. We all have code ideals we believe and talk about that don&#x27;t work as well in the real world as we imagined. We all have deadlines that are shorter than we want -- it&#x27;s a universal constant. We all imagine we can write code and fix big problems faster than we really can. And we all fail to fully understand what&#x27;s working right in a messy large codebase and tend to focus on what&#x27;s wrong.<p>I don&#x27;t know how to fix this, but it&#x27;s very possible the author ran into thoughtful paradigms he just hadn&#x27;t seen before and didn&#x27;t fully understand. Some styles seem messy if you haven&#x27;t seen them before.<p>React is an intentional lack of separation of concerns between code and markup. Some projects are <i>required</i> to mix tabs and spaces depending on tools. For that matter, bash scripts alone require mixing tabs and spaces for some features. And so on, it&#x27;s important to have context for why things are the way they are before jumping to the conclusion that it&#x27;s bad.
评论 #13681185 未加载
评论 #13681461 未加载
评论 #13681477 未加载
评论 #13681489 未加载
评论 #13683617 未加载
评论 #13682032 未加载
评论 #13682242 未加载
dsego超过 8 年前
I work on a lot of projects like this. The non-techies running the project are usually clueless and programmers are out of touch with modern best practices. The funny thing is that it makes me look slow for not finishing tasks. People in charge want to see features banged out. The guys who write hundred-line if-defs or copy&#x2F;paste code from one file to another, get to go home at 5pm and live their life. Someone else picks up the tab later. When they need some info from the db, they just add an ajax call and some php function to fetch that and use jQuery to change it on page. I don&#x27;t even try to refactor this stuff, just breaks everything, so I go along. I won&#x27;t even say anything about cleaning it up, because it will be assigned to me, while the other guys pile on spaghetti code like there is no tomorrow, good luck merging that.
评论 #13680746 未加载
joeax超过 8 年前
<i>Focusing on poor metrics such as “issues closed” or “commits per day”</i><p>I once worked at a company that used an offshore company to work on certain modules of a large project. They would commit code that my team would have to then code review. We&#x27;d see things like large IF-ELSE blocks with minor differences among the conditions (sometimes just one char). I know everyone hates this.<p>Turns out their internal metric was lines of code per day, so they&#x27;d bloat the shit out of everything.
评论 #13680528 未加载
erikb超过 8 年前
Honestly, I think the best developers are not the ones that write beautiful code and put quality above everything else. The best ones are the ones that can push out a solution given too little time and given a (maybe self inflicted) bad code base. Because that&#x27;s real life, and not the pony farm. Money trumps everything else in capitalism. Getting money means paying your bills today. And even more so than skill, quality and code getting money requires kowtowing and overpromising to someone who currently has money.<p>Second comes qualifying for the money (yes, in real world you get money without having what you are selling, but that&#x27;s a short-term success). That means getting to ask for money again tomorrow. That is where skill and code come into play. You promised something and now when you are lucky you can deliver 80% of that. Push hard to get there. Not everybody who tries will achieve that much.<p>And only then comes quality, which means qualifying for money next year becomes cheaper.<p>If you realize LIFE is that way, suddenly high quality isn&#x27;t all that important anymore, is it? Quality is a luxury and you must have achieved A LOT to be in a position to just think about quality. And the ohter people (management, sales) are not total idiots. If you dream the high quality dream they are the people who pay your bills.<p>I am an engineer like you, btw. I was just in the situation already, where I had to pay my bills myself and therefore know what amount of humiliation and sweat is required to get money just for ONE person, me.
评论 #13681165 未加载
评论 #13680960 未加载
评论 #13681021 未加载
SatvikBeri超过 8 年前
One thing I&#x27;ve been thinking about more and more is code that&#x27;s easy to delete.<p>For example, we recently built a data pipeline that did a bunch of processing and wrote data to a SQL database at the end. For various reasons, there was an unscalable, quick way to implement the write, and a scalable, slow way to do it. We wanted to get the product to testing ASAP, so we chose the quick way initially.<p>In order to make sure that we could easily replace that code, we ended up creating a separate write function for each table, where the function did nothing else except the write. That involved a lot of duplication, but made it easy to move the tables over to a better method one by one later.<p>It seems like having functions with one purpose, pure if possible, is a pretty good way to ensure &quot;upgradeable&quot; code–even if the internals of the function are messy, you just have to write a new one that copies the same functionality. Furthermore, I&#x27;ve found single responsibility functions to be easier to enforce in code reviews than single responsibility classes.
评论 #13681353 未加载
评论 #13682332 未加载
评论 #13682387 未加载
alexeiz超过 8 年前
* Giving excessive importance to estimates<p>Seen this one. It was used as a excuse not to do code reviews because they cause to miss estimates. &quot;Look, the feature is done, but because of the code review requirement I cannot mark it &#x27;done&#x27; in the project plan.&quot; Solution: abolish code reviews.<p>* Assuming that good process fixes bad people<p>This one is a big one. It&#x27;s everywhere. Especially in big software development companies, such as Microsoft and Google. They tend to believe that once they institute a perfect process, everything works out perfectly. Perfect coding guidelines lead to perfect code, no matter who writes it. Perfect testing process - testing can be done by monkeys. Perfect project management process - now we can hire project managers with just basic Microsoft Excel skills. They don&#x27;t understand that without actual talent the company enters a &quot;spiral of death&quot; which is impossible to escape.<p>* Ignoring proven practices such as code reviews and unit testing<p>This is done frequently by people who never tried such techniques as code reviews and unit testing. If you do it consistently through, say, one release cycle, you start to value those techniques and understand their importance.<p>Unit testing, for example, helps me to avoid painful debugging complex issues in production. All features that I unit tested usually just work when integrated into the rest of the product. In fact, the last bug I had to fix happened in code that I neglected to unit test, because the unit test setup was too complex for that component (in itself an indirect sign of a problem). Unit tests also lead to components usable independently of each other, thus reducing the overall system coupling.<p>* Hiring developers with no “people” skills<p>This is a double edged sword. On one hand a developer who can&#x27;t communicate well will eventually produce code that doesn&#x27;t do what&#x27;s intended. On the other hand there are people with too much &quot;people&quot; skills who can&#x27;t code shit. They just bullshit their way through. I&#x27;d say there are too many of such bullshitters. A lack of communication skills in a developer is a problem fairly isolated to that developer. A lack of coding skills in a bullshitter is much bigger problem that affect many people around him.
arcanus超过 8 年前
All good examples (such as excessive importance to deadlines, a big no-no).<p>My question: can they be truly good programmers of they write bad code? Isn&#x27;t the essential product of a programmer SLOC and functionality via software? And if they do that in a manner inferior to another dev, isn&#x27;t that objectively a measure of inferiority in their craft?<p>I&#x27;ve met far too many &#x27;good&#x27; programmers who were a net <i>detriment</i> to a project not to be wary of the term.
评论 #13680315 未加载
评论 #13680558 未加载
评论 #13681061 未加载
评论 #13680584 未加载
lettersdigits超过 8 年前
a good programmer should be able to identify bad companies to work for, which could solve many of the issues displayed in the article. it&#x27;s much like choosing a good life partner - choosing a good life partner (instead of a crazy one) will save you from many troubles that you would encounter if you married the wrong person in the first place.<p>ps: i need to tell this more to myself. i already made bad choices regarding where i work, which forced me to quit those jobs at the end..<p>(edit: spacing)
评论 #13680825 未加载
评论 #13680830 未加载
partycoder超过 8 年前
Imagine you have a sales team. Initially you tell them: sell $10000 in 1 week. Most of them will go through the traditional selling process. One of them will make a loan on behalf of the company for $10000, and hand you the money right away.<p>If you are smart, you will say that you are not interested in having that money if it comes from a loan. If you are not smart, you will say: &quot;wow, this guy is a 10x salesman, we will give him a bonus&quot;. Meanwhile the company gets into an unpayable debt beyond any possibility of paying.<p>Then, when the company is about to die from debt, they declare bankrupcy and start over or sell themselves to be acquired.<p>Now, imagine it&#x27;s not salesmen, but software engineers, and it&#x27;s not actual debt, but technical debt, and it&#x27;s not bankruptcy but starting your project again.
codingdave超过 8 年前
The other way terrible code gets written by good developers is focusing more on deliver working code that meets the business needs, more than elegant code that meets the needs of future maintainers.<p>Ideal code meets both. I&#x27;m sure we all agree on that. But when working on deadlines, under pressure, with poor management, you sometimes write bad code. And if the code is 15 years old, that great engineer you are talking about today was, at the time, an inexperienced new coder. So you didn&#x27;t inherit his greatest work. You inherited his embarrassment where he made mistakes.<p>I suspect the original authors of the terrible code in question could give much deeper insights into exactly how and why it was done that way.
lunz超过 8 年前
Perhaps the team planned a rewrite long ago and stopped worrying about the quality of their code, which seemed obsolete in the moment it was written. Over the years, however, there was always something more important than the &quot;soon-to-be&quot; rewrite.
Animats超过 8 年前
Converting Python to node.js seems terrible in itself. Converting to Go might be useful, if you need more performance or scalability.
评论 #13685366 未加载
pmarreck超过 8 年前
&gt; When I found out I would be working on porting an old Python codebase to Node<p>&quot;Out of the frying pan and into the fire&quot; is not a programming direction I would recommend. (I don&#x27;t think I&#x27;ve met a single Node developer who isn&#x27;t bitching about it.)
NumberSix超过 8 年前
A number of points in the post&#x2F;article are questionable.<p>First, it assumes the developers had substantial control over the schedule for the project (&quot;Giving excessive importance to estimates&quot;). Certainly in my experience this is unusual. More frequently, the schedule is dictated by management, frequently by sales&#x2F;marketing executives in commercial software development. It is <i>very</i> difficult to push back and a good way to lose your job.<p>Sales: We have closed this great deal with BigCorp. Can you do X (complicated, challenging software project) by the end of the quarter?<p>Developers: Err, um, X sounds like a project that will take six months.<p>Sales: We really need to make our quarterly numbers. Our CEO Bob used to be a developer and he says any <i>competent</i> programmer can do it and we only hire the best. Competent doesn’t cut it here! You are a rockstar ninja, aren’t you? Can you prove you can’t do it by the end of the quarter?<p>Developers: Well, no. The schedules are driven by some unexpected problem or problems that usually happen. But, well, if <i>nothing</i> unexpected happens, we can do it by the end of the quarter.<p>Sales: Great! Bob is expecting results by the end of the quarter.<p>So much for the beautiful, elegant software design methodologies taught in college and university CS programs and peddled by high priced consultants.<p>Second (“Giving no importance to project knowledge”), high technology employers seem to have extremely high turnover rates of software developers and other employers. Payscale produced a study claiming that the average employee tenure and Amazon and Google is only one year. Many companies seem to target employees with more than seven years of paid work experience — Logan’s Run style — for layoffs and “constructive discharge,” (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Constructive_dismissal" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Constructive_dismissal</a>) where employees are made uncomfortable and quit “voluntarily.” Undoubtedly, this is costly as the author implies, but it seems to be common practice.<p>Yes, metrics like “issues closed,” “commits per day,” or “lines of code” don’t work very well. Once employees realize they are being tracked and evaluated on some metric, they have a strong motivation to figure out how to manipulate the metric. Even if the employees don’t try to manipulate the metrics, the metrics all have serious weaknesses and map imperfectly to value added (biz speak).<p>Third, are code reviews and unit testing proven processes especially for normal non-Microsoft companies? In the early days of Test Driven Development (TDD), Kent Beck and his colleagues made numerous claims about the success of Test Driven Development in the Chrysler Comprehensive Compensation System (C3) payroll project, an attempt to create a unified company wide payroll system for Chrysler. This project in fact had a range of problems and was eventually cancelled by Chrysler in 2000, without replacing the Chrysler payroll systems successfully.<p>As the problems with C3 have become well documented and well known, TDD enthusiasts have shifted to citing studies at Microsoft and some other gigantic companies that claim practices like TDD and code reviews work well. Are these really true or do these case studies have hidden issues as C3 did?<p>Further, Microsoft, Google, and other companies that have played a big role in promoting these practices are very unusual companies, phenomenally successful super-unicorns with sales in the range of 40-100 billion (with a B) dollars with near monopoly positions and anomalously high revenues and frequently profits per employee. Microsoft claims to have revenues of $732,224 per employee. Google claims an astonishing $1,154,896 per employee. (<a href="http:&#x2F;&#x2F;www.businessinsider.com&#x2F;top-tech-companies-revenue-per-employee-2015-10&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.businessinsider.com&#x2F;top-tech-companies-revenue-pe...</a>) This compares to $100-200,000 per employee for most successful companies.<p>Fergus Henderson at Google recently published an article on Google’s software engineering practices (<a href="https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1702.01715" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1702.01715</a>) with the following statements:<p><i>2.11. Frequent rewrites</i><p><i>Most software at Google gets rewritten every few years.</i><p><i>This may seem incredibly costly. Indeed, it does consume a large fraction of Google’s resources.</i><p>Note: “incredibly costly”<p>Companies like Microsoft and Google have enormous resources including monopoly power and can follow practices that are extremely costly and inefficient, which may work for them. Even if these practices are quite harmful, they have the resources to succeed nonetheless — at least for the immediate future, the next five years.<p>From a business point of view, it may even be in the interests of Microsoft, Google, and other giant near monopolies to promote software development practices that smaller competitors and potential competitors simply can’t afford and that will bankrupt them if adopted.<p>Both code reviews and unit tests are clearly time consuming up front. Code reviews using tools like Google’s Gerrit or Phabricator (a spin-off from Facebook, another super-unicorn) are committee meetings on every line of code.<p>Regarding:<p><i>Imagine my dismay when I had to collaborate with a colleague on that legacy project and his screen displayed Notepad in its full glory. Using “search” to find methods might have been rad back in the nineties, but these days, refraining from using tools such as modern IDEs, version control and code inspection will set you back tremendously. They are now absolutely required for projects of any size.</i><p>Using “search” to find methods was not rad back in the 1990’s. IDE’s and code browsers specifically have been in widespread use since the 1980’s. Turbo Pascal (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Turbo_Pascal" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Turbo_Pascal</a>) was introduced in 1983 and featured a fully functional IDE, soon to be followed by IDE’s in many other products. Version control dates back at least to SCCS (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Source_Code_Control_System" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Source_Code_Control_System</a>) which was released in 1972. RCS was released in 1981 and version control was common in the 1980s and since.<p>Code reviews have been around for a long time. However, in the 1990’s and earlier they were restricted to relatively special projects such as the Space Shuttle avionics where very high levels or safety and reliability, far beyond most commercial software, were required. This speaks to the “incredibly costly” quote about Google above.<p>Without more context, it is difficult to evaluate the use of Notepad. Simple code&#x2F;text editors like Notepad and <i>vim</i> (formerly <i>vi</i> ) are very fast to start up and can be a better option for some quick projects than starting an IDE.<p>Some IDE’s are particularly hard to use. Early versions of Apple’s Xcode circa 2010 were particularly difficult to use in practice; it has improved somewhat in the current releases.<p>People vary significantly. Some developers seem to find stripped down tools like <i>vim</i> or Notepad or Notepad++ (on Windows) a better option than complicated IDE’s. I am more of an emacs or IDE person.<p>The fact that someone else works differently than you do does not mean they are worse (or better) than you. The fact that something works well for someone else also does not mean it will work well for you — or vice versa.<p>There are sound reasons for duplicating code, cutting and pasting, rather than creating a function or object called in several location in the code. If the developer anticipates that the code may subsequently diverge, then duplication is often best.<p>Like grand master chess players, highly experienced developers, especially under tight time constraints (like a chess tournament), code by intuition, not by laboriously reasoning out every step. If it feels like the code is likely to diverge in the future, duplicate. If it does not diverge, no problem, it can be merged back later if needed.<p>In the bad old days of structured design (1980’s) and object-oriented design (OOD — 1990s), software development projects suffered from Big Design Up Front (BDUF), grandiose attempts to design a perfect software system before writing a line of code. This often resulted in massive cost and schedule overruns and total failures. It often proves better to just throw (“hack”) something together quickly — a prototype, proof of concept, Minimum Viable Product (MVP). Just “get something working.”<p>Inevitably these prototypes and early stage software projects are going to compare poorly to some theoretical perfectly designed system with 20-20 hindsight. That is what seduced people into BDUF twenty, thirty years ago.<p>Modern Agile software development methodologies are foolishly trying to have it both ways, have an initial quick iteration BUT that first iteration should be perfectly designed up front — beautiful, elegant, with hundreds of tests, endless committee meetings on coding style and design (code reviews), all sorts of supposed best practices, no code duplication, etc. This is a seductive fantasy doomed to fail in most cases.
bartread超过 8 年前
I sort of lost the will to read further at this point:<p>&quot;An important component of this project was the focus on deadlines, even to the detriment of code quality. If your developers have to focus on delivering rather than on writing good code, they will eventually have to compensate to make you happy. &quot;<p>AAAAAAAARGH!!! Seriously? What do you think you&#x27;re there for?<p>Good code can be a means but never an end. Of <i>course</i> you&#x27;re there to deliver. And of course it&#x27;s more important to do that than to write beautiful code.<p>Give me strength.
mannykannot超过 8 年前
&quot;The authors created their own framework...&quot;<p>I cannot say this was an issue here, but I can say that some of the worst messes I have seen have followed from this decision. In all such cases in my experience, it was not a technically justifiable decision, and I strongly suspect it was driven by developer ego and overconfidence.<p>The very worst included a roll-your-own language.
评论 #13681387 未加载
评论 #13681875 未加载
doggydogs94超过 8 年前
The key word is &quot;deadline&quot;. Horrible code that works beats beautiful code that has not been thoroughly tested.
评论 #13681042 未加载
hinkley超过 8 年前
I work with a team that managed to write the code he describes in a little over three years. it&#x27;s really just chaos and I only trust a few of them. So why do I keep talking myself out of looking for a new job? Hell if I know.
EliRivers超过 8 年前
&quot;mixed spaces&#x2F;tabs for indentation&quot;<p>If that&#x27;s the second thing in the list of problems, the problems aren&#x27;t nearly so bad or the author&#x27;s got a savage case of mixing in the trivial with the important.
评论 #13687132 未加载
peter_retief超过 8 年前
I had a quick look at your commentary, its great, the whole issue of rushing code and debugging forever, also nice allusion to anti patterns :) I have bookmarked and will read properly very soon, maybe
macawfish超过 8 年前
I know how. Cause I just wanna get something done!<p>Then later I come back and rewrite it with a dose of <i>patience</i>. Then my code is much better.
jelder超过 8 年前
Mirror?
评论 #13681074 未加载
pfarnsworth超过 8 年前
This is a fucking arrogant article. I would love to see this blogger try to maintain a large codebase after several development cycles in the real world. To come into someone else&#x27;s codebase that has umpteen number of iterations and tough business realities like trying to make money, and proclaiming that it&#x27;s terrible code and how he would fix it, is delusional and self-aggrandizing.<p>Most production code needs to be revamped every few years because the subsequent unforeseen functionalities that was forced by product managers and customers. That code is usually going against the grain of the original code but you can&#x27;t blame the original designers because it was never spec&#x27;ed out. The best code is the code that is easiest to manipulate and modify, but even then it gets old and needs a rewrite. There&#x27;s nothing wrong with that, except thinking you can comment on the shitty code and thinking your above it and how you would never let it happen.
评论 #13680511 未加载
评论 #13680420 未加载
评论 #13680480 未加载
pmarreck超过 8 年前
The site is now 404&#x27;ing so I guess s&#x2F;he isn&#x27;t heeding their own warning?
评论 #13680714 未加载
评论 #13680823 未加载
sadfsa超过 8 年前
&gt;porting an old Python codebase to Node<p>Node is how.