I’m a big fan of tools like PMD, FindBugs, checkstyle, etc. Those tools are really helpful. Thanks to them you don’t need to worry about many small issues. You don’t have to verify whether an author of the code you are reviewing follows coding standards or other agreed practices. Your tools will do it for you.
Sunday, May 8, 2016
Monday, May 2, 2016
Need some explanation?
As developers we are doing everything what we can to increase the quality of the code we are working on. To make it easier, we learn to use new tools, techniques and practices. Each tool makes us stronger and better weaponized for the fight for the sake of the code quality.
However, a tool won’t be useful until we use it according to its design and intended purpose.
What are the main reasons behind doing a code review? In my opinion they include sharing knowledge (learning and teaching) and increasing readability and understandability of the written code.
However, a tool won’t be useful until we use it according to its design and intended purpose.
What are the main reasons behind doing a code review? In my opinion they include sharing knowledge (learning and teaching) and increasing readability and understandability of the written code.
Wednesday, April 20, 2016
Code Review and Single Responsibility Principle
According to the Single Responsibility Principle each unit in our code should have only one reason to change.
Code Review, on the other hand, is a technique that helps us improve the quality of our code and increase its readability.
I believe that you know both the principle and the technique.
The question is: why do I juxtapose them in one article?
Well, if SRP is about one reason to change code, then I think that code in the review should be organized around one change. The author should organize the commit of the code which is sent to the review in a way that will reflect only one change.
That’s why we should make code review as small as possible. To decrease the effort that must be put into this activity.
More things that are merged can go unnoticed..
When the code that is put to the review, it has various reasons for modifications than, except for everything I mentioned in the previous paragraph, we need to carry out two additional activities: switch contexts and group changes into subsets organized around each change. And we also have to remember that each change can have an impact on another.
So the amount of the effort and time that reviewer needs to invest into a code review is:
I heard more than once that “it is better/easier/faster to do one code review instead of many, because you will do a review only once”. As you can see, though, putting many things into a code review is not simple multiplication of effort needed for one review.
Unfortunately there is additional complexity in this equation.
Such thing doesn’t help when you have to find a root cause of some issue or you want to understand some part of the functionality. It is hard because of the same reasons that make the review of such code hard - complexity and presence of many contexts.
Let’s organize our commits around a single change.
Let’s make things simple and easier for us and all of those who will read the code.
Code Review, on the other hand, is a technique that helps us improve the quality of our code and increase its readability.
I believe that you know both the principle and the technique.
The question is: why do I juxtapose them in one article?
Well, if SRP is about one reason to change code, then I think that code in the review should be organized around one change. The author should organize the commit of the code which is sent to the review in a way that will reflect only one change.
Code Review and the effort
Code review is really useful and important. However, it requires some amount of effort from the reviewer. A developer that will read the code will have to understand what needs to be implemented. They need to know whether expectations are met. They need to have enough understanding to verify the quality of the code and its readability. All of it requires both time and full attention. During the review, if you want to do it right, you have to stay focused.That’s why we should make code review as small as possible. To decrease the effort that must be put into this activity.
Code Review and only one change
Many changes mean that you are jumping from one place to another and you are trying to figure out which change is the reason of which modification of the code. It makes reading the code harder, because you need to keep in mind many contexts and reasons. It makes it harder to find bugs in such situation.More things that are merged can go unnoticed..
When the code that is put to the review, it has various reasons for modifications than, except for everything I mentioned in the previous paragraph, we need to carry out two additional activities: switch contexts and group changes into subsets organized around each change. And we also have to remember that each change can have an impact on another.
So the amount of the effort and time that reviewer needs to invest into a code review is:
Number of changes * effort needed for one change + switching the context + understanding implication
I heard more than once that “it is better/easier/faster to do one code review instead of many, because you will do a review only once”. As you can see, though, putting many things into a code review is not simple multiplication of effort needed for one review.
Unfortunately there is additional complexity in this equation.
Many changes in one review
The additional complexity of the review is not the only thing that stands against putting many changes into one commit. What is also important, many changes in one commit mean less readable history so when you want to find something, it would be harder because some changes will be merged with other changes. What would be the name of your commit in that case? It will need to either focus on the most important change or it will be something meaningless, because you will try to use one sentence to explain many things that were modified.Such thing doesn’t help when you have to find a root cause of some issue or you want to understand some part of the functionality. It is hard because of the same reasons that make the review of such code hard - complexity and presence of many contexts.
One change at a time
What do you think about this idea?Let’s organize our commits around a single change.
Let’s make things simple and easier for us and all of those who will read the code.
Tuesday, April 5, 2016
First for test, second for implementation!
Test-Driven Development is a great technique, isn’t it? Today I want to propose you an experiment that may help you convince all of those struggling developers that writing code in such manner really improves your code and development.
What is the experiment about? It’s about only one, tiny commit which will force you to practice this technique for some time. Talk with your team/teams and propose a new way of doing pull requests. The first commit for test, the second for implementation. Easy, isn’t it?
What is the experiment about? It’s about only one, tiny commit which will force you to practice this technique for some time. Talk with your team/teams and propose a new way of doing pull requests. The first commit for test, the second for implementation. Easy, isn’t it?
Thursday, March 24, 2016
The places where you want to be
Today I would just like to invite you to a few conferences/event where I will have a pleasure to talk.
Friday, March 18, 2016
The first exception changes the rules of the game
We are developers who care. On a daily basis we use techniques and practices that help us make our code easier to maintain, develop and understand. We carry out code reviews, pair programming, TDD, etc. We use tools that allow us to automate many things. We have rules that help us protect common coding standards and design practices. Rules that we agreed to follow. Rules that help us improve the quality of our code and its design.
Yet, there is a one challenging thing in following the rules. If you agreed to follow them, you should not allow for any exception. Why? Because the first exception is the first step for more exceptions. The more exceptions are made, the less valuable the rule becomes.
Yet, there is a one challenging thing in following the rules. If you agreed to follow them, you should not allow for any exception. Why? Because the first exception is the first step for more exceptions. The more exceptions are made, the less valuable the rule becomes.
Wednesday, March 16, 2016
@Autowired all the things!
Recently I have written that @Autowired annotation make our lives easier in that it allows us to write less code. However, using it may often make your design more complicated. Especially when we are talking about using it on class’s properties. It makes it easier to violate Single Responsibility Principle. It makes it easier not to notice that.
It is ok to use @Autowired with properties, yet, I think, that presence of the constructor visualizes the problem with too many dependencies when it occurs. Even without exercising additional care from our side.
It is ok to use @Autowired with properties, yet, I think, that presence of the constructor visualizes the problem with too many dependencies when it occurs. Even without exercising additional care from our side.
Subscribe to:
Posts (Atom)