• nikaaa@lemmy.world
    link
    fedilink
    arrow-up
    26
    arrow-down
    7
    ·
    5 months ago

    Good code is self-explanatory. You should only comment your code if it does something unexpectedly complicated.

    That being said, it’s always a good idea to write a manual, about how to use the code. Don’t document how it works, because those who can code will understand it anyways, and those who can’t, have no need to understand it.

    • BorgDrone@lemmy.one
      link
      fedilink
      arrow-up
      29
      ·
      5 months ago

      Good code is self-explanatory. You should only comment your code if it does something unexpectedly complicated.

      The code shows what is being done. The comments should explain the why.

      • Pasta Dental@sh.itjust.works
        link
        fedilink
        arrow-up
        12
        ·
        edit-2
        5 months ago

        Yes. This 1000x. I hate it at work when I come across code that was written 3 years ago that has literally no traces of why it’s there and a quick summary of what it does. Especially because that code is always the most abbreviated spaghetti you’ve ever seen. People should stop thinking (their) code documents itself because 99.999% of programmers cannot do it right.

        I really like the Google way of coding: assume the person reading the code is the most 1337 programmer ever, BUT that this person knows absolutely nothing about the project

        • BorgDrone@lemmy.one
          link
          fedilink
          arrow-up
          6
          ·
          5 months ago

          Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

      • dan@upvote.au
        link
        fedilink
        arrow-up
        9
        ·
        5 months ago

        This is something a lot of people don’t seem to understand. Even if code is self-explanatory, I want to know why it was designed that way.

        I’ve fixed bugs where the fix was only a one line change, but it was extremely difficult to figure out, so I left a 10ish line comment above it explaining why it has to be done that way.

    • tiredofsametab@kbin.run
      link
      fedilink
      arrow-up
      2
      ·
      5 months ago

      Asinine business logic can still make some things very hard to read and digest no matter how well-planned and well-written it is (particularly if it is rushed by the business meaning that engineers don’t have time to do it well). As such, there are places where code can’t/won’t be self-documenting to a useful degree.

    • TORFdot0@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      5 months ago

      This is true, but it’s easier and faster to parse plain English and so if I don’t adequately comment my code the first time. I will be commenting it when I have to return to it for whatever reason. Honestly the second round of commenting is more verbose and clearer than the function x does y style of comments I tend to make when coding the first time