Is it a bad practice to write many lines of codes without adding comments? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 65

Is it a bad practice to write many lines of codes without adding comments?

28th Jun 2019, 6:15 PM
eMBee
eMBee - avatar
118 Answers
+ 66
No, it isn't. It definitely helps, but if you are making huge codes without comments, it can be really confusing. If you got the time and nerves, it is definitely positive
28th Jun 2019, 6:32 PM
Airree
Airree - avatar
+ 87
Write a huge code without comments. Come back a month later and try to understand your own code. You'll see for yourself.
28th Jun 2019, 8:32 PM
Chris
Chris - avatar
+ 47
Code Comments: Yes for Learners, No for Pros [Part 1 of 2] It really depends on what stage you are in as a developer. Learners should probably use comments to help keep track of their thoughts while writing various code parts. This is especially helpful as they are still trying to understand how to write clear and self documenting code. Early in my career, I used to believe that writing code comments was an essential practice for all professional development. However, over the years, as counterintuitive as this might seem, general code comments have proven to be a bad practice in more ways than you might have considered. On dev teams I lead, one of our code review checks is to scrutinize any code comments before allowing it to remain and be merged into our master branch. So... basically, code comments are the exception to the rule for my teams. (Scroll down 11 posts for Part 2)
29th Jun 2019, 8:27 AM
David Carroll
David Carroll - avatar
+ 36
Code Comments: Yes for Learners, No for Pros [Part 2 of 2] (Scroll up 11 posts for Part 1) Josh Greig I agree 100%! I remember a time when it was common to also include keeping a history of all commit notes at the top of files, which were of little to no value. 🤦‍♂️ I've found that comments are nearly impossible to accurately keep maintained over time resulting in a mess of outdated information that people are reluctant to change. 🤷‍♂️ Then there are comments that are clearly no longer consistent with the actual code, but people are still reluctant to remove or update. 🤦‍♂️ Eventually, you can't trust the comments and need to read the code to know what's really going on. Fortunately, the proliferation of high coverage unit tests, git tools (pull requests, review history, diff tools), cleaner code, design patterns, code reviews, agile, etc, we have more reliable ways to understand the code allowing us to minimize superfluous comments that become stale, cluttered, and ultimately, unreliable. 🤓🤘
29th Jun 2019, 5:17 PM
David Carroll
David Carroll - avatar
+ 24
It could be if the code is not self explanatory.
29th Jun 2019, 2:09 AM
Sonic
Sonic - avatar
+ 23
I think it is not very good practice though 😅 Specially people like me who forget their code after a week 😂😂 You don't necessarily need to write comments in Html codes... Because they're very easy to remember and understand.... And the commenting in Html itself needs a lot of writing ( <!--... -->)... So I'm lazy in that case... But in other Programming languages, commenting is a really good habit because then you'll understand your code very easily after many days...
29th Jun 2019, 11:30 AM
Humayra🇧🇩
Humayra🇧🇩 - avatar
+ 19
The answers here are great. I want to add that if you use a version control system like git, that is the best place to say why you're making certain changes. Your code base should be maintained to clearly express how it works now and what things are doing now. The version history is a great place to say why little changes are happening and reference other requirements documentation such as jira or github issues. The main reason to separate your code base(including its comments) from that extra documentation is that your code base is evolving along with requirements. Making all the appropriate changes to meet a new requirement or fix a bug is enough work. Comments that don't hold their weight either waste time or explain how things used to work instead of how they work now. In other words, comments should be as short as possible, actually explain something that isn't obvious and be worth maintaining.
29th Jun 2019, 12:30 PM
Josh Greig
Josh Greig - avatar
+ 11
Hello Mofey , writing long code without comments isn't a bad practice, if you follow all the naming convention rules and your code itself is easily understandable. To make your code easy to understand I suggest follow the clean coding principle's. Like for example, Uncle Bob says : name your methods with the same care you name your baby.
29th Jun 2019, 6:01 PM
Ankush Mamidwar
Ankush Mamidwar - avatar
+ 11
Gray area... I've read articles that support comments but I've also read articles that don't support comments. Personally I believe if you write your code as cleanly as possible comments become redundant. Also known as KISS principle! ( Keep It Stupidly Simple ) If you can't avoid writing something complicated then minimalist comments are best imo. E.g. : "This function does that."
2nd Jul 2019, 3:18 PM
Haris
Haris - avatar
+ 10
I insert comments basically for teaching's sake. I really enjoy to write descriptions about the functions all around and help someone understand my code. But I realize that being a comment code buff can have its downsides like you are going to be worried not only with your code, but also to check if your comment is equally updated. And if you need to do it constantly, then it is very probable that some of your comments are not working as you described them initially. Codes with self explanatory identifiers are very good to bear in mind while coding. Comments are cool for me, on the other hand, to split sections and category and insert the codes accordingly. Main sections and categories are way more stable and make you have an organized code structure.
30th Jun 2019, 3:38 AM
Luis Febro 🇧🇷
Luis Febro 🇧🇷 - avatar
+ 10
No, it's not but if you are making huge code then it will good for whom who are going to develope again on that code or who are new developer going to work on that code..
2nd Jul 2019, 4:37 PM
A͢J
A͢J - avatar
+ 9
Code is fine on its own if the variable names are clear and self explanatory, but if your unable to make good variable names comments are a must. Even if the code is very self-explanatory, comments can still be useful to say what each portion of code does in the context of the larger program.
29th Jun 2019, 5:50 AM
Jason Stone
Jason Stone - avatar
+ 8
but if you're working as a group, those comments are crucial
28th Jun 2019, 6:38 PM
Taste
Taste - avatar
+ 8
Osama Mohammed Shaker How do you address the problems I described about code comments on active software projects? See my earlier posts in this thread.
30th Jun 2019, 1:55 AM
David Carroll
David Carroll - avatar
+ 8
It means you are a pro coder 🙏 Trust me ,one who codes without comments he will be god of programmers //in dreams only 😂
30th Jun 2019, 4:55 PM
Charan Leo25
Charan Leo25 - avatar
+ 8
I think it is, but i don't add comments anyway. I like minimalism, lol.
2nd Jul 2019, 3:10 PM
Maz
Maz - avatar
+ 8
Yes it's important if we are writing and working on the big projects. The comments are very helpful , if we are confused in the middle of code then comments help to understand what we do on above without understanding and reading the code and it's logic. Thank You ....
2nd Jul 2019, 3:35 PM
Pankaj Kumar Maurya
Pankaj Kumar Maurya - avatar
+ 8
Hitlist 1. good comments 2. no comments 3... . . . oo. wrong comments
2nd Jul 2019, 5:49 PM
Oma Falk
Oma Falk - avatar
+ 7
I teach my students to write short comments as function header and one line comment before a important block of instructions. It helps reading code knowing what it does. The review goes fast and easy.
29th Jun 2019, 11:44 AM
Geoffroy Malherbe
Geoffroy Malherbe - avatar
+ 7
(2/2) But then there are other classes. When you engage in data science, machine learning and scientific computing, your codes are usually based around (already documented) mathematical formulas and algorithms. However, as soon as you have a huge calculation, your code easily gets messed up. And in this case it seems more readable to me when you simply comment, which part of the code calculates what, and explaining your train of thought in the middle, instead of splitting the formula up into 10 variables you only use once. Furthermore, you probably can't expect good documentation from hobby coders and very small teams.
30th Jun 2019, 2:13 AM
Chris
Chris - avatar