194
Comments
  • 6
    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.
  • 4
    I 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 😅
  • 2
    SRP 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.
  • 1
    and then you duplicate your code. in all things you need a balance.
  • 2
    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.
  • 2
    @Jormungandr indeed! And the only one who appreciates clever code is you! Others will probably hate you for it 😅
  • 1
    @mrstebo I too try to follow this rule.
  • 0
    @krsna540 it refers to a collection of books about programming. Search for O'Reilly :)
  • 0
    Don'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.
  • 0
    @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.
Add Comment