You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
In some of my previous posts (for example [in this one](/2017/09/11/clean-code-meaningful-names.html "clean code
20
-
meaningful names")), I talked about my new experience at [lastminute.com group](https://lmgroup.lastminute.com/
21
-
"lastminute.com group") and how much we care about code quality. In fact I already talked about the fact that we do
22
-
[pair programming during our daily job](/2018/01/16/ide-refactoring-android-studio-xcode-appcode-webstorm-jetbrains.html"pair programming").
23
-
But pair programming is not the only techniques we use to be sure that our software matches high
24
-
code quality standard :sunglasses:.
25
-
One of the most important procedure I use during my daily job with my colleagues is code review. What is it? Let's
26
-
see a standard definition from [wikipedia](https://en.wikipedia.org/wiki/Code_review"code review"):
27
-
28
-
>A code review is a process where two or more developers visually inspect a set of program code, typically, several times. The code can be a method, a class, or an entire program. The main code-review objectives are:
29
-
>* Best Practice: a more efficient, less error-prone, or more elegant way to accomplish a given task.
30
-
>* Error Detection: discovering logical or transitional errors.
31
-
>* Vulnerability Exposure: identifying and averting common vulnerabilities like Cross-Site Scripting,
32
-
Injection, Buffer Overflow, Excessive Disclosure, etc.
33
-
>* Malware Discovery ~ This often-overlooked and very special code-review objective looks for segments of code that appear extraneous, questionable, or flat-out weird. The intent is to discover back doors, Trojans, and time bombs.
34
-
In today’s world malevolent code is a very real threat and should not be overlooked, especially by Government agencies.
35
-
36
-
The definition is simple and clear. Basically you go through the code of another guy (or from a couple if they are
37
-
doing pair programming) to find errors, bugs, code style/best practice not compliant to the team set of rules.
38
-
Three weeks ago I attended a coding dojo with my colleagues [Angelo Sciarra](https://www.linkedin.com/in/angelosciarra/"Angelo Sciarra").
39
-
Angelo is a senior full-stack software engineer with many years of experience.
40
-
You may wonder now what is also a coding dojo. So again, here we are with
41
-
another [definition](http://codingdojo.org/WhatIsCodingDojo/"coding dojo") :bowtie::
42
-
43
-
> A Coding Dojo is a meeting where a bunch of coders get together to work on a programming challenge. They have fun
44
-
and they engage in order to improve their skills.
19
+
In some of my previous posts (for example [in this one](/2017/09/11/clean-code-meaningful-names.html"clean code meaningful names")), I talked about my new experience at [lastminute.com group](https://lmgroup.lastminute.com/"lastminute.com group") and how much we care about code quality. In fact I already talked about the fact that we do [pair programming during our daily job](/2018/01/16/ide-refactoring-android-studio-xcode-appcode-webstorm-jetbrains.html"pair programming"). But pair programming is not the only techniques we use to be sure that our software matches high code quality standard :sunglasses:. One of the most important procedure I use during my daily job with my colleagues is code review. What is it? Let's see a standard definition from [wikipedia](https://en.wikipedia.org/wiki/Code_review"code review"):
20
+
21
+
>A code review is a process where two or more developers visually inspect a set of program code, typically, several times. The code can be a method, a class, or an entire program. The main code-review objectives are:
22
+
>
23
+
>* Best Practice: a more efficient, less error-prone, or more elegant way to accomplish a given task.
24
+
>* Error Detection: discovering logical or transitional errors.
25
+
>* Vulnerability Exposure: identifying and averting common vulnerabilities like Cross-Site Scripting, Injection, Buffer Overflow, Excessive Disclosure, etc.
26
+
>* Malware Discovery ~ This often-overlooked and very special code-review objective looks for segments of code that appear extraneous, questionable, or flat-out weird. The intent is to discover back doors, Trojans, and time bombs.
27
+
>
28
+
>In today’s world malevolent code is a very real threat and should not be overlooked, especially by Government agencies.
29
+
30
+
The definition is simple and clear. Basically you go through the code of another guy (or from a couple if they are doing pair programming) to find errors, bugs, code style/best practice not compliant to the team set of rules.
31
+
Three weeks ago I attended a coding dojo with my colleagues [Angelo Sciarra](https://www.linkedin.com/in/angelosciarra/"Angelo Sciarra"). Angelo is a senior full-stack software engineer with many years of experience. You may wonder now what is also a coding dojo. So again, here we are with another [definition](http://codingdojo.org/WhatIsCodingDojo/"coding dojo") :bowtie::
32
+
33
+
> A Coding Dojo is a meeting where a bunch of coders get together to work on a programming challenge. They have fun and they engage in order to improve their skills.
45
34
46
35
During the dojo that I attended with Angelo we tried to resolve the [Minesweeper problem](http://codingdojo.org/kata/Minesweeper/"Minesweeper").
47
36
Basically we had to write an automatic Minesweeper resolver (do you remember the Windows game? :heart_eyes:). At the end of the dojo we didn't complete the task, so I decided to try to solve it in another way. I developed a complete command line version of a Minesweeper resolver and let Angelo do the code review of my implementation.
48
37
In this way I can show you the power of code review :neckbeard: (and last but not least how much meticulous is Angelo
49
38
during his code review :cold_sweat::sweat_smile::cupid:).
50
-
Before starting, I suggest you to have a look at [this repository](https://github.com/chicio/Minesweeper"Minesweeper kata dojo") that contains the entire Minesweeper implementation I develop and, on the [Code review pull request](https://github.com/chicio/Minesweeper/pull/1) opened on this repo you can find the observation/new implementation from Angelo. Usually
51
-
the code reviewer doesn't implement by himself/herself the stuff of his/her observation, but in this case we did it so
52
-
that we can share the code before/after the code review in a pull request (and also to show you the Angelo's skills
53
-
:heart_eyes:).
39
+
Before starting, I suggest you to have a look at [this repository](https://github.com/chicio/Minesweeper"Minesweeper kata dojo") that contains the entire Minesweeper implementation I develop and, on the [Code review pull request](https://github.com/chicio/Minesweeper/pull/1) opened on this repo you can find the observation/new implementation from Angelo. Usually the code reviewer doesn't implement by himself/herself the stuff of his/her observation, but in this case we did it so that we can share the code before/after the code review in a pull request (and also to show you the Angelo's skills :heart_eyes:).
54
40
To facilitate you in the navigation of the two different implementations I created two [class diagram](https://en.wikipedia.org/wiki/Class_diagram"class diagram"): one that describe my implementation before the code review, and the second one that shows the final result after Angelo's code review. The following one describes my implementation of the minesweeper.
55
41
56
-
{% include blog-lazy-image.html description="fabrizio duroni minesweeper" width="1075" height="1615" src="/assets/images/posts/minesweeper-fabrizio.jpg" %}
42
+
{% include blog-lazy-image.html description="Class diagram of my personal implementation of minesweeper" width="1075" height="1615" src="/assets/images/posts/minesweeper-fabrizio.jpg" %}
57
43
58
44
This one describes Angelo's implementation.
59
45
60
-
{% include blog-lazy-image.html description="angelo sciarra minesweeper" width="1033" height="1620" src="/assets/images/posts/minesweeper-angelo.jpg" %}
46
+
{% include blog-lazy-image.html description="Class diagram of Angelo Sciarra implementation of minesweeper" width="1033" height="1620" src="/assets/images/posts/minesweeper-angelo.jpg" %}
61
47
62
48
So let's start to see which kind of observation I received from Angelo, that basically include most of the observation you could receive during a code review.
63
-
The first observation I received from Angelo is about the java JDK version I used for my project. I did the setup of
64
-
the project using JDK 1.5 instead of JDK 1.8 (as you may know, this is a more recent version). In general it is
65
-
common to receive suggestion about technology specific problems/setup/changes, especially if your code reviewer is
66
-
more experienced than you on that type of technology.
49
+
The first observation I received from Angelo is about the java JDK version I used for my project. I did the setup of the project using JDK 1.5 instead of JDK 1.8 (as you may know, this is a more recent version). In general it is common to receive suggestion about technology specific problems/setup/changes, especially if your code reviewer is more experienced than you on that type of technology.
67
50
68
-
{% include blog-lazy-image.html description="technology version update" width="1500" height="901" src="/assets/images/posts/01-technology-version-update.jpg" %}
51
+
{% include blog-lazy-image.html description="Technology update from Java 1.5 to Java 1.8" width="1500" height="901" src="/assets/images/posts/01-technology-version-update.jpg" %}
69
52
70
-
In fact Angelo gave me another technology advice during his review. He suggested to change some pieces of code with
71
-
others that leverage the power of functional programming. This is really interesting because it is easy
72
-
imagine how much knowledge you can absorb from the experience of your code reviewer.
53
+
In fact Angelo gave me another technology advice during his review. He suggested to change some pieces of code with others that leverage the power of functional programming. This is really interesting because it is easy imagine how much knowledge you can absorb from the experience of your code reviewer.
73
54
74
-
{% include blog-lazy-image.html description="functional update" width="1500" height="901" src="/assets/images/posts/03-functional-field.jpg" %}
75
-
{% include blog-lazy-image.html description="functional update with new class" width="1500" height="901" src="/assets/images/posts/04-new-fields-class.jpg" %}
55
+
{% include blog-lazy-image.html description="Functional improvements to the original class" width="1500" height="901" src="/assets/images/posts/03-functional-field.jpg" %}
56
+
{% include blog-lazy-image.html description="A new field class has been introduced to describe a list of fields" width="1500" height="901" src="/assets/images/posts/04-new-fields-class.jpg" %}
76
57
77
-
Another important aspect that is one of the main subject of the code review is software design. In fact Angelo
78
-
discovered a series of improvement and refactoring opportunities in my code:
58
+
Another important aspect that is one of the main subject of the code review is software design. In fact Angelo discovered a series of improvement and refactoring opportunities in my code:
79
59
80
-
* the `Minesweeper` class doesn't need to receive the fields input at construction time but directly in the `play()`
81
-
method. In this way the `Minesweeper` class becomes a stateless object, and the same instance could be used to
82
-
resolve/unmask multiple fields input.
60
+
* the `Minesweeper` class doesn't need to receive the fields input at construction time but directly in the `play()` method. In this way the `Minesweeper` class becomes a stateless object, and the same instance could be used to resolve/unmask multiple fields input.
83
61
84
-
{% include blog-lazy-image.html description="stateless object" width="1500" height="901" src="/assets/images/posts/02-minesweeper-fields-as-parameter.jpg" %}
62
+
{% include blog-lazy-image.html description="Minesweeper class is now a stateless object" width="1500" height="901" src="/assets/images/posts/02-minesweeper-fields-as-parameter.jpg" %}
85
63
86
64
* The objects that are the building block of a [chain of responsibility](https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern"chain of responsability") named `FieldRowParser` could become lighter and some of their responsibility could be assigned to some new collaborators. Also the object that contains the parsing status could become more lighter.
87
65
88
-
{% include blog-lazy-image.html description="lightweight chain" width="1500" height="901" src="/assets/images/posts/05-lightweight-chain.jpg" %}
89
-
{% include blog-lazy-image.html description="parsing status" width="1500" height="901" src="/assets/images/posts/07-parsing-status-become-parsing-content-lightweight.jpg" %}
66
+
{% include blog-lazy-image.html description="A lightweight chain has been introduced for the row parsing" width="1500" height="901" src="/assets/images/posts/05-lightweight-chain.jpg" %}
67
+
{% include blog-lazy-image.html description="A new ParsingContext class keeps the current status of the parsing" width="1500" height="901" src="/assets/images/posts/07-parsing-status-become-parsing-content-lightweight.jpg" %}
90
68
91
69
As you can see from these kind of comments the code review could really improve the general architectural design of your application :heart_eyes::relieved:.
92
70
Code convention are another important thing to check during code review. For example Angelo told me to move all the constants at the beginning of some of the classes. Usually tools like Github or Gitlab let you discuss your code review by adding comments directly to the code.
93
71
94
-
{% include blog-lazy-image.html description="constants position" width="1500" height="893" src="/assets/images/posts/08-constants-beginning-of-file.jpg" %}
95
-
{% include blog-lazy-image.html description="guidelines comments" width="1500" height="891" src="/assets/images/posts/06-guidelines.jpg" %}
72
+
{% include blog-lazy-image.html description="Constants should be at the top of the class" width="1500" height="893" src="/assets/images/posts/08-constants-beginning-of-file.jpg" %}
73
+
{% include blog-lazy-image.html description="A comment related to a team guideline" width="1500" height="891" src="/assets/images/posts/06-guidelines.jpg" %}
96
74
97
75
Last but not least, if you are a real fan of clean code, you know that [meaningful names are important](/2017/09/11/clean-code-meaningful-names.html"clean code meaningful names"). So you can suggest some more meaningful name for a class, variable or method.
98
76
99
-
{% include blog-lazy-image.html description="rename" width="1500" height="901" src="/assets/images/posts/10-rename-masker.jpg" %}
77
+
{% include blog-lazy-image.html description="An example of using meaningful names" width="1500" height="901" src="/assets/images/posts/10-rename-masker.jpg" %}
100
78
101
79
That's all for code review. I hope you understood how much important it is to do it and how much your codebase can improve if you use code review as a validation tool and as a tool to find new refactoring opportunities (anyway, I hope Angelo will never be your reviewer :laughing::sparkling_heart:).
0 commit comments