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.

What is the best comment in source code you have ever encountered? (2011)

157 pointsby yammesickaover 11 years ago

56 comments

fennecfoxenover 11 years ago
In a unit test:<p><pre><code> # And what father is there among you, who, # if his son asks for a slice of bread, # will offer him a stone? # or if he asks for a fish, # will instead of a fish offer him a snake? my $fish = &#x27;one-fish two-fish red-fish blue-fish&#x27;; my $snake = &#x27;oooh! a snake! ooh! snake! ooooooooo!&quot;; </code></pre> (Unit test proceeds to insert both $snake and $fish into a cache object, does a little bit of extra manipulation to recreate the error condition, requests &#x27;fish&#x27; back, and -- until the code was fixed -- got the contents of $snake instead.)<p>That&#x27;s right. A successful combination of biblical allusion with Dr. Seuss and _Badger Badger Mushroom Mushroom_.
spatulonover 11 years ago
One of those reminded me of the following legend that gets passed around here at work.<p>A codebase had been maintained by a single person, who then left the company. When the other engineers took over responsibility for the project, they discovered, to their dismay, that it was almost entirely bereft of comments.<p>Amongst the tens of thousands of lines of code, they found only one comment, preceding an unintuitive bitmask operation:<p><pre><code> &#x2F;* gok *&#x2F; </code></pre> Nobody could work out what on earth &quot;gok&quot; could mean, let alone why the previous engineer had chosen to leave that comment when they found no reason to comment any other part of the project.<p>Years later, somebody bumped into this chap at a conference and managed to ask him about the project and the significance of &quot;gok.&quot;<p>&quot;Oh, that&#x27;s easy. It stands for &#x27;god only knows.&#x27;&quot;.
ColinWrightover 11 years ago
Several of these have just one or two comments - I&#x27;ve made a note of the one that has the most discussion. But here are some previous submissions:<p><a href="https://news.ycombinator.com/item?id=555201" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=555201</a><p><a href="https://news.ycombinator.com/item?id=604463" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=604463</a><p><a href="https://news.ycombinator.com/item?id=620595" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=620595</a><p><a href="https://news.ycombinator.com/item?id=1626686" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=1626686</a><p><a href="https://news.ycombinator.com/item?id=1699760" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=1699760</a> (Many comments)<p><a href="https://news.ycombinator.com/item?id=1805021" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=1805021</a><p><a href="https://news.ycombinator.com/item?id=2566782" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2566782</a><p><a href="https://news.ycombinator.com/item?id=2791385" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2791385</a><p><a href="https://news.ycombinator.com/item?id=4838161" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=4838161</a><p><a href="https://news.ycombinator.com/item?id=5140016" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5140016</a><p><a href="https://news.ycombinator.com/item?id=5379948" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5379948</a><p><a href="https://news.ycombinator.com/item?id=5978923" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=5978923</a><p><a href="https://news.ycombinator.com/item?id=6232500" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6232500</a> (Ask HN, not StackOverflow)
评论 #6413000 未加载
sansworkover 11 years ago
Ad company I work for buys one of our traffic partners. I&#x27;m code reviewing their system to document it and find a comment describing how they defraud us.<p>That got awkward fast.
评论 #6411569 未加载
groovy2shoesover 11 years ago
Netcat is full of great comments. Here&#x27;s a good one:<p><pre><code> &#x2F;* I really want to strangle the twit who dreamed up all these sockaddr and hostent abstractions, and then forced them all to be incompatible with each other so you *HAVE* to do all this ridiculous casting back and forth. If that wasn&#x27;t bad enough, all the doc insists on referring to local ports and addresses as &quot;names&quot;, which makes NO sense down at the bare metal. What an absolutely horrid paradigm, and to think of all the people who have been wasting significant amounts of time fighting with this stupid deliberate obfuscation over the last 10 years... then again, I like languages wherein a pointer is a pointer, what you put there is your own business, the compiler stays out of your face, and sheep are nervous. Maybe that&#x27;s why my C code reads like assembler half the time... *&#x2F; </code></pre> <a href="http://sourceforge.net/p/nc110/code/HEAD/tree/nc110/netcat.c" rel="nofollow">http:&#x2F;&#x2F;sourceforge.net&#x2F;p&#x2F;nc110&#x2F;code&#x2F;HEAD&#x2F;tree&#x2F;nc110&#x2F;netcat.c</a>
评论 #6415147 未加载
jpitzover 11 years ago
I&#x27;ve commented before that I feel that the PostgreSQL project is especially wonderful about code comments. According to the cloc tool, their C code has 700k lines of code and 221k lines of comments. That by itself isn&#x27;t terribly impressive if you&#x27;ve seen a lot of the typical boilerplate comments a lot of IDEs place in code, but have a look at a sample of the actual comments : <a href="https://github.com/postgres/postgres/blob/master/src/backend/parser/analyze.c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;postgres&#x2F;postgres&#x2F;blob&#x2F;master&#x2F;src&#x2F;backend...</a><p>Thoughtful, meaningful, and high-level. I aspire to this.
harrytuttleover 11 years ago
The favourite one from our codebase:<p><pre><code> &#x2F;&#x2F; And God said: &quot;let there be....shite&quot;! </code></pre> (followed by some C# reflection code to break into a sealed class in the .Net framework)<p>All other comments are pointful, well described and useful.
__david__over 11 years ago
This is a purposefully obfuscated piece of code (the chip manufacturer didn&#x27;t want to leak what the bits meant):<p><pre><code> sBoardWantsEncryption = (x&amp;0x3)!=0x1||(x&amp;0x3)==0x1&amp;&amp;(x&amp;0x3c)!=0x00; &#x2F;&#x2F; Wheee! </code></pre> Here&#x27;s a better one from some DDS tape drive firmware:<p><pre><code> &#x2F;* All measurements in 27 MHz ticks &#x2F;&#x2F; PG = Drum PG &#x2F;&#x2F; RG = Read Gate &#x2F;&#x2F; WG = Write Gate &#x2F;&#x2F; BH = B Head &#x2F;&#x2F; &#x2F;&#x2F; ***************************************************************************** &#x2F;&#x2F; **DDS: &#x2F;&#x2F; sReadTrackStart Sync &#x2F;&#x2F; v v &#x2F;&#x2F; | Margin |Preamble|SubData|...|Subdata|PostAmble| Margin | &#x2F;&#x2F; |&lt;- 3782 -&gt;|&lt;- 688-&gt;| |&lt;- 343 -&gt;|&lt;- 3782 -&gt;| &#x2F;&#x2F; ____________________ . . . ____________________ &#x2F;&#x2F; RG ________| |________ &#x2F;&#x2F; WWWWWWWWWWWW &#x2F;&#x2F; RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR &#x2F;&#x2F; |&lt;--- ???? ---&gt;| &#x2F;&#x2F; (gDesiredRGToSync) &#x2F;&#x2F; (ArbitrarySyncTime) &#x2F;&#x2F; ~2500 &#x2F;&#x2F; |&lt;---------- 67382.701 nominal (67248 - 67517) -------------&gt;| &#x2F;&#x2F; (From DDS Spec) &#x2F;&#x2F; &#x2F;&#x2F; W = write track &#x2F;&#x2F; R = read track &#x2F;&#x2F; sReadTrackStart is calculated below. &#x2F;&#x2F; SkipMargin = Margin+Preamble - ArbitrarySyncTime (3300) &#x2F;&#x2F; ReadGateOn = sReadTrackStart + Margin+Preamble - ArbitrarySyncTime &#x2F;&#x2F; ReadGateOff = sReadTrackStart + SpecTrackLength - (Margin+PostAmble)&#x2F;2 </code></pre> This is another one from the same project that I particularly liked:<p><pre><code> &#x2F;* So you want to know the relation between the hardware and the software control constants. Well, &#x2F;---&#x2F;\&#x2F;\---||---\ | R2 C | R1 | |\ | e--&#x2F;\&#x2F;\----|-\___________|____v 2.5v-------|+&#x2F; |&#x2F; Kh = Ks&#x2F;(2^ix) = R2&#x2F;R1 Ih = Is&#x2F;(2^ix)&#x2F;dt = 1&#x2F;R1&#x2F;C Capstan Drum dt 1&#x2F;1800 1&#x2F;100 ix Cix Vix *&#x2F;</code></pre>
pilifover 11 years ago
This tangentially reminds me of the fact that every time I&#x27;m writing a comment that&#x27;s longer than 4 lines and explaining in detail why the thing following works as it does, then both the comment and the thing it was explaining won&#x27;t survive the next hour.<p>When you need more than two lines to explain something, then something is wrong and you&#x27;d better fix it.<p>But maybe the act of writing the comment helps to free the brain to find a better solution.<p>This happens to me time and time again.
评论 #6412145 未加载
6d0debc071over 11 years ago
&#x2F;* Date of comment 17-10-2001<p>WHY ORDERS ARE VANISHING<p>You can&#x27;t see this from just looking at the code: there are four other systems that interact with the same database. I&#x27;ve managed to localise the problem by the timing of faults, it seems like Cassandra is erasing entries that aren&#x27;t on its local list.<p>They won&#x27;t let us change this because they&#x27;re afraid of breaking the system.<p>If Alec&#x27;s still in charge, you&#x27;re effectively out of luck. If the boss has changed, try asking about changing it again.<p>tl-dr: Your princess is in another castle. *&#x2F;
评论 #6411686 未加载
adnamover 11 years ago
Before I click, I bet this has been closed as &quot;not constructive&quot;.<p>[edit] Yep.
评论 #6410878 未加载
评论 #6411080 未加载
评论 #6410833 未加载
评论 #6411690 未加载
评论 #6412273 未加载
ScottBursonover 11 years ago
<p><pre><code> while (read(line, ...) &gt; 0) { if (line[0] == &#x27;#&#x27;) continue; &#x2F;&#x2F; comment ... }</code></pre>
robomartinover 11 years ago
This is one of the things that really bugs me about a lot of open source and Github code: almost no comments.<p>It almost seems that there&#x27;s a generation of programmers being taught that comments are a waste of time. I really don&#x27;t know where this trend comes from. Lazy? I don&#x27;t want to believe that.<p>For my purposes it is a huge negative mark if a programmer is not religious about commenting code. I will not hire someone like that. Why? Developing code is a huge financial investment, yes, but there are other metrics that are far more important than money. If you are doing something non-trivial it often requires a lot of thought, discussion, testing, experimentation, failures, iterations and decisions. Comments within code should be used to document some of this. Document intent, thinking, problem solving approach, corner cases, decisions, where&#x2F;how it could be improved, performance notes, etc.<p>This and the code become incredibly valuable. It means that months or years later someone can go back into the code and truly understand what it does, why it does it that way, where it came from and, perhaps, how it could be improved. You don&#x27;t need to engage in a research project in order to pick-up where the last programmers left of and continue moving forward. In addition to that I firmly believe a well-commented code-base is far more valuable during an acquisition than a thousand files of code with hardly a comment.<p>I can think of a number of Github projects I&#x27;ve come across with nearly zero comments. What you are looking at is dozens or hundreds of files vomited upon your hard drive that, yes, might perform a useful function at that point in time yet would be a nightmare to dive into to maintain them in any way. Before someone jumps down my throat: Just because something is FOSS it doesn&#x27;t mean we should not critique such practices. If everyone took the time to thoughtfully document their code the FOSS ecosystem would probably evolve at a faster rate. Some of these packages are so dense they are virtually impenetrable without cubic hours of work deciphering the rats nest of files.
评论 #6412770 未加载
评论 #6413610 未加载
VikingCoderover 11 years ago
<p><pre><code> &#x2F;&#x2F; Don&#x27;t remove this comment, or the next line will break. WTF?!? </code></pre> Turns out, we had mixed carriage returns and line feeds in our source. We had some UNIX coders, and some Windows coders. The Windows coders were in VS6 (ug), and the IDE showed the code perfectly. The compiler, on the other hand, was getting confused because one file had mixed CR&#x2F;LF... So, essentially, it thought<p><pre><code> &#x2F;&#x2F; Comment formatHardDrive = true; </code></pre> It thought that pesky next line was still part of the comment. It wasn&#x27;t literally formatting the hard drive... that was another bug we encountered, one time... oh, the places you&#x27;ll go...
ja27over 11 years ago
I think the best one that I didn&#x27;t write was a long back-and-forth argument in a C header file where TRUE was defined as 0 and FALSE as non-zero. The original author of this product apparently had screaming fights about that being THE RIGHT WAY. Of course that surprised a lot of developers over the years and had been &quot;fixed&quot; several times only to be reverted back.
jgrahamcover 11 years ago
Pretty sad that all these examples are bad comments not good ones.<p>Here&#x27;s a comment from some code that I posted to my blog. The idea was that this would explain in detail to someone reading the code what I was doing with the pieces of a wooden train set. This was critical to the operation of the program and I imagined that many of the readers of the code would need a careful explanation.<p>It turns out that I&#x27;d forgotten what this code does so the comment was helpful.<p><pre><code> # The 15 possible pieces: a straight edge (which has $unit length) and # is used as the measurement for everything else, a bridge (which is # twice the length of the straight edge; it is actually supplied in # two pieces but for the purposes of this program is considered to be # a single piece) and a curve (using $radians_in_curve above the # length of the straight line between the ends of the curve is # calculated). # # Each entry consists of three parts: # # length: the length in a straight line between the ends of the piece # at its centre. # # angle: the angle (in radians) between the straight line through the # piece and a tangent to the curve at the piece&#x27;s start. This only # applies to curved pieces where the straight line is the line joining # its two endpoints. # # count: how many of these pieces are supplied. # # Note that curves can be placed in either a clockwise or # anticlockwise direction. The program detects this by looking at the # angle. If it&#x27;s non-zero then the piece has two orientations. my %pieces = ( Bridge =&gt; { length =&gt; $unit * 2, angle =&gt; 0, count =&gt; 1 }, Straight =&gt; { length =&gt; $unit, angle =&gt; 0, count =&gt; 2 }, # Here&#x27;s a curved piece, the angle a is $radians_in_curve, the # length l of a side is $unit. So length is the distance between # the points labelled s and f. Bisect the angle a you get a right # angle triangle with hypotenuse of length $unit and angle at the # vertex of $radians_in_curve&#x2F;2. So the angle b is $PI&#x2F;2 - # $radians_in_curve&#x2F;2. By simple trigonometry the length is twice # $unit * cos($PI&#x2F;2-$radians_in_curve&#x2F;2). # # s # C # . . C # . b C # l . . C # . C # . . C # . a C # . . . . . . . C # o f # # To calculate the angle to the tangent at point s (the angle c), # note that the angle formed by os and the tangent is a right angle # (since os comes from the centre of the circle). So b+c is $PI&#x2F;2 # but b is $PI&#x2F;2 - $radians_in_curve&#x2F;2 and so c is # $radians_in_curve&#x2F;2 # # s # . # . . . # . b c . # l . . . # . . # . . . # . a . # . . . . . . . . . . . # o f # Curve =&gt; { length =&gt; 2 * $unit * cos($PI&#x2F;2-$radians_in_curve&#x2F;2), angle =&gt; $radians_in_curve&#x2F;2, count =&gt; 16 } ); </code></pre> <a href="http://blog.jgc.org/2010/01/more-fun-with-toys-ikea-lillabo-train.html" rel="nofollow">http:&#x2F;&#x2F;blog.jgc.org&#x2F;2010&#x2F;01&#x2F;more-fun-with-toys-ikea-lillabo-...</a><p>Interestingly, the first line of this comment contains an error. There are 19 pieces not 15.
评论 #6410758 未加载
评论 #6411464 未加载
评论 #6410965 未加载
评论 #6410914 未加载
wrlover 11 years ago
I had a line of code in one of my C projects which read:<p><pre><code> free(self); &#x2F;* so liberating *&#x2F;</code></pre>
pkulakover 11 years ago
I&#x27;ve come across this one several times courtesy of <a href="https://news.ycombinator.com/user?id=aphyr" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;user?id=aphyr</a><p><pre><code> def self.merge(man) # Shock! clark_kent = super man</code></pre>
peterkellyover 11 years ago
&quot;Beware of bugs in the above code; I have only proved it correct, not tried it.&quot;<p>- Donald Knuth
auviover 11 years ago
I think is the all time classic:<p><pre><code> &#x2F;* * If the new process paused because it was * swapped out, set the stack level to the last call * to savu(u_ssav). This means that the return * which is executed immediately after the call to aretu * actually returns from the last routine which did * the savu. * * You are not expected to understand this. *&#x2F;</code></pre>
评论 #6417072 未加载
_halgariover 11 years ago
Back around 2006 was an auto-generated file in Blender 3d&#x27;s source code, if you edited it by hand and then ran one of the tools it would spit out a .h file with the contents:<p>&quot;NO! YOU FOOL! STUPID, STUPID, STUPID!&quot;
ananth99over 11 years ago
Exception up = new Exception(&quot;Something is really wrong.&quot;); throw up; &#x2F;&#x2F;ha ha<p>LOL.
sturadnidgeover 11 years ago
From tunefs(1) on older SunOS<p><pre><code> .\&quot; Take this out and a Unix Demon will dog your steps from now until .\&quot; the time_t&#x27;s wrap around. .sp You can tune a file system, but you can&#x27;t tune a fish.</code></pre>
slowmoverover 11 years ago
Back in my heady startup days, I&#x27;d occasionally take my programmers to a local pub for afternoon chat and coding sessions. Code produced during these sessions often contained comments like:<p><pre><code> &#x2F;* First pint begins here *&#x2F; &#x2F;* Starting a second pint *&#x2F; </code></pre> The idea being to keep track of code written during increasing states of inebriation. Interestingly, later analysis of that code showed no relationship between number of drinks and number of defects. (Of course none of us would ever get really smashed.)
rheideover 11 years ago
Comment from a project I used to work on:<p><pre><code> # Circular references are a pain, yet so easy to avoid, # however unpicking them at a later date can be hard # and [python module name] especially so. # Therefore I shall ignore this for now and use this poor quality # botch to stop the code from breaking. # I dream of a day in the future when I will be able to remove # this crappy hack and the [project name] source code makes the world # a better place. # Until then I will cry myself to sleep each night.</code></pre>
评论 #6410818 未加载
andyjohnson0over 11 years ago
&#x2F;* Here be dragons. *&#x2F;<p>At the top of the main loop of a heavily multi-threaded, iocp-based socket server written in K&amp;R-style C. When I refactored it and ported to C++ I left the comment in.
helloTreeover 11 years ago
There is also a fun part in the documentation of xorg.conf, just do<p>$ man xorg.conf<p>and search for &quot;nobody&quot;<p>;)
agronaover 11 years ago
Not exactly a comment, but I immediately thought of this:<p>&quot;Whoa, that’s a full fog all the way. Double fog, oh my god. It’s a double fog, all the way. Whoa that’s so intense. Whoa man! Wow! Whoa! Whoa! Whoa ho ho oh my god! Oh my god! Oh my god! Woo! Oh wow! Woo! Yeah! Oh ho ho! Oh my god! Oh my god look at that! It’s starting even to look like a triple fog! Oh my god it’s full on! Double fog all the way across the sky! Oh my god. Oh my god. Oh god. What does this mean? Oh. Oh my god. Oh. Oh. God. It’s so bright, oh my god it’s so bright and vivid! Oh. Ah! Ah! It’s so beautiful! Oh my god. Oh my god. Oh my god! Oh my god, it’s a double complete fog! Oh right in my map. Oh my god. Oh my god, what does it mean? Tell me. Too much. I don’t know what it means. Oh my god it’s so intense. Oh. Oh. Oh my god.&quot; - Change 533404 by jim on 2010&#x2F;07&#x2F;19 18:07:00<p><a href="http://www.reddit.com/r/gaming/comments/11mz4k/i_am_a_programmer_for_guild_wars_2_amaa/c6nwksr?context=1" rel="nofollow">http:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;gaming&#x2F;comments&#x2F;11mz4k&#x2F;i_am_a_progra...</a>
mtmover 11 years ago
Late one night in the early &#x27;80s I was bored and found myself paging through the code for WordStar (best I can remember) with &#x27;ddt&#x27; on my Kaypro. Just page after page of Z80 disassembly and blocks of data… when suddenly I came across the words:<p><pre><code> &quot;Nosy, aren&#x27;t you?&quot; </code></pre> In my sleep addled state that was one of the funniest things I&#x27;d ever seen.
srlover 11 years ago
Back when I was first learning C++.<p><pre><code> &#x2F;&#x2F; This is what I think of websites saying not to use fflush(). fflush(stdout);</code></pre>
techtalskyover 11 years ago
I&#x27;ll always love all the comments that came to light when a significant hunk of Win2k source code was leaked, especially:<p>* The magnitude of this hack compares favorably with that of the national debt.<p><a href="http://www.kuro5hin.org/story/2004/2/15/71552/7795" rel="nofollow">http:&#x2F;&#x2F;www.kuro5hin.org&#x2F;story&#x2F;2004&#x2F;2&#x2F;15&#x2F;71552&#x2F;7795</a>
joshuahedlundover 11 years ago
Several of the answers revolve around dire warnings to not change or remove something even though no one may know why. They made me laugh and I&#x27;ve done similar, but I&#x27;ve also found that sometimes I stumble upon them again a couple years later and find I now have the skills to understand and optimize the code without breaking it.
habosaover 11 years ago
This might be asking for trouble, but what are people&#x27;s views on comments in normal cases? I once worked on a codebase where there were no comments, and people actively worked to remove them. It was a large Java Enterprise codebase and the idea was that anywhere I wanted to insert a comment, I should refactor and rename until the code explained itself.<p>At first this was horrifying, especially when I was thrown into this comment-free codebase with thousands of files. However it did make me write better code, knowing that I couldn&#x27;t rely on comments to explain what I was doing. I wrote short functions that were easy to understand, and paid attention to all variable names. It definitely made me a better Java programmer, but outside of that project I still think comments have huge value. I comment my code a ton, and I think it makes it better. Anyone else ever worked in a no-comment zone?
评论 #6414963 未加载
peter303over 11 years ago
Knuth&#x27;s &quot;Art of Programming&quot; series after 1985. He pretty much writes the documentation first, embeds the code in the documentation, uses compiler-preprocessors to extract, join and compile the code. He spent over a decade writing these tools himself since there wasnt really anything in existance to do that.
apiover 11 years ago
In a template C++ class called Buffer that supports assignments and comparisons with other instances templated for different Buffer sizes:<p><pre><code> &#x2F;&#x2F; &quot;Learning to love yourself is the greatest love of all.&quot; - Whitney Houston template &lt;unsigned int C2&gt; friend class Buffer;</code></pre>
dmoneyover 11 years ago
<p><pre><code> &#x2F;&#x2F; Maybe these two lines will crush everything. </code></pre> Whatever it referred to was no longer there.
belornover 11 years ago
I used to read the nethack source code comments just for fun. Beyond jokes, lore, and the numerous not-implemented-yet features, it also included a small section regarding polymorph in fantasy games.<p>It asked: how should one handled multi-head&#x2F;arms creatures? Do they get one amulet and one helmet per head? What constitute an arm? How many rings should a 4 armed creature be allowed to wear?<p>It nice when you see source code that is meant to be read as well as compiled.
gprasanthover 11 years ago
<p><pre><code> &#x2F;* thisIsCodeBlock(1); moreCode(); &#x2F;*&#x2F; thisIsCodeBlock(2); andMore(); &#x2F;&#x2F;*&#x2F;</code></pre>
robomartinover 11 years ago
<p><pre><code> #define REG_08_POWER_DOWN 0x36 &#x2F;&#x2F; 0011 0110 &#x2F;&#x2F; |||| |||| &#x2F;&#x2F; |||| |||Power Down: 0 = Power down&#x2F;&#x2F; 1 = Normal operation &#x2F;&#x2F; |||| ||Edge Select: 0 = Falling edge&#x2F;&#x2F; 1= Rising edge &#x2F;&#x2F; |||| |Input Bus: 0 = 12 bits&#x2F;&#x2F; 1 = 24 bits &#x2F;&#x2F; |||| Dual edge: 0 = Single edge&#x2F;&#x2F; 1 = Dual edge &#x2F;&#x2F; |||H-sync enable: 0 = Always low (no H-sync)&#x2F;&#x2F; 1 = Transmitted &#x2F;&#x2F; ||V-sync enable: 0 = Always low (no V-sync)&#x2F;&#x2F; 1 = Transmitted &#x2F;&#x2F; Reserved #define REG_08_NORMAL 0x37 &#x2F;&#x2F; 0011 0111 &#x2F;&#x2F; |||| |||| &#x2F;&#x2F; |||| |||Power Down: 0 = Power down&#x2F;&#x2F; 1 = Normal operation &#x2F;&#x2F; |||| ||Edge Select: 0 = Falling edge&#x2F;&#x2F; 1= Rising edge &#x2F;&#x2F; |||| |Input Bus: 0 = 12 bits&#x2F;&#x2F; 1 = 24 bits &#x2F;&#x2F; |||| Dual edge: 0 = Single edge&#x2F;&#x2F; 1 = Dual edge &#x2F;&#x2F; |||H-sync enable: 0 = Always low (no H-sync)&#x2F;&#x2F; 1 = Transmitted &#x2F;&#x2F; ||V-sync enable: 0 = Always low (no V-sync)&#x2F;&#x2F; 1 = Transmitted &#x2F;&#x2F; Reserved #define REG_09_NORMAL 0x21 &#x2F;&#x2F; 0010 0001 &#x2F;&#x2F; |||| |||| &#x2F;&#x2F; |||| |||Monitor detect interrupt: (MDI) 0 = Detected&#x2F;&#x2F; 1 = Clear&#x2F;Not detected &#x2F;&#x2F; |||| ||Hot plug detect: (HTPLG) READ ONLY &#x2F;&#x2F; |||| |Receiver sense: (RSEN) READ ONLY &#x2F;&#x2F; |||| Interrupt generation method: 0 = MDI generated by RSEN&#x2F;&#x2F; 1 = HTPLG &#x2F;&#x2F; |MSEL output pin source selection: (MSEL[2:0]) &#x2F;&#x2F; | 000 = MSEN always high &#x2F;&#x2F; | 001 = MSEN = MDI bit &#x2F;&#x2F; | 010 = MSEN = RSEN bit &#x2F;&#x2F; | 011 = MSEN = HTPLG &#x2F;&#x2F; | 1xx = RESERVED &#x2F;&#x2F; VREF setting indicator: (VLOW) READ ONLY #define REG_0A_NORMAL 0x10 &#x2F;&#x2F; 0001 0000 &#x2F;&#x2F; |||| |||| &#x2F;&#x2F; |||| |||Reserved &#x2F;&#x2F; |||| General purpose inputs (same as CTL[3:1] pins) &#x2F;&#x2F; |||De-skewing enable: (DKEN) 0 = Disabled&#x2F;&#x2F; 1 = Enabled &#x2F;&#x2F; De-skewing setting: (DK[3:1]) &#x2F;&#x2F; 000 = 1 step minimum setup&#x2F;maximum hold &#x2F;&#x2F; 001 = 2 steps &#x2F;&#x2F; 010 = 3 steps &#x2F;&#x2F; 011 = 4 steps &#x2F;&#x2F; 100 = 5 steps default (recommended setting) &#x2F;&#x2F; 101 = 6 steps &#x2F;&#x2F; 110 = 7 steps &#x2F;&#x2F; 111 = 8 steps maximum setup&#x2F;minumum hold #define REG_0C_NORMAL 0x89 &#x2F;&#x2F; 1000 1001 &#x2F;&#x2F; |||| |||| &#x2F;&#x2F; |||| |||PLL Filter Enable: 0 = Disable&#x2F;&#x2F; 1 = Enable &#x2F;&#x2F; |||| PLL Filter characteristic: 100 = recommended value &#x2F;&#x2F; |Reserved &#x2F;&#x2F; Sync Continuous: 0 = Disable&#x2F;&#x2F; 1 = Enable (recommended)</code></pre>
WickyNilliamsover 11 years ago
Here&#x27;s something I recently discovered I had written when revisiting some code. Swallowing exceptions FTW :)<p><pre><code> try { &#x2F;&#x2F;some code that frequently dies } catch (Exception) { &#x2F;&#x2F; &quot;If he dies, he dies&quot; - Ivan Dragor }</code></pre>
9emE0iL18gxCqLTover 11 years ago
&quot;C++&#x27;s idea of a reinterpret_cast lacks sufficient cojones.&quot; <a href="http://code.woboq.org/qt5/qtwebkit/Source/WTF/wtf/StdLibExtras.h.html#129" rel="nofollow">http:&#x2F;&#x2F;code.woboq.org&#x2F;qt5&#x2F;qtwebkit&#x2F;Source&#x2F;WTF&#x2F;wtf&#x2F;StdLibExtr...</a>
评论 #6411408 未加载
评论 #6411246 未加载
gutsyover 11 years ago
I love when this shows back up (I&#x27;ve only been reading HN for about a year and have seen it 3 times). Always funny to read through.<p>throw up &#x2F;&#x2F;ha ha<p>I found that in a project I was working on for work last fall. I&#x27;m sure it not&#x27;s the same code, but it cracked me up the first time I saw it.
dllthomasover 11 years ago
At a new job, I once encountered<p><pre><code> using namespace std; &#x2F;&#x2F; using namespace standard</code></pre>
dbattagliaover 11 years ago
The best I&#x27;ve seen recently was: &#x2F;&#x2F; this is shit<p>Followed by a #region block (it&#x27;s C# code): #region shit { ... }<p>This was done by a remote contractor on his last week on the project, which may explain his attitude. Regardless I nearly wet myself when I saw it!
Jareover 11 years ago
I did not encounter this myself and it&#x27;s somewhat spoilery to post it here, but very much worth it:<p><a href="http://www.insomniacgames.com/a-hair-tearing-out-bug/" rel="nofollow">http:&#x2F;&#x2F;www.insomniacgames.com&#x2F;a-hair-tearing-out-bug&#x2F;</a>
MattGrommesover 11 years ago
In a class on assembly in college our professor walked us through a strange bit of real world code with the comment<p># You are not expected to understand this<p>I&#x27;ve always aspired to be a good enough programmer to put something like that in my code. :)
评论 #6412689 未加载
professorTuringover 11 years ago
This is the best comment I have ever faced. Ever:<p><pre><code> &#x2F;&#x2F;We have to declare it as &quot;32 bytes long&quot; because it is said in some magical place. this-&gt;diagsInfo.sbits_descr = new char*[32];</code></pre>
symisc_develover 11 years ago
zPtr = malloc(128);<p>if( zPtr == 0 ){<p>&#x2F;*<p><pre><code> *If the system is so sick that we are unable * to allocate a tiny chunk of memory, there * is no much we can do here, kill this bitch *&#x2F; exit(-1); &#x2F;&#x2F;Seriously? }</code></pre>
etermover 11 years ago
&#x27;&#x27;WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!<p>With no explanation why. But then it <i>is</i> vb6 so who knows, perhaps the comments do make a difference. ;)
Aldo_MXover 11 years ago
For me this is the best comment I have ever read.<p>From: <a href="https://code.google.com/p/xee/source/browse/XeePhotoshopLoader.m#102" rel="nofollow">https:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;xee&#x2F;source&#x2F;browse&#x2F;XeePhotoshopLoad...</a><p><pre><code> &#x2F;&#x2F; At this point, I&#x27;d like to take a moment to speak to you about the Adobe PSD format. &#x2F;&#x2F; PSD is not a good format. PSD is not even a bad format. Calling it such would be an &#x2F;&#x2F; insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having &#x2F;&#x2F; worked on this code for several weeks now, my hate for PSD has grown to a raging fire &#x2F;&#x2F; that burns with the fierce passion of a million suns. &#x2F;&#x2F; If there are two different ways of doing something, PSD will do both, in different &#x2F;&#x2F; places. It will then make up three more ways no sane human would think of, and do those &#x2F;&#x2F; too. PSD makes inconsistency an art form. Why, for instance, did it suddenly decide &#x2F;&#x2F; that *these* particular chunks should be aligned to four bytes, and that this alignement &#x2F;&#x2F; should *not* be included in the size? Other chunks in other places are either unaligned, &#x2F;&#x2F; or aligned with the alignment included in the size. Here, though, it is not included. &#x2F;&#x2F; Either one of these three behaviours would be fine. A sane format would pick one. PSD, &#x2F;&#x2F; of course, uses all three, and more. &#x2F;&#x2F; Trying to get data out of a PSD file is like trying to find something in the attic of &#x2F;&#x2F; your eccentric old uncle who died in a freak freshwater shark attack on his 58th &#x2F;&#x2F; birthday. That last detail may not be important for the purposes of the simile, but &#x2F;&#x2F; at this point I am spending a lot of time imagining amusing fates for the people &#x2F;&#x2F; responsible for this Rube Goldberg of a file format. &#x2F;&#x2F; Earlier, I tried to get a hold of the latest specs for the PSD file format. To do this, &#x2F;&#x2F; I had to apply to them for permission to apply to them to have them consider sending &#x2F;&#x2F; me this sacred tome. This would have involved faxing them a copy of some document or &#x2F;&#x2F; other, probably signed in blood. I can only imagine that they make this process so &#x2F;&#x2F; difficult because they are intensely ashamed of having created this abomination. I &#x2F;&#x2F; was naturally not gullible enough to go through with this procedure, but if I had done &#x2F;&#x2F; so, I would have printed out every single page of the spec, and set them all on fire. &#x2F;&#x2F; Were it within my power, I would gather every single copy of those specs, and launch &#x2F;&#x2F; them on a spaceship directly into the sun. &#x2F;&#x2F; &#x2F;&#x2F; PSD is not my favourite file format.</code></pre>
careersuicideover 11 years ago
In regards to a csv-like export of a store location database:<p># This format is weird and makes no sense but it&#x27;s what the client is expecting for some reason.
knownover 11 years ago
<a href="http://lxr.linux.no/+trees" rel="nofollow">http:&#x2F;&#x2F;lxr.linux.no&#x2F;+trees</a> has many interesting&#x2F;insightful comments
antsamover 11 years ago
Not really a comment but this is an exception I see that gets thrown every once and awhile :(<p>throw new Exception(&quot;no exception thrown&quot;);
randomsearchover 11 years ago
From the HotSpot source code:<p>&#x2F;&#x2F; this infelicity should be fixed.
btbuildemover 11 years ago
&#x2F;&#x2F; debugger;
auggieroseover 11 years ago
Did I just get text-Rick-Roll&#x27;ed?