• ebc@lemmy.ca
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

    Yeah, good code should explain the “what” without the need for comments. Good comments explain the “why”.

    • SolarMech@slrpnk.net
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Generally, you can replace some comments with variable names or comment names. Which means you must already be in the habbit of extracting methods, setting new variables to use appropriate names, and limit context to reduce the name (Smaller classes and methods means shorter names can be just as expressive, because the context is clearer). It lowers the number of wtfs per minute you get reading code before you even need whole sentences to explain why things are done in a certain way, because the names can be a powerful hint.

      But realistically, you end up needing comments for some things anyways.

    • pomodoro_longbreak@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Also some parts of code are just going to smell, because of deadlines, other trade offs. For those it helps to have a comment to really highlight that bit of weirdness - the what and the why. If it is weird it should really “pop out” when you’re reading it.