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

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.

1

u/vi_sucks Mar 23 '22

To capture the intent/thoughts of the dev when he wrote the comment. Generally this will answer things like "what was he trying to do?" And "why was he trying to do that?"

That is often very different from "what the code is actually doing right now" and knowing that it is different is incredibly useful.

1

u/Metalor Mar 24 '22

t is often very different from "what the code is actually doing right now" and knowing that it is different is incredibly useful.

Let it go, mate. Not trying to be a dick, but it's totally ok to be wrong. What's important is that you learn from it.

1

u/vi_sucks Mar 24 '22

I'm not wrong, though. Just speaking from experience.

I've generally found that the difficulty in understanding code is less an issue of trying to figure out WHAT code is doing, and much much often in trying to figure out WHY it's doing that.

Like, most of the code I've worked on is enterprise business code. It's not some fancy special algorithm. You can mostly look at it and get exactly what it does.

But that obvious and easy read code still ends up "not behaving correctly" from the perspective of the users. And the headscratcher that takes forever to resolve is WHY the developer chose to do it that way. Was he just an idiot? Is there a conflicting requirement that the users just forgot to mention? Did the code change at some point? Etc, etc.

Think of it like a translation process from user needs to code.

User need -> requirement documentation -> developer understanding -> code.

Comments aren't there to help capture step 4. They are there to help capture step 3. So if they don't match step 4, that's not a lie. It's useful information and helpful red flag that there is or was a problem in the translation from developer understanding to actual code.