Comments help writing better code

Reacting to another great video of the Youtube channel Healthy software developper.

When I try to explain why I give so much importance to commenting my code, one important point is that it helps me a lot when I'm coding. You know the quote 'you haven't understood it if you can't explain it to a child' attributed to Einstein, or the Feynman technique which basically says the same ? This is the same principle I apply with comments when coding: I first explain through the comments to an imaginary reader what the piece of code is doing. By explaining it, I actually ensure that I've understood what it is supposed to do. Then, once I've cleared up my mind with these explanations, I'm ready to translate the comments in natural language to the code in whatever programming language I'm using. In the end the comments stay there with the code for the next programmer, to avoid the burden of the inverse translation (code->natural language) when trying to understand the code, cause I can't believe anyone think in programming language. We are humans, not machines, we think in the languages we speak.

2022-08-04
in All, C programming, Pub talk,
96 views
Copyright 2021-2024 Baillehache Pascal