this post was submitted on 01 Sep 2023
331 points (96.1% liked)

Programming

16975 readers
1288 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 1 year ago (8 children)

If your code files don't contain more lines of comments than lines of actual code, then you're doing it wrong. (For Python, docstrings count as comments)

And your comments shouldn't say what each line of code is doing. If you can code, then you can already tell what each line is doing by just reading the code. The comments should explain WHY it's being done this way, or HOW it's being done, or highlight some pitfalls that might snare a future developer, and generally just give some higher level context to a line or block of code.

@257m @programming

[–] [email protected] 23 points 1 year ago* (last edited 1 year ago) (3 children)

Oh fuck I hate encountering this level of commenting. If it's complicated, you should have a design doc. Source code is not where you write your dissertation. Simple explanations are good, especially since the code could be updated while the comment is likely to remain unchanged. Long expositions are usually the result of bad coding or improperly allocated design.

[–] [email protected] 11 points 1 year ago (2 children)

Absolutely agreed. If your code line by line isn't clear, then the code is the problem.

Commenting before a block of code (a function / algorithm or whatever) explaining what it is meant to do, absolutely that's great though, saves time when revisiting.

[–] [email protected] 2 points 1 year ago

As long as it's updated when the code changes

[–] [email protected] 1 points 1 year ago

And that one single line that makes zero FUCKING SENSE AND YOU SPENT 5 DAYS TRYING TO FIX IT!!! That definitely needs a comment so the next idiot (aka you in 6 months) doesn't think "what useless shit is this? Let's delete this!".

load more comments (4 replies)