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.

Ask HN: Examples of bad open-source code to learn what to avoid?

66 pointsby theSageabout 6 years ago
What are some of the bad examples of code that you have seen? Something you would want to avoid?<p>I&#x27;m looking for examples which fall along the lines of &quot;fail to see the forest for the trees&quot;.

27 comments

neyaabout 6 years ago
I feel like this could lead to very opinionated, non-constructive comments&#x2F;flame, but if were to give you an example, I&#x27;d suggest taking a look at Wordpress eco-system. While Wordpress core&#x27;s codebase has improved significantly over the years, some of the plugins haven&#x27;t.<p>The top pick goes to WooCommerce, although an open source E-commerce solution on top of Wordpress, it has some terrible decisions under the hood.<p>The top pick would go to mixing presentational logic with business logic. For example, to render a table, instead of exposing an array of objects to allow the developer to loop through it as he&#x2F;she sees fit, WooCommerce will force you to use a PHP function that renders a table for you and there&#x27;s actually no way to modify the presentation logic if you wanted to.<p>It&#x27;s a really fundamental programming paradigm that even top open source companies fail to adhere to.<p>Again, I&#x27;m not saying this to attack them or the maintainers behind the code, just my opinion of why I think it&#x27;s bad quality code while respecting the fact that developers still do take time and effort for us to enjoy something with freedom and zero cost.
评论 #19952981 未加载
评论 #19952835 未加载
ben_baiabout 6 years ago
Always a crowd-pleaser: OpenBSD true.c vs. GNU&#x27;s true.c<p><a href="http:&#x2F;&#x2F;cvsweb.openbsd.org&#x2F;cgi-bin&#x2F;cvsweb&#x2F;~checkout~&#x2F;src&#x2F;usr.bin&#x2F;true&#x2F;true.c?rev=1.1&amp;content-type=text&#x2F;plain" rel="nofollow">http:&#x2F;&#x2F;cvsweb.openbsd.org&#x2F;cgi-bin&#x2F;cvsweb&#x2F;~checkout~&#x2F;src&#x2F;usr....</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;coreutils&#x2F;coreutils&#x2F;blob&#x2F;master&#x2F;src&#x2F;true.c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;coreutils&#x2F;coreutils&#x2F;blob&#x2F;master&#x2F;src&#x2F;true....</a>
评论 #19955105 未加载
codr7about 6 years ago
It doesn&#x27;t work, energy follows thought and it makes no sense to focus it on what you want to avoid. Take or leave.<p>That being said, the worst I ever saw was the in-house business nonsense I was paid to deal with as a Java consultant. The worst code isn&#x27;t open source from my experience, subjecting it to public scrutiny would mean suicide for the companies involved.
评论 #19953528 未加载
jasodeabout 6 years ago
An example of bad code that always stuck with me was the flawed CDDB disc id hash algorithm.[0]<p>I was reminded of that short-sighted decision every time I ripped a bunch of CDs and saw how importing song titles was <i>not automatic</i> because a dozen different discs had the same hash ids which resulted in collisions[1]. It ended up creating needless friction for millions that depended on that discid.<p>What&#x27;s sad is I&#x27;m not even sure if one can extract any useful &quot;lessons learned&quot; from it! The programmer that wrote it was not an amateur script kiddie; he had a computer science degree from Uni California. Apparently, he didn&#x27;t realize he was writing a flawed hash algorithm as he wrote it.<p>One could say that hash algorithms should be &quot;peer reviewed&quot;. Well, he got <i>unsolicited</i> peer review that pointed how his homegrown hashing computation was flawed but he <i>ignored</i> the suggestion to improve it.<p>[0] <i>&gt;Ti Kan wanted to use a hash. He could have chosen something like CRC32, which would have given him a 32 bit number, yielding 4 billion unique IDs. Instead he wrote his own hash. [...] Ti Kan was made aware (not by me) of this problem back in 1994, and given a script to convert this format into a CRC32-based format, but he rejected it because the deployed base was too big. At that point it was probably in the high dozens.</i> -- excerpt from <a href="http:&#x2F;&#x2F;quimby.gnus.org&#x2F;circus&#x2F;notes&#x2F;cddb.html" rel="nofollow">http:&#x2F;&#x2F;quimby.gnus.org&#x2F;circus&#x2F;notes&#x2F;cddb.html</a><p>[1] <a href="https:&#x2F;&#x2F;forums.macrumors.com&#x2F;attachments&#x2F;multiple-matches-jpg.17857&#x2F;" rel="nofollow">https:&#x2F;&#x2F;forums.macrumors.com&#x2F;attachments&#x2F;multiple-matches-jp...</a><p>[2] wiki: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;CDDB#How_CDDB_works" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;CDDB#How_CDDB_works</a>
评论 #19953231 未加载
AnaniasAnanasabout 6 years ago
Here you go <a href="https:&#x2F;&#x2F;github.com&#x2F;progwml6&#x2F;Natura&#x2F;blob&#x2F;1.7.10&#x2F;src&#x2F;main&#x2F;java&#x2F;mods&#x2F;natura&#x2F;common&#x2F;NContent.java" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;progwml6&#x2F;Natura&#x2F;blob&#x2F;1.7.10&#x2F;src&#x2F;main&#x2F;java...</a><p>Tip: If you ever end up in a situation where you have to copy-paste code with minor changes then there is something that you are doing wrong. In this case using arrays and loops would be a much better solution.
评论 #19953234 未加载
评论 #19952841 未加载
评论 #19953189 未加载
评论 #19954518 未加载
评论 #19952675 未加载
spionabout 6 years ago
How about examples of open source code to learn whats really, really good, together with why it was designed that way? Seems like that would be way more useful.<p>Or examples of projects that did things one way, but later refactored, and why they refactored.
评论 #19953948 未加载
评论 #19953150 未加载
kissgyorgyabout 6 years ago
That&#x27;s a really bad idea. You need to have a good counterexample, otherwise it&#x27;s just wasting time at the best case. A lot of people learn from really bad codebases and picking up the same style which is terrible. You should look at GOOD codebases instead!
评论 #19954719 未加载
otrasabout 6 years ago
If you’re interested in a case of unnecessary optimization and effort, the infamous left-pad npm library has been refactored to only add to the string O(log(n)) times. It is short but not sweet.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;left-pad&#x2F;left-pad#readme" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;left-pad&#x2F;left-pad#readme</a>
评论 #19954423 未加载
Sir_Cmpwnabout 6 years ago
Here&#x27;s some old code of mine:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;vatt849&#x2F;LibMinecraft&#x2F;blob&#x2F;master&#x2F;LibMinecraft&#x2F;Client&#x2F;MultiplayerClient.cs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;vatt849&#x2F;LibMinecraft&#x2F;blob&#x2F;master&#x2F;LibMinec...</a><p>The whole library is a trip if you want to read a bunch of bad C#. Highlights:<p>- Generated documentation<p>- Giant switch&#x2F;case instead of a more organized dispatch map<p>- Large swaths of commented code instead of using version control<p>- try...catch statements that just eat the errors<p>- Inconsistent code style<p>- This thing:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;vatt849&#x2F;LibMinecraft&#x2F;blob&#x2F;master&#x2F;LibMinecraft&#x2F;Client&#x2F;MultiplayerClient.cs#L603-L621" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;vatt849&#x2F;LibMinecraft&#x2F;blob&#x2F;master&#x2F;LibMinec...</a><p>I&#x27;ve written something similar from scratch since, which I&#x27;m still not entirely satisfied with, but is much better for reference:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft</a><p>The client-side networking code lives here:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft&#x2F;blob&#x2F;master&#x2F;TrueCraft.Core&#x2F;Networking&#x2F;PacketReader.cs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft&#x2F;blob&#x2F;master&#x2F;TrueCraft....</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft&#x2F;blob&#x2F;master&#x2F;TrueCraft.Client&#x2F;MultiplayerClient.cs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft&#x2F;blob&#x2F;master&#x2F;TrueCraft....</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft&#x2F;tree&#x2F;master&#x2F;TrueCraft.Client&#x2F;Handlers" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ddevault&#x2F;TrueCraft&#x2F;tree&#x2F;master&#x2F;TrueCraft....</a><p>Notable improvements:<p>- Handwritten docs only where necessary<p>- Uses a stream implementation for decoding this particular wire format<p>- Has a different and better abstraction for reading packets out<p>Still has bad error handling though.
slezyrabout 6 years ago
See Syobon Action it&#x27;s source code as bad as the game itself.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;angelXwind&#x2F;OpenSyobonAction&#x2F;blob&#x2F;master&#x2F;main.cpp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;angelXwind&#x2F;OpenSyobonAction&#x2F;blob&#x2F;master&#x2F;m...</a>
jstarfishabout 6 years ago
The source for Terraria is notoriously terrible.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;TheVamp&#x2F;Terraria-Source-Code" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;TheVamp&#x2F;Terraria-Source-Code</a><p>It is another example of how even inelegant code full of hardcoded values can be successful.
评论 #19956172 未加载
twhitmoreabout 6 years ago
Libraries can be useful despite imperfections, and poor design decisions can occur in overall good libraries. So we can&#x27;t judge too harshly.<p>Having said that:<p>1) iText PDF library used to have some fairly poor &amp; duplicated code. Column layout was a highlight. Also strange ideas overemphasizing subclasses, eg. for paragraph styles. (Correct approach: use values rather than types.)<p>2) Tomcat webserver back around 2007 used to have some amazing &#x27;clustering&#x27; code to deploy your webapp across multiple servers. But it lacked proper knowledge &amp; hence control of what it was doing. IIRC there was no clear master, and a server couldn&#x27;t tell what had been started on it versus what had been replicated since a peer was seen to be running it. Effect: replication would be additive only, contexts would just replicate everywhere uncontrolled, and there was no good way to stop&#x2F; undeploy an app across the cluster.
ddebernardyabout 6 years ago
OpenSSL (before HeartBleed) springs to mind.<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7640378" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7640378</a>
评论 #19953114 未加载
评论 #19958407 未加载
type0about 6 years ago
&quot;How to Make Mistakes in Python&quot; - <a href="https:&#x2F;&#x2F;www.oreilly.com&#x2F;library&#x2F;view&#x2F;how-to-make&#x2F;9781492048275&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.oreilly.com&#x2F;library&#x2F;view&#x2F;how-to-make&#x2F;97814920482...</a>
blattimwindabout 6 years ago
Drupal 6&#x2F;7 would be an example for &quot;widely used [at the time] but pretty bad&quot;. I don&#x27;t know how many of the issues across all layers were addressed in later versions.<p>OpenSSL is still an excellent example for very messy code where even maintainers &#x2F; frequent contributors regularly get lost. Also a good example for designing many bad APIs and poor docs. libsodium is a good counterexample, although the internal structuring of the code base is a bit atypical, it is logical and consistent. (It does have some API idiosyncrasies which cater specifically to dynamic bindings, like providing a constant always as a #define&#x2F;macro but also as an exported function; and it has a bit of an issue where you have both legacy APIs and newer APIs, but the docs are pretty clear on which is which).<p>BorgBackup is an example of how you don&#x27;t want to mix C and Python code, and also contains various bits that only 1-2 people on the planet really bothered to understand, besides demonstrating other issues of organically grown code bases.
bradknowlesabout 6 years ago
There are an infinite variety of things that you don’t want. If you focus all your energy on those things, then you won’t have anything left to do the positive things you do want.<p>You have to turn that equation around. Even if all you know right now is the negative thing you don’t want, you have to figure out how to reframe that into the positive thing you do want. On,y then can you make positive progress towards that thing you want — and by the way, you will naturally avoid the things you don’t want by focusing on the things you do want.<p>Sure, examples of bad stuff can be instructive, but only so far as it helps you further clarify the good stuff you’re actually trying to achieve.
superpermutat0rabout 6 years ago
I&#x27;ve always found Calibre to be a huge mess.
arthevabout 6 years ago
While usually focusing on smaller snippets, thedailywtf.com is a site about (mostly) code wtfs. A fair number of management wtfs too, though.
pjc50about 6 years ago
&gt; fall along the lines of &quot;fail to see the forest for the trees&quot;<p>I think I&#x27;m going to need an example to understand this?<p>Having said that, one of the most informative programming books I&#x27;ve ever read was <i>C Traps And Pitfalls</i>. Flags common easily-made errors and explains them, which in turn fixes misconceptions about the language. I feel most languages could do with one.
ksajabout 6 years ago
Here is something atrocious I wrote in Lisp. You actually <i>can</i> make Lisp ugly! Who knew?<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ksaj&#x2F;Capitalize.Lisp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ksaj&#x2F;Capitalize.Lisp</a>
RickJWagnerabout 6 years ago
Just a side note-- this is the beauty of Open Source. If there is some bad code (we all write it), it can be improved with a little help from Open Source &quot;friends&quot;.<p>All of us are stronger than any one of us. Long live Open Source!
craftomanabout 6 years ago
Many JavaScript libraries like Fastify (Node.js) for example. You always get a nice &amp; clean API but if you look under the hood you would be amazed at how much spaghetti code can be written in a project.
frostburgabout 6 years ago
Praat: <a href="https:&#x2F;&#x2F;github.com&#x2F;praat&#x2F;praat" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;praat&#x2F;praat</a> I&#x27;m not sure that this is a good way to learn anything, however.
sam_lowry_about 6 years ago
Jgit is amazingly bad for a piece of software built on top of well thought out data structures if git. Some if its flaws could be attributed to Java IO design, though.
peterwwillisabout 6 years ago
Anything related to OpenStack, but particularly jenkins-job-builder is rather horrible.
jxubabout 6 years ago
Many, if not most OSS packages which are released by academics or universities.
yamannabout 6 years ago
<a href="https:&#x2F;&#x2F;github.com&#x2F;mholt&#x2F;caddy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mholt&#x2F;caddy</a> not only a mediocre code, but the guy behind it received lots of money from Mozilla as an innocent promising open source project author, then he made it as a paid product.