Category: Coding best practices

  • Remove unused/dead code

    You have a room full of books and you don’t even have time to read them. Every week you clean the room and have to spend a lot of time organizing and cleaning up the clutter Wouldn’t it be reasonable to throw away things you don’t use so you don’t waste time on weekly cleaning?…

  • Use comments as a booster

    Don’t put comments in the code – this is one of the guidelines in the projects. Is it good? Imagine you are working with legacy code and analyzing one of the functionalities. After many long hours, you are finally done. You feel tired, but happy that you know what’s going on. You want to write…

  • Pass all parameters to function

    Your task is to simplify the testing of this function logic: How easy is it to test this function? Not complicated, but not trivial either. We can use mocking: As you can see, a certain amount of test code is needed. This example is simple, but imagine that you have more complex logic and classes…

  • Do not use the Service suffix

    Look at the names of classes: Do you guess what these services are responsible for, what they do, what functions/methods they contain? It is hard to guess. So why do we name classes like xxxService? Because it’s easy. We have a Book entity and without thinking we create a BookService and logic related to the…

  • Interface means strategy

    If you see an interface in the source code: what do you expect? I expect many (at least two) implementations: which we choose depending on certain conditions – such a mechanism is called a strategy pattern. Why am I writing about this? Because I have seen in many projects such code: Yes, interface and only…

  • Prefer Set over List

    When you look at this code what do you think, what do you expect? I expect a collection of people with possible duplicated elements: but I saw in many projects that developers use List to store unique objects: Photo Ryan McGuire from Pixabay, Photo by Alvin Balemesa on Unsplash You may ask: is that really a problem? Yes, it is. Why…

  • Do not put elephant into function

    Is it possible to put an elephant in a refrigerator? Hmmm, with the right approach, anything is possible. But why would I want to put an elephant in a refrigerator? Many programmers do not ask themselves this question and pass the elephant – a large class/object to a function and then use only one or…