r/learnprogramming • u/BullCityPicker • 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
1
u/vi_sucks Mar 23 '22 edited Mar 23 '22
Nobody said anything about writing the method multiple times.
Anyway, the idea is that you can create a wrapper method called
callPricerAndSave()
which will do all the subsidiary method calls. You can then explain that it calls the pricer, saves, backs up to cache and logs in a comment attached to the method. You can even explain WHY it does that in that order if you want to.
No, I'm not assuming that comment will be up to date. Never assume that.
But imagine if you look at the callPricerAndSave method and the comment says "this method calls the pricer, saves, and then backs up to cache. This is because of a relatively mundane reason." But the code actually does callPricer, backupData, saveToDatabase.
This is useful information because the comment doesn't match the code. It should tell you that at some point the dev intended it to behave that way, and likely wrote the code that way, but now it's been changed and whoever changed it didn't update the comment.
Without the comment, you don't have this info. You might, maybe, figure it out after going through the git history line by line (oof) but probably not. Especially not if the commit got squashed because person who wrote the comment was you six months ago and you never actually committed just the change with the backup after the save. In that case, all you have is the code and a headscratcher trying to figure out why it was written the way it is.
Tests are great. But again, the benefit of comments is not to tell you what the code is doing. It's to help you figure out why it's doing it that way. Either explicitly as a statement of intent by the dev, or implicitly as a record of past intentions.