When You Should (and Shouldn’t) Comment Your Code

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2024

ความคิดเห็น • 14

  • @ChrisAthanas
    @ChrisAthanas 3 หลายเดือนก่อน +1

    I think your camera is out of focus, please check your settings. Audio is perfect.

  • @MalushJ
    @MalushJ 3 หลายเดือนก่อน

    The only time I leave a comment is with a TODO tag where I plan to comeback and remedy the problem later and remove said comment. I think contract comments are generally fine as long they are kept up to date.. anything else should be auto generated..

    • @ThePassionateProgrammer
      @ThePassionateProgrammer  3 หลายเดือนก่อน

      Yeah, I forgot to mention that TODO tags in comments are fine. Thank you for pointing it out.

  • @skulver
    @skulver 3 หลายเดือนก่อน

    The problem with code as documentation is that the code tells you what the program does, it doesn't tell you what the programmer wanted to happen. The ridiculously simple example I use is to imagine seeing the following in a piece of code:
    // Increment the counter
    counter = counter - 1;
    Now without comments a future developer trying to proof read or fix an error in this code has to scan back and forwards through the entire chunk of code to try and figure out what is the error while the commented version will immediately jump out as a mismatch to a reader.

    • @ThePassionateProgrammer
      @ThePassionateProgrammer  3 หลายเดือนก่อน

      Yeah, but at least you know which one the computer believes is correct.

  • @SteveKuo
    @SteveKuo 3 หลายเดือนก่อน +3

    To me a comment is either a lie or an apology.

  • @fashionrebelution
    @fashionrebelution 3 หลายเดือนก่อน

    I never put comments in my code. Wait, do I write code?

  • @asteriondaedalus6859
    @asteriondaedalus6859 16 วันที่ผ่านมา

    You want "why" not "what".

    • @ThePassionateProgrammer
      @ThePassionateProgrammer  15 วันที่ผ่านมา

      Yes, we actually want both why and what.

    • @asteriondaedalus6859
      @asteriondaedalus6859 15 วันที่ผ่านมา

      @ThePassionateProgrammer carefully crafting function and variable name goes a long way to self documentation of code. I used to program in FORTH, and took great delight in the art of self commenting code, though you still had plings and bangs at the lowest level to deal with.