Top comments in source code

Hi, Habrovsk. I havenโ€™t written much here yet, but managed to try several formats of articles. Here were interviews with some IT specialists from the company in which I work, translations, guides ... Something went in, something did not. And so, today I decided to try a new format for myself.



In my free time I sometimes like to sit on Quora - I answer questions from other participants, or just read answers to interesting questions. The other day I came across one rather popular question. The thread has more than a thousand subscribers and 100+ responses. And the question is: what is the best comment you have seen in the source code? (Orig. What is the best comment in source code that you have ever encountered?)

I know that there are such threads on both stackoverflow and reddit, but since I was inspired by the answers from Quora, I decided to make a selection from there. I looked through most of the answers and chose the couple that came in the most.

Answer by Costya Perepelitsa


Best comment I've ever seen, probably, Safety Pig ( Security Pig ):



I've never been entirely sure exactly how it was supposed to help me in the code processing, but whatever it was, it worked.

In the end, we included Safety Pig as part of our debugging and security process:
โ€œThe way this code is structured makes it especially difficult to detect memory leaks. Add a Safety Pig and push your changes through Valgrind before each commit. โ€
โ€œThe compiler cannot provide type safety here, so we added Safety Pig just in case.โ€
โ€œI don't have unit tests yet, but I added a pig to them.โ€ (almost worked)

For those of you who would like to have your own Safety Pig, ignore the first line. Quora code blocks automatically remove leading spaces in the first line.

1. .
2.                         _
3. _._ _..._ .-',     _.._(`))
4.'-. `     '  /-._.-'    ',/
5.   )         \            '.
6.  / _    _    |             \
7. |  a    a    /              |
8. \   .-.                     ;  
9.  '-('' ).-'       ,'       ;
10.     '-;           |      .'
11.        \           \    /
12.        | 7  .__  _.-\   \
13.        | |  |  ``/  /`  /
14.       /,_|  |   /,_/   /
15.          /,_/      '`-'

Reply by Sasha Krassovsky


Once I was looking at the source code of some random student games that I found on DigiPen when I suddenly saw this:

/* Do NOT delete this comment */

Naturally, I had to see what happens if I delete the comment. I deleted it and tried to recompile. Did not work. When I returned the comment, it compiled as if by magic.

There was an error LNK1000: "unknown error; See the documentation for technical support options. โ€ Why this comment was necessary will forever remain a mystery.

Answer by Rishi Kumar


The best I've seen is in a complicated program:

1. //Fu*k whoever wrote this shit

And then, after about five lines, this:

//oh god it was me

Reply by Chen Xu


Once I saw this:


1. //
2. //                       _oo0oo_
3. //                      o8888888o
4. //                      88" . "88
5. //                      (| -_- |)
6. //                      0\  =  /0
7. //                    ___/`---'\___
8. //                  .' \\|     |// '.
9. //                 / \\|||  :  |||// \
10.   //             / _||||| -:- |||||- \
11.   //            |   | \\\  -  /// |   |
12.   //            | \_|  ''\---/''  |_/ |
13.   //            \  .-\__  '-'  ___/-. /
14.   //          ___'. .'  /--.--\  `. .'___
15.   //       ."" '<  `.___\_<|>_/___.' >' "".
16.   //      | | :  `- \`.;`\ _ /`;.`/ - ` : | |
17.   //      \  \ `_.   \_ __\ /__ _/   .-` /  /
18.   //  =====`-.____`.___ \_____/___.-`___.-'=====
19.   //                       `=---='
19.   //
20.   //
21.   //  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22.  //
23.  //            God Bless         No Bugs
24.  //

Buddha statue blesses your code to be free from bugs. Laughing at it for a while.

From a response from Somnath Mishra


Once upon a time I saw a similar thread on Stackoverflow and there shared some of the funniest comments I came across. Yes, I myself wrote a lot of funny comments, but I will not share them here for obvious reasons.

This comment is not just fun, but brilliant. Some people give up their literary dreams when working as programmers:

1. // Replaces with spaces the braces in cases where braces
2. // in places cause stasis                                                           
3. $str = str_replace(array("\{","\}")," ",$str);

(lane. Replaces spaces between brackets in those places where they cause stasis)
It sounds impressive in English - two lines of commentary, and there are 6 rhyming words in them.

A bit of black humor:

1. double penetration; // ouch

The code can make a person an atheist:

1. //When I wrote this, only God and I understood what I was doing    
2. //Now, God only knows                                                  
3. // Update: I am an atheist now!

When cleaning up old code, programmers often encounter parts that are not used, but do not delete, for fear of possible consequences:

1. // I am not sure if we need this, but too scared to delete.

Annoyed programmer:

1. // I am not responsible of this code.
2. // They made me write it, against my will.

(lane. I am not responsible for this code. They forced me to write it against my will)

Angry programmer:

1. // no comments for you
2. // it was hard to write
3. // so it should be hard to read

Conclusion


The thread still had a lot of interesting things, you can read everything in English here . In general, if this post comes in, I think that later I will collect a list of the most interesting comments that were found in my practice. And which ones have you met? I will be glad to read in the comments.

All Articles