this post was submitted on 12 Apr 2025
195 points (90.1% liked)

Technology

69109 readers
2405 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] -2 points 1 week ago (4 children)

if you're worried about readability you can leave a comment.

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

Comments shouldn't explain code. Code should explain code by being readable.

Comments are for whys. Why is the code doing the things it's doing. Why is the code doing this strange thing here. Why does a thing need to be in this order. Why do I need to store this value here.

Stuff like that.

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

There is no guarantee that the comment is kept up to date with the code. "Self documenting code" is a meme, but clearly written code is pretty much always preferable to unclear code with a comment, largely because you can actually be sure that the code does what it says it does.

Note: You still need to comment your code kids.

[–] [email protected] 1 points 1 week ago* (last edited 1 week ago)

Better yet, a type hint. foo: list | None can be checked by static analysis, # foo is a list isn't.

[–] [email protected] 0 points 1 week ago

If there is an alternative through which I can achieve the same intended effect and is a bit more safer (because it will verify that it has len implemented) I would prefer that to commenting. Also if I have to comment every len use of not that sounds quite redundant as len checks are very common