r/learnprogramming • • Mar 22 '22

Don't be that guy.

I just took over a project for a guy who left. Don't be this guy:

  • ZERO comments in your codebase.

  • One and two character variable names with no discernable pattern.

  • Comment characters used to comment out big chunks of code for no discernable reason.

  • No error checking.

  • Reliance on data files that you forgot to include or explain, going in to meaningless data frame names.

  • Making outrageous claims about how much your code improves things with zero baseline performance.

People like this think you're an idiot because you can't make their code work, and get to be all smug. We will track you down and find you. You will need references someday....oh my.

2.6k Upvotes

427 comments sorted by

View all comments

Show parent comments

-4

u/vi_sucks Mar 22 '22 edited Mar 23 '22

Comments don't lie.

What they do is capture the mind of the developer at a given point in time. Even if that intention is different from the current intended state of the code, that's still incredibly valuable information. First because it's not always true that the current intention is right; but also because when debugging, being able to understand WHY the dev was doing the things he was doing is just as important as figuring out what he did. Since what he did was probably wrong, so you need to backtrack to find out what he should have done.

5

u/imnos Mar 22 '22

If you really want access to the mind of the developer at that moment in time - you have an even better resource which never changes - the git log. Writing detailed commits is also a crucial part of self documenting code.

And of course comments can lie. If a piece of code needs to be updated - the dev changing it now has two things they need to update. Guess which one isn't going to be updated because it doesn't break a unit test if they leave it as it is?

0

u/vi_sucks Mar 23 '22

If you really want access to the mind of the developer at that moment in time - you have an even better resource which never changes - the git log.

Until the code base gets ported. Or the commits get squashed during a merge. Or the commit is cherrypicked.

And that's not even counting how much more difficult it is to read theough 2, 3 or even 10 years worth of git commit logs to try to find the one commit that made the exact change that you care about.

And of course comments can lie.

No, they don't. What people mean by this is that comments don't accurately capture what the code is actually doing. My point is that you should never expect a comment to accurately describe what the code is doing. It's not a lie unless you make an incorrect assumption.

1

u/Metalor Mar 23 '22

'My point is that you should never expect a comment to accurately describe what the code is doing. It's not a lie unless you make an incorrect assumption.'

So what the hell is the point of comments? You've just gone and contradicted yourself entirely.

→ More replies (3)