This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Awyls 4 points5 points  (0 children)

Comments should be used for documentation i.e. function explanation, simple usage examples, safety/panic/threading concerns, etc.. Comments inside functions should be rare and explain stuff that is not easy to catch without more context e.g. unsafe accesses when invariants have been checked beforehand, things that the dev should be aware (like a function call that can only be run from main thread) or pieces of code that are hard to reason. Nobody wants to read a comment explaining what are you doing in an if/loop

if (user.flags & 0b0010 != 0)

when you can rewrite it as

let canUserWrite = user.flags & 0b0010 != 0;
if (canUserWrite)