When To Comment Your Code - ardalis
My opinions on comments in software code have evolved with my experience. When I was a teenager first learning to…
I like that he concludes at the end that you just need to be careful and does not make a stand like “never comment, always let your code do the talking”. Since I read his article, I’ve been thinking about the code I write and examples where comments are critical.
Just now, I ran into one example. I’m rebuilding the Silicon Valley Code Camp Sessions interest page in React and I’m at the part where I need to enforce that when a users chooses to attend a session at a given time, other previously chosen sessions at that time that are marked to attend, get switched back to being interested in.
The issue is that I know (because of tribal knowledge on my part) that I only need to update the server with what session to attend and that the server will unmark the other sessions previously marked. There is NO WAY for the client code to know that, hence comments are critical. Otherwise, the developer may think that if other sessions don’t unmark on the server that there is ab ug in the client code when, indeed there is not.
So yes Virginia, sometimes it’s OK to comment code but always have a good reason!