• 0 Posts
  • 19 Comments
Joined 11 months ago
cake
Cake day: July 30th, 2023

help-circle









  • Your brain deliberately forgets trivial stuff. Do you really need to remember every lunch you had? Same goes for all the mundane stuff in history.

    On the other hand so little of the mundane stuff was recorded that when we do see it it can be a window into how people actually lived, like Samuel Pepys diary. The daily stuff was so accepted as boring and common knowledge that it wasn’t considered worth recording.




  • Yes, two of the most important things I see comments do is explain things like boundary conditions, “This is why we stop at 50 here.” and historical reasons “We have to return a 1 here because we still use calling func FOO for all of our calls still and it expects 1 as the default…”

    Another helpful use is to describe the expected format of the input. “We expect a struct with this format here…” Stick in a small example too. It makes it so much easier to quickly scan the code’s flow.




  • I worked with a guy who was smart but “useless smart”. He was convinced that “code is self descriptive”, that is comments are not needed because the code speaks for itself. Well that is like saying DNA is self descriptive. Yes, I can sit there tracing the code, tracking the variables, etc or you could make a small effort to describe what is happening instead and save me a lot of time and risk missing subtle points.


  • Yes, you don’t need to comment “n++” to say it is incrementing it but you should mention why you are starting with 1 instead of 0, etc. Boundary conditions are notoriously tricky and need to be documented. Then there are historical reasons that are NEVER obvious, “This function has to return -2 as a default because we’ve been calling it using X for years and it expects a -1 as the error…”