this post was submitted on 15 Nov 2023
0 points (50.0% liked)

Programming

355 readers
1 users here now

This magazine is dedicated to discussions on programming languages, software development, and coding. Whether you are a beginner programmer or an experienced developer, this is the place for you. Here you can share your knowledge, ask questions, and engage in discussions on topics such as coding languages, software engineering, web development, and more. From the latest trends and frameworks to tips and tricks for debugging, this category covers a wide range of topics related to programming.

founded 2 years ago
 

Comments in code are quite often a code smell. Let’s see what is suboptimal about comments and talk about some strategies to avoid them.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 7 points 11 months ago (3 children)

Comments should be used when it’s hard to convey the intent using only code. For example, maybe there’s some unintuitive border case that must handled. Then it could be useful to add some explanation with a comment.

I also like to add comments when I find some clever solution/workaround on the web. For example, some stack overflow answer or Wikipedia page of some algorithm.

[–] [email protected] 1 points 11 months ago

Totally agree, that's why I also mentioned this in the article.

Very often good code that is self-explanatory does not need any comments at all and if it does, the comment should describe why it has been implemented this way instead of just repeating what the code already says.

load more comments (2 replies)