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
-
This is always an argument with my colleagues. Some of them say that, the code and its tests should document itself. So you if your code is clean enough, you don't need any comments. Honestly I share this views as well, because the code and the comments can get easily out of sync.
-
mrstebo9288yI have got in to the habit of making really small classes and functions. If you start writing code in a class that is not doing what the class / method is describing then you just extract it out somewhere else. Makes everything nice and neat. Plus you don't end up with massive test files 😅.
The benefit of this is that you know exactly what your code is doing. There is no logic that is doing anything other than what is required to solve your problem.
It is a very tricky thing to get right and I am still constantly battling with myself to enforce this particular rule 😅 -
Chroma38ySRP is great. I do not want to have a class "Post" that has methods like "filterPosts", I rather create a new class "PostFilter" which does that. It makes it easier to test the code. Furthermore I do not have to be afraid to break something else if I adjust the filtering methods.
That does not mean that you always should enforce SRP. Rules have to be "bend" sometimes. Or sometimes you even break the rules. That does not mean that your code is bad. -
What everyone's trying to say is: please follow the Clean Code rules, and you won't have any problems. If your code is too complicated, maybe you should try a different approach.
-
mrstebo9288y@Jormungandr indeed! And the only one who appreciates clever code is you! Others will probably hate you for it 😅
-
@krsna540 it refers to a collection of books about programming. Search for O'Reilly :)
-
tkglaser1628yDon't comment your code. Comments don't compile, they're unreliable, they might even be misleading. If you can't understand your code you should really learn how to write cleaner code.
-
@tkglaser I find that to be true. I don't comment nearly as much as I should but whenever I look at my code it's clear enough that it's never an issue. I guess the other important part of that is don't write needlessly complicated code unless you have to.
Related Rants
-
erdlof16Pun of the day Boss: I heard your colleagues hate dealing with code you wrote. Why? Me: No comment
-
viadukt20Front-end developer's to-do list : ☑ Climb Everest ☑ Learn how to speak mandarin ☑ Become god ◻ Verti...
-
NiTr013"I wrote the code, I have to maintain the code, I wont need any comments" *some months later*
Every. Single. Time.
undefined
todo documentation comments shit
todo
comments