Comments in the code as a way of expression

    Recently, picking one not very popular framework, I came across the next piece of code.

    Because killer robots love unicorns!

    I don’t know what thought and in what mood the author wanted to convey, but it made me think: how often do we use comments not quite for the intended purpose? Some finds under the cut.

    // Not recommended for reading, if you do not like Friday posts on Tuesday.

    There are different opinions on the topic of commenting code. There are adherents of self-explanatory code (self-explanatory code). According to this concept, variables and functions are named as maximally as possible, which in many cases eliminates the need to write additional comments. Others prefer to describe each step in the comments to help themselves and those who later have to work with the code. Some people write 3-storey constructions in one line and do not comment on them in any way (I myself am so wronged, I confess). But there are other cases.

    Sad confession

    Did you have to write something for which you hated yourself? You understood that doing so was bad and ugly, but circumstances (customer requirements, for example) were stronger than you? For some, this has happened.

    // This is code sucks, you know it.
    // Move on and call me an idiot later.

    This code is disgusting, you know it and I know it. Move on, then call me an idiot.

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

    I am not responsible for this code. I was forced to write it, against my will.

    // I have to find a better job

    It's time to get a better job.

    // I dedicate my code to my wife, Darlene, who will 
    // it gets 
    // released into the public.

    I dedicate all this code, all my work, to my wife Darlene, who will have to take care of me, our three children and the dog as soon as it sees the light.

    And sometimes corporate standards for writing code are forced to do something that defies the internal logic of the developer.

    const int TEN = 10; // As if the value of 10 will fluctuate ...

    As if the value of 10 can vary ... I

    remembered a case when I got a small piece of work on one directory on freelance. The interaction system was built in a complicated way, as a result of which there was no direct feedback from the customer. And it was necessary to do "as in the picture, because the customer approved it so," even though it was ugly from the point of view of the code. Did you come across these too?

    Warnings and lost knowledge

    It happens that it is better not to interfere with any code. Do not try to refactor it, optimize it or improve it in any other way.

    / *
     * You can think about what the following code does.
     * But you don't. Trust me.
     * You spend many a sleepless
     * night cursing the moment you thought youd be clever
     * enough to "optimize" the code below.
     * Now close this file and go play with something else.
     * / 

    You may think you know what the following code does. This is not true. Believe me. Get into it, and you will spend many sleepless nights, cursing the moment when you thought you were smart enough to “optimize” it. Now close this file and go play with something else.

    / *
     * Dear Maintainer
     * Once you are trying to optimize this routine,
     * and you have been realized what a terrible mistake that was,
     * Please increment the following counter as a warning
     * to the next guy.
     * total_hours_wasted_here = 73
     * /

    Dear Accompanying! When you finished your attempt to “optimize” this process and realized how monstrous this error was, increase the subsequent counter for the edification of those who come for you.

    // Magic. Do not touch.

    Magic. Do not touch.

    / *
    after hours of consulting the tome of google
    i have been discovered
    without the below line, IE7 believes that 6px = 12px
    * /
    font-size: 0px;

    After hours of consultations and googling, I found that by the will of unknown forces, without a subsequent line, IE7 considers that 6px = 12px

    // Autogenerated, do NOT edit. All changes will be undone.

    Automatically generated, do NOT edit. All changes will be undone.

    The latter, by the way, is an interesting example of quick-wittedness in the fight against attempts to get into your code. They say it works.

    Pain and despair

    Have you ever worked with something that caused you to despair? The developer of the image viewer Xee faced with the analysis of the PSD format. But with whom can a programmer share his sufferings, if not with a commentary? Below is the translation, the original is currently on the githaba .

    Here I would like to stop for a moment and tell you about the Adobe PSD format. PSD is not a good format. PSD is not even a bad format. To call it that would be an insult to other bad formats, such as PCX or JPEG. No, PSD is a monstrous format. A few weeks of working on this code elevated my hatred of PSD to the level of violent fire blazing with the fierce passion of a million suns.

    If there are two ways to do something, PSD uses both in different places. In addition, he will create three more ways that would not occur to any sensible person, and use them at the same time. PSD raises inconsistency to the level of art. Why, for example, he decided that these blocks should be aligned by four bytes, and this alignment is notshould be included in the size? Other blocks in other places are either not aligned, or include alignment in size. Here, however, it is not included. Any of these three methods would work. A reasonable format would stop at one. PSD, of course, uses all three, and others.

    Trying to extract data from a PSD file is the same as looking for something in the attic of your eccentric old uncle who died from the attack of a furious freshwater shark on his 58th birthday. The last detail does not really matter for the story, but at the moment I spend a lot of time presenting interesting destinies for the people responsible for this Ruba Goldberg among the file formats.

    Earlier, I tried to get the latest PSD format specifications. For this, I had to ask them for permission to contact them to consider the possibility of sending me this sacred volume. The process involved faxing copies of various documents, possibly signed in blood. The only explanation that comes to my mind about such a complex process is that they are extremely ashamed of creating this abomination. Naturally, I was not able to undergo this procedure, but if I could, I would print every single page of this specification, and burn them. If it were in my power, I would have collected all the copies of the specification in the world, and sent them by rocket directly to the Sun.

    PSD is not my favorite format.

    I did not reach this level of hatred, but I remembered how my eyes were bleeding when reading some of the documentation for the API of some domestic developers.

    Way to entertain yourself

    We know how boring and lonely the work of a programmer is. Therefore, all of us sometimes play KVN of one person. The safest thing to do is in the comments, of course, but there are options.

        #Christmas tree initializer  
        toConnect = []  
        toRead = []  
        toWrite = []   
        primes = []  
        responses = {}  
        remaining = {}  

    Christmas tree initializer

    /////////////////////////////////////// this is a well commented line

    Well commented out line

    Until (JesusChristsReturn) 'Not sure

    Religious dogma in doubt ...

    // if i’m ever

    I'll see it again - I'll start carrying a weapon to work.

    // Abandon all hope ye who enter beyond this point

    Give up hope, everyone entering here

    // drunk, fix later

    Drunk, fix it later

    Jokes with jokes, and once I left myself a similar note on a sticker on the monitor: “Sober up - check classes XXX, YYY” ...

    catch (Exception e) {
     // who cares?

    Who cares?

    // I didn’t understand how it worked.

    I do not know how this piece works, but it worked in the program, from where I stole it.

    // This code was written by a genius.
    // your tiny little brain.

    This code is written by genius. Do not try to understand it with your miniature brain.

    double penetration; // ouch

    And really, oh ...

    // Added because boss changed his mind: 20020111,20020501,20020820, ...
    // Commented out because the boss changed his mind: 20020201,20020614,20020908, ...

    Added, because the boss changed his mind ... Comment, because the boss changed his mind ...

    // Haleluya i can go home!

    Aleluia, I can go home.

    I went home. And you tell us what was your most memorable or fun comment.

    Thank you for staying with us. Do you like our articles? Want to see more interesting materials? Support us by placing an order or recommending to friends, 30% discount for Habr users on a unique analogue of the entry-level servers that we invented for you: The whole truth about VPS (KVM) E5-2650 v4 (6 Cores) 10GB DDR4 240GB SSD 1Gbps from $ 20 or how to share the server? (Options are available with RAID1 and RAID10, up to 24 cores and up to 40GB DDR4).

    Dell R730xd 2 times cheaper? Only we have 2 x Intel Dodeca-Core Xeon E5-2650v4 128GB DDR4 6x480GB SSD 1Gbps 100 TV from $ 249 in the Netherlands and the USA!Read about How to build an infrastructure building. class c using servers Dell R730xd E5-2650 v4 worth 9000 euros for a penny?

    Also popular now: