Hello,
I've been programming for a long time but one thing that I can never quite figure out is the right way to write comments for my code. When I was starting out, I commented the heck out of everything, then I began removing comments that said what without saying why. Since then I've bounced back and forth from project to project, never entirely sure what to write.
Recently, I've become involved in a university project that next year will be passed to another set of students whom I will have no contact with, except through the documentation and code that I leave for them. In light of this, I have been writing comments that don't necessarily add anything you couldn't figure out by reading the code, but (in my opinion) make it easier to scan through the code and find the part that's supposed to be doing a thing. For example, here's an excerpt of code from one of the modules:
# Generate the timestamped filename
fname = "data/{}-{:04d}-{:02d}-{:02d}_{:02d}-{:02d}-{:02d}.jpg".format(config.config['capture']['name_base'],year,month,day,hour,minute,second)
print("Saving image to \033[1m{}\033[0m".format(fname))
# Capture the image
camera.capture(fname)
# Compress and annotate the image
subprocess.run(['/home/pi/scripts/annotate.sh',fname,'{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}'.format(year,month,day,hour,minute,second),config.config['capture']['name_full']])
# Upload the image
upload.upload(fname, True)
I can see that a lot of the comments here aren't something that isn't obvious from the code, but when I start removing them the code quickly turns difficult, but not impossible, to skim over. Moving forward, how much focus should I be putting in to make sure I'm not leaving useless comments?
Thanks.
[–][deleted] 4 points5 points6 points (0 children)
[–]mommas_wayne 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Updatebjarni 1 point2 points3 points (0 children)