Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
b3b340655yCommenting code is a bad thing. Code should be readable without explanation, like as if you were reading a story.
If you write code that is not easily readable because of performance/whatever then you should comment it for others or yourself reading that code the next week -
bnjns865y@b3b3 I disagree that comments are bad as a generality.
I wholeheartedly agree that you should not need to explain what your code is doing, as your structure and naming should do that, but instead why. It's not always necessary, but if you had to do some research and/or experimentation, putting a comment in to explain why you chose your solution will prevent anyone else coming along and either getting confused or wanting to change it to something that you've already ruled out.
Docblocks can also be really useful for people unfamiliar with a function which calls a few other functions. Yes you can figure it out by following the code, but it's usually much easier and quicker to read a summary at the top level function. -
Consider perhaps, particularly if writting "advanced" or "complex" code or algorithms, that the skill level of those who will read your code is not the same as yours.
-
I try to comment in such a fashion that my code acts as an example and tutorial to someone totally new to it, new to the principles involved, and new to the libraries and frameworks involved.
That way if I want to go on a vacation
1. I don't have to worry about relaxing so much my brain falls out and I forget things when I get back.
2. Someone can fill in for me and requires less time to train up if they are new because the source itself is designed as example and tutorial to new people.
Granted I've only ever worked with one other programmer. Still worth learning to comment well, comment often, and comment clearly. It is a skill all it's own.
Related Rants
What frustrates me 'most' in coding is, putting comments...🙄🙄🙄
The frustration seems to go more than the 'most', when I don't find them and wonder, what the heck! 😠😠😠
rant
coding practices
developer
coding
devlife
commenting