What is the best comment in source code you have ever encountered? (2011)
stackoverflow.com
stackoverflow.com
# 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 = 'one-fish two-fish red-fish blue-fish';
my $snake = 'oooh! a snake! ooh! snake! ooooooooo!";
(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 'fish' back, and -- until the code was fixed -- got the contents of $snake instead.)That's right. A successful combination of biblical allusion with Dr. Seuss and _Badger Badger Mushroom Mushroom_.
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.
Amongst the tens of thousands of lines of code, they found only one comment, preceding an unintuitive bitmask operation:
/* gok */
Nobody could work out what on earth "gok" 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.Years later, somebody bumped into this chap at a conference and managed to ask him about the project and the significance of "gok."
"Oh, that's easy. It stands for 'god only knows.'".
https://news.ycombinator.com/item?id=555201
https://news.ycombinator.com/item?id=604463
https://news.ycombinator.com/item?id=620595
https://news.ycombinator.com/item?id=1626686
https://news.ycombinator.com/item?id=1699760 (Many comments)
https://news.ycombinator.com/item?id=1805021
https://news.ycombinator.com/item?id=2566782
https://news.ycombinator.com/item?id=2791385
https://news.ycombinator.com/item?id=4838161
https://news.ycombinator.com/item?id=5140016
https://news.ycombinator.com/item?id=5379948
https://news.ycombinator.com/item?id=5978923
https://news.ycombinator.com/item?id=6232500 (Ask HN, not StackOverflow)
That got awkward fast.
/* 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't bad enough, all the doc insists on referring to local ports
and addresses as "names", 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's why my C code reads like assembler half the time... */
http://sourceforge.net/p/nc110/code/HEAD/tree/nc110/netcat.c grep -in poop netcat.c
110:struct host_poop {
115:#define HINF struct host_poop
117:struct port_poop {
122:#define PINF struct port_poop
163:HINF ** gates = NULL; /* LSRR hop hostpoop */
169:PINF * portpoop = NULL; /* for getportpoop / getservby* */
336: cross-check the host_poop we have so far against new gethostby*() info,
340:int comparehosts (poop, hp)
341: HINF * poop;
349: if (strcmp (poop->name, hp->h_name) != 0) { /* case-sensitive */
351: if (strcasecmp (poop->name, hp->h_name) != 0) { /* normal */
353: holler ("DNS fwd/rev mismatch: %s != %s", poop->name, hp->h_name);
360:/* gethostpoop :
361: resolve a host 8 ways from sunday; return a new host_poop struct with its
365:HINF * gethostpoop (name, numeric)
371: register HINF * poop = NULL;
397: poop = (HINF *) Hmalloc (sizeof (HINF));
398: if (! poop)
399: bail ("gethostpoop fuxored");
400: strcpy (poop->name, unknown); /* preload it */
411: strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 2);
413: memcpy (&poop->iaddrs[x], hostent->h_addr_list[x], sizeof (IA));
414: strncpy (poop->addrs[x], inet_ntoa (poop->iaddrs[x]),
415: sizeof (poop->addrs[0]));
418: return (poop); /* inverse stuff, we're done. */
421: for (x = 0; poop->iaddrs[x].s_addr && (x < 8); x++) {
422: hostent = gethostbyaddr ((char *)&poop->iaddrs[x],
426: poop->addrs[x]);
428: (void) comparehosts (poop, hostent);
432: memcpy (poop->iaddrs, &iaddr, sizeof (IA));
433: strncpy (poop->addrs[0], inet_ntoa (iaddr), sizeof (poop->addrs));
435: return (poop);
437: return (poop); /* the full DNS hair */
443: strncpy (poop->name, hostent->h_name, MAXHOSTNAMELEN - 2);
444: hostent = gethostbyname (poop->name);
447: poop->name);
449: (void) comparehosts (poop, hostent);
453:/* whatever-all went down previously, we should now have a host_poop struct
456: return (poop);
457:} /* gethostpoop */
459:/* getportpoop :
460: Same general idea as gethostpoop -- look up a port in /etc/services, fill
461: in global port_poop, but return the actual port *number*. Pass ONE of:
466:USHORT getportpoop (pstring, pnum)
476: portpoop->name[0] = '?'; /* fast preload */
477: portpoop->name[1] = '\0';
495: strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name));
509: return (getportpoop (NULL, x)); /* recurse for numeric-string-arg */
514: strncpy (portpoop->name, servent->s_name, sizeof (portpoop->name));
536: sprintf (portpoop->anum, "%d", x); /* always load any numeric specs! */
537: portpoop->num = (x & 0xffff); /* ushort, remember... */
538: return (portpoop->num);
539:} /* getportpoop */
994: gethostpoop wants a string and there's much gnarlier code out there already,
1002: whozis = gethostpoop (bigbuf_net, o_nflag);
1451: portpoop = (PINF *) Hmalloc (sizeof (PINF));
1545: gp = gethostpoop (optarg, o_nflag);
1572: o_lport = getportpoop (optarg, 0);
1584: wherefrom = gethostpoop (optarg, o_nflag);
1654: whereto = gethostpoop (argv[optind], o_nflag);
1669: curport = getportpoop (argv[optind], 0);
1713: hiport = getportpoop (cp, 0);
1719: loport = getportpoop (argv[optind], 0);
1740: curport = getportpoop (NULL, curport);
1749: whereto->name, whereto->addrs[0], curport, portpoop->name);
1768: whereto->name, whereto->addrs[0], curport, portpoop->name);Thoughtful, meaningful, and high-level. I aspire to this.
// And God said: "let there be....shite"!
(followed by some C# reflection code to break into a sealed class in the .Net framework)All other comments are pointful, well described and useful.
sBoardWantsEncryption = (x&0x3)!=0x1||(x&0x3)==0x1&&(x&0x3c)!=0x00; // Wheee!
Here's a better one from some DDS tape drive firmware: /* All measurements in 27 MHz ticks
// PG = Drum PG
// RG = Read Gate
// WG = Write Gate
// BH = B Head
//
// *****************************************************************************
// **DDS:
// sReadTrackStart Sync
// v v
// | Margin |Preamble|SubData|...|Subdata|PostAmble| Margin |
// |<- 3782 ->|<- 688->| |<- 343 ->|<- 3782 ->|
// ____________________ . . . ____________________
// RG ________| |________
// WWWWWWWWWWWW
// RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
// |<--- ???? --->|
// (gDesiredRGToSync)
// (ArbitrarySyncTime)
// ~2500
// |<---------- 67382.701 nominal (67248 - 67517) ------------->|
// (From DDS Spec)
//
// W = write track
// R = read track
// sReadTrackStart is calculated below.
// SkipMargin = Margin+Preamble - ArbitrarySyncTime (3300)
// ReadGateOn = sReadTrackStart + Margin+Preamble - ArbitrarySyncTime
// ReadGateOff = sReadTrackStart + SpecTrackLength - (Margin+PostAmble)/2
This is another one from the same project that I particularly liked: /* So you want to know the relation between the hardware and the
software control constants. Well,
/---/\/\---||---\
| R2 C |
R1 | |\ |
e--/\/\----|-\___________|____v
2.5v-------|+/
|/
Kh = Ks/(2^ix) = R2/R1
Ih = Is/(2^ix)/dt = 1/R1/C
Capstan Drum
dt 1/1800 1/100
ix Cix Vix
*/When you need more than two lines to explain something, then something is wrong and you'd better fix it.
But maybe the act of writing the comment helps to free the brain to find a better solution.
This happens to me time and time again.
Also, if we are talking about embedded there are a lot of comments that are invariant because they might explain details of the hardware interface this particular chunk-o-code might be dealing with. That hardware --external to the chip you are programming-- will not change unless a hardware revision is done, which is far less frequent than code iterations.
WHY ORDERS ARE VANISHING
You can't see this from just looking at the code: there are four other systems that interact with the same database. I've managed to localise the problem by the timing of faults, it seems like Cassandra is erasing entries that aren't on its local list.
They won't let us change this because they're afraid of breaking the system.
If Alec's still in charge, you're effectively out of luck. If the boss has changed, try asking about changing it again.
tl-dr: Your princess is in another castle. */
[edit] Yep.
I'm glad that StackOverflow leaves closed questions visible. A lot of the value I get from SO comes from opinion-y questions getting answered by experts.
There is especially no harm in letting the historical ones stay open.
And closing them with the "historical" note makes it clear that similar questions should not be asked.
> question is now closed, I think 528 "answers" is probably enough, no? :) – Jeff Atwood
It is annoying, though, how so many useful SO questions get closed for various reasons when they are just the question I want answered. Perhaps the real problem is Google giving a lot of weight to SO answers, even when they are closed?
Of course it was closed immediately.
while (read(line, ...) > 0) {
if (line[0] == '#') continue; // comment
...
}It almost seems that there's a generation of programmers being taught that comments are a waste of time. I really don't know where this trend comes from. Lazy? I don't want to believe that.
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/how it could be improved, performance notes, etc.
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'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.
I can think of a number of Github projects I'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'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.
What you describe about the development process, to write down the thinking and edge cases and decisions and such, is important but doesn't really belong in the source code. That stuff belongs in your issue tracker system or the commit messages. What other medium tries to embed a description of the creative process in the work itself? Da Vinci didn't write on the back side of the Mona Lisa the production process for his paints. Tolkien didn't explain how he created the Elvish language in the text of the novels. There's accompanying material for that.
But realistically for software, that accompanying material is not going to get read elsewhere, or survive long-term through migrations to different tools and hosts. So it ends up in the source as the only way to keep it with the code and visible ten years later. Commenting is a least-bad solution, not a good one.
And of course, policies for code commenting never work. You just get scintillating gems like "x+=5; //add 5 to x".
Which is a myth. Try to come back to code five years and three languages later and see how self-documenting it is. It isn't.
I could maybe --possibly-- stretch disbelief and accept that if someone works with one language and one platform for a long time the code will be self documenting to that person or that team. This is not the case for multi-technology projects with generations of people touching the code base.
I'll give you a very concrete example. About fifteen years ago we spent three months authoring a tool in Visual Basic for Applications (VBA). This tool was used to automate certain aspects of the EDA (electronics design software) tool we were using at the time. The custom software was needed in order to vastly improve productivity with 1,000+ pin chips. The VBA tool effectively linked Excel with PCAD and reduced a twelve hour task to less than an hour.
Well, I have not touched VBA in probably fifteen years. The code is full of comments about the very things I described in my prior post: intent, design, thoughts, ideas, enhancements, problems, etc. After fifteen years of not touching the language or the application I can jump into that code base and be up and running within not much more than an hour.
It is hard to place a number on the value this adds to a project. It is nothing less than huge when it comes to supporting, maintaining, migrating and enhancing it.
> "x+=5; //add 5 to x"
Clearly the domain of morons.
In contrast to what you've said I completely disagree with the notion that the "best code transcends the need for comments". I'd argue the best type of code has the most effective comments in line with code to ensure the next person can gain with the least amount of effort clear understanding of both the rationale and of the functionality that lead to what they see before them.
Except that in really big/successful projects, the proper places are outdated specs that end up buried in obscure unindexed archives. This can happen for a lot of reasons, technical debt, intellectual property acquisition, erosion of institutional knowledge due to personnel attrition, etc.
On the other hand, source code is forever. It is the thing that you cannot unknowingly get rid off without getting rid of (your ability to update) the product itself.
> Da Vinci didn't write on the back side of the Mona Lisa the production process for his paints.
If you were a curator of the Louvre Museum, your job would have been easier if he did.
I used to believe that too, but I now believe that that point-of-view only addresses the accidental complexities of reading code. Don't get me wrong, descriptive function and variable names are great and make understanding code much easier. But I think it misses the forest (program structure) for the trees (functions).
Where I get off that train is when trying to understand a program's structure. How do the modules decompose the problem being solved? Why was it designed a certain way? There's usually a combination of technical and domain knowledge that influenced the design. Sometimes, there's a philosophy that needs to be shared by the whole team to work effectively. I need to know all of that in order to effectively extend the program.
There are also times (though less common) that I believe comments are needed to understand even the most clearly-written functions. This is usually when one needs background knowledge to understand the function. For example, a mathematical derivation isn't obvious when you're staring at a line of trig functions. At the very least, code like that needs a reference to a Wikipedia article or a book.
That might be true. I had at least one professor who discouraged comments. He said, "I know how to read code." I can understand that in his particular case, he didn't need documentation for higher-level understanding. He taught us the algorithms and data structures being used and he gave us a boiler plate design that we had to conform to. All we had to do was fill in the function bodies and write a main() function.
Unfortunately, it's possible that some students might have adopted that as an overall attitude without recognizing that the context in which it was said invalidated the need for comments for any higher-level understanding. A lot of students looked up to this professor.
That's just a single example. I have no idea how common this is.
// Don't remove this comment, or the next line will break. WTF?!?
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/LF... So, essentially, it thought // Comment
formatHardDrive = true;
It thought that pesky next line was still part of the comment. It wasn't literally formatting the hard drive... that was another bug we encountered, one time... oh, the places you'll go...Here'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.
It turns out that I'd forgotten what this code does so the comment was helpful.
# 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'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's non-zero then the piece has two orientations.
my %pieces = (
Bridge => { length => $unit * 2,
angle => 0,
count => 1 },
Straight => { length => $unit,
angle => 0,
count => 2 },
# Here'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/2. So the angle b is $PI/2 -
# $radians_in_curve/2. By simple trigonometry the length is twice
# $unit * cos($PI/2-$radians_in_curve/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/2
# but b is $PI/2 - $radians_in_curve/2 and so c is
# $radians_in_curve/2
#
# s
# .
# . . .
# . b c .
# l . . .
# . .
# . . .
# . a .
# . . . . . . . . . . .
# o f
#
Curve => { length => 2 * $unit * cos($PI/2-$radians_in_curve/2),
angle => $radians_in_curve/2,
count => 16 }
);
http://blog.jgc.org/2010/01/more-fun-with-toys-ikea-lillabo-...Interestingly, the first line of this comment contains an error. There are 19 pieces not 15.
// Briefly the algorithm goes like this:
//
// Slide a 16x16 block across the entire image from left hand corner
// to bottom right hand corner. For each 16x16 block perform a
// discrete cosine transform on it and then quantize the 16x16 block
// using an expanded version of the standard JPEG quantization matrix.
//
// Each quantized DCT transformed is stored in a matrix with one row
// per (x,y) position in the original image (the (x,y) being the upper
// left hand corner of the 16x16 block being examined.
//
// The resulting matrix is lexicographically sorted and then rows that
// match in the matrix are identified. For each pair of matching rows
// (x1,y1) and (x2,y2) the shift vector (x1-x2,y1-y2) (normalized by
// swapping if necessary so that the first value is +ve) is computed
// and for each shift vector a count is kept of the number of times it
// is seen.
//
// Finally the shift vectors with a count > some threshold are
// examined, the corresponding pair of positions in the image are
// found and the 16x16 blocks they represent are highlighted.
//
// Uses the FreeImage library (http://freeimage.sf.net/) to access
// image data
From: http://blog.jgc.org/2008/02/tonight-im-going-to-write-myself...Also as it was interpreted at the time of development - the two should be the same of course but we don't live in a perfect world. If a comment explains exactly what the code is trying to do and why, and the "what" matches the code but doesn't match the client expectations then as well as fixing the code you know you might need to update documentation elsewhere too to make it cleare.
free(self); /* so liberating */ def self.merge(man)
# Shock!
clark_kent = super man- Donald Knuth
/*
* 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.
*/"NO! YOU FOOL! STUPID, STUPID, STUPID!"
LOL.
.\" Take this out and a Unix Demon will dog your steps from now until
.\" the time_t's wrap around.
.sp
You can tune a file system, but you can't tune a fish. /* First pint begins here */
/* Starting a second pint */
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.) # 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.What does a programmer have to cry about?
I'm now working on DOT road signing systems. The software I am writing will be used to figure out when and where to put up speed limit and warning signs.
What is really, super concerning is that, though I am capable of doing all of the math and physics that the job requires (and there is really no reason for you to believe me on that point, which makes the situation even worse), none of the other programmers I've ever worked with on these projects could.[2] The companies that hired me just got lucky that I typically go with the least-effort job application process and am too lazy to be constantly applying to jobs. There was no vetting process, it was just "take the cheapest guy we can get".
When people could die as a direct result of a programming error on your behalf, it tends to change your perspective on things.
[1] When the company ignored my analysis that certain parts of the data was logically inconsistent (this system used look-up tables to do everything, very little was actually simulated), I quit. As far as I was concerned, the fact that none of our own customers had been in the news was mere luck and I had no interest in being on watch with my hands tied behind my back when it finally did happen.
[2] The most recent fun defect I had to fix involved someone having added two angles together, one in degrees, the other in radians. That prompted this little thought-experiment in code: https://github.com/capnmidnight/UnitsOfMeasure/tree/master/U.... It works for some simple things and has an interesting side effect of helping document the code, which I realized when I failed to convert a particular poorly documented section of the code to this system.
Thank you, this is going into my risk assessment of various dangers.
On the other hand, I do not support the efforts of my state to attempt to license software engineers. As it's written, it really only seems like a protectionism racket to keep upstarts from competing with established firms. To whit: employees of S-corps are exempt. Way to miss the entire freaking point, Virginia.
At the top of the main loop of a heavily multi-threaded, iocp-based socket server written in K&R-style C. When I refactored it and ported to C++ I left the comment in.
$ man xorg.conf
and search for "nobody"
;)
"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." - Change 533404 by jim on 2010/07/19 18:07:00
http://www.reddit.com/r/gaming/comments/11mz4k/i_am_a_progra...
"Nosy, aren't you?"
In my sleep addled state that was one of the funniest things I'd ever seen. // This is what I think of websites saying not to use fflush().
fflush(stdout);* The magnitude of this hack compares favorably with that of the national debt.
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'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?
We write in the same way you did - short methods, lots of classes, descriptive (but not overly-so) variable names. The code should more or less document itself.
One place you will find comments are docblock style in projects providing an external API to allow us to generate the documentation from the code - it's the easiest way to ensure our docs are up to date.
The other is one or two word comments in the code, usually to avoid overly-verbose variable names. For instance, a variable named 'distance' might be immediately followed by 'in meters'.
As an added bonus, it helps make the code testable and improves (at least my) confidence in the results because complex logic is instead broken into lots of bits of simple logic which can more easily be thoroughly tested.
// "Learning to love yourself is the greatest love of all." - Whitney Houston
template <unsigned int C2> friend class Buffer; // Maybe these two lines will crush everything.
Whatever it referred to was no longer there.It asked: how should one handled multi-head/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?
It nice when you see source code that is meant to be read as well as compiled.
/*
thisIsCodeBlock(1);
moreCode();
/*/
thisIsCodeBlock(2);
andMore();
//*/ #define REG_08_POWER_DOWN 0x36 // 0011 0110
// |||| ||||
// |||| |||Power Down: 0 = Power down// 1 = Normal operation
// |||| ||Edge Select: 0 = Falling edge// 1= Rising edge
// |||| |Input Bus: 0 = 12 bits// 1 = 24 bits
// |||| Dual edge: 0 = Single edge// 1 = Dual edge
// |||H-sync enable: 0 = Always low (no H-sync)// 1 = Transmitted
// ||V-sync enable: 0 = Always low (no V-sync)// 1 = Transmitted
// Reserved
#define REG_08_NORMAL 0x37 // 0011 0111
// |||| ||||
// |||| |||Power Down: 0 = Power down// 1 = Normal operation
// |||| ||Edge Select: 0 = Falling edge// 1= Rising edge
// |||| |Input Bus: 0 = 12 bits// 1 = 24 bits
// |||| Dual edge: 0 = Single edge// 1 = Dual edge
// |||H-sync enable: 0 = Always low (no H-sync)// 1 = Transmitted
// ||V-sync enable: 0 = Always low (no V-sync)// 1 = Transmitted
// Reserved
#define REG_09_NORMAL 0x21 // 0010 0001
// |||| ||||
// |||| |||Monitor detect interrupt: (MDI) 0 = Detected// 1 = Clear/Not detected
// |||| ||Hot plug detect: (HTPLG) READ ONLY
// |||| |Receiver sense: (RSEN) READ ONLY
// |||| Interrupt generation method: 0 = MDI generated by RSEN// 1 = HTPLG
// |MSEL output pin source selection: (MSEL[2:0])
// | 000 = MSEN always high
// | 001 = MSEN = MDI bit
// | 010 = MSEN = RSEN bit
// | 011 = MSEN = HTPLG
// | 1xx = RESERVED
// VREF setting indicator: (VLOW) READ ONLY
#define REG_0A_NORMAL 0x10 // 0001 0000
// |||| ||||
// |||| |||Reserved
// |||| General purpose inputs (same as CTL[3:1] pins)
// |||De-skewing enable: (DKEN) 0 = Disabled// 1 = Enabled
// De-skewing setting: (DK[3:1])
// 000 = 1 step minimum setup/maximum hold
// 001 = 2 steps
// 010 = 3 steps
// 011 = 4 steps
// 100 = 5 steps default (recommended setting)
// 101 = 6 steps
// 110 = 7 steps
// 111 = 8 steps maximum setup/minumum hold
#define REG_0C_NORMAL 0x89 // 1000 1001
// |||| ||||
// |||| |||PLL Filter Enable: 0 = Disable// 1 = Enable
// |||| PLL Filter characteristic: 100 = recommended value
// |Reserved
// Sync Continuous: 0 = Disable// 1 = Enable (recommended) try
{
//some code that frequently dies
}
catch (Exception)
{
// "If he dies, he dies" - Ivan Dragor
}throw up //ha ha
I found that in a project I was working on for work last fall. I'm sure it not's the same code, but it cracked me up the first time I saw it.
using namespace std; // using namespace standardFollowed by a #region block (it's C# code): #region shit { ... }
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!
# You are not expected to understand this
I've always aspired to be a good enough programmer to put something like that in my code. :)
//We have to declare it as "32 bytes long" because it is said in some magical place.
this->diagsInfo.sbits_descr = new char*[32];if( zPtr == 0 ){
/*
*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
*/
exit(-1); //Seriously?
}With no explanation why. But then it is vb6 so who knows, perhaps the comments do make a difference. ;)
From: https://code.google.com/p/xee/source/browse/XeePhotoshopLoad...
// At this point, I'd like to take a moment to speak to you about the Adobe PSD format.
// PSD is not a good format. PSD is not even a bad format. Calling it such would be an
// insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having
// worked on this code for several weeks now, my hate for PSD has grown to a raging fire
// that burns with the fierce passion of a million suns.
// If there are two different ways of doing something, PSD will do both, in different
// places. It will then make up three more ways no sane human would think of, and do those
// too. PSD makes inconsistency an art form. Why, for instance, did it suddenly decide
// that *these* particular chunks should be aligned to four bytes, and that this alignement
// should *not* be included in the size? Other chunks in other places are either unaligned,
// or aligned with the alignment included in the size. Here, though, it is not included.
// Either one of these three behaviours would be fine. A sane format would pick one. PSD,
// of course, uses all three, and more.
// Trying to get data out of a PSD file is like trying to find something in the attic of
// your eccentric old uncle who died in a freak freshwater shark attack on his 58th
// birthday. That last detail may not be important for the purposes of the simile, but
// at this point I am spending a lot of time imagining amusing fates for the people
// responsible for this Rube Goldberg of a file format.
// Earlier, I tried to get a hold of the latest specs for the PSD file format. To do this,
// I had to apply to them for permission to apply to them to have them consider sending
// me this sacred tome. This would have involved faxing them a copy of some document or
// other, probably signed in blood. I can only imagine that they make this process so
// difficult because they are intensely ashamed of having created this abomination. I
// was naturally not gullible enough to go through with this procedure, but if I had done
// so, I would have printed out every single page of the spec, and set them all on fire.
// Were it within my power, I would gather every single copy of those specs, and launch
// them on a spaceship directly into the sun.
//
// PSD is not my favourite file format.# This format is weird and makes no sense but it's what the client is expecting for some reason.
throw new Exception("no exception thrown");
// this infelicity should be fixed.