{"id":6563,"date":"2021-11-16T12:07:20","date_gmt":"2021-11-16T11:07:20","guid":{"rendered":"http:\/\/blog.bart.sk\/en\/?p=6563"},"modified":"2024-01-29T10:29:43","modified_gmt":"2024-01-29T09:29:43","slug":"code-review-responsibly-success-project-depends","status":"publish","type":"post","link":"https:\/\/blog.bart.sk\/en\/code-review-responsibly-success-project-depends\/","title":{"rendered":"Do code review responsibly &#8211; the success of the project depends on it"},"content":{"rendered":"\n<p><span style=\"font-weight: 400;\">The success of a project can be assessed based on the hours worked or from the managerial point of view <\/span><span style=\"font-weight: 400;\">\u2013<\/span> <span style=\"font-weight: 400;\">&nbsp;based on the value delivered to the customer. If the customer&#8217;s business goals are met, it&#8217;s a success.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">At Bart.sk, we focus on long-term projects and long-term customer goals. Completing and submitting a short project is relatively easy. Delivering a quality product perpetually and consistently over a long period of time is something that requires a different perspective on how to write and maintain code.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Code review is one of the tools for increasing the quality of your team and the code itself. It&#8217;s basically a process in which one or more people check your code before it&#8217;s incorporated into a project.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">You can meet the code review as a merge request (MR) on GitLab or a pull request (PR) on GitHub. Hereafter, I use the term MR, because we work on GitLab, but it&#8217;s the same thing.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Why is code review important?<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">We all see our code as the best thing that we managed to cough up that day. But the truth is that if we spend a lot of time solving a specific problem, our perception of the problem may shrink and we&#8217;ll miss the broader context. For example, that our function or component solves one particular problem, but we forget to treat some inputs for which we can&#8217;t think of a use-case.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In the same way, all variables, feature names and algorithms are very clear to us. But it usually helps when someone else looks at the code and checks if it reads well. Most of the time, programmers just read the code anyway.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In our company, reviewers often try out the code themselves. For example, when it comes to an MR for a part of a UI, they can come up with improvements, and if they try to use the UI in a way the programmer didn&#8217;t intend, they will find bugs.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If you also involve QA (Quality Assurance) in a MR, you can find mistakes even at this stage, which will save you time later.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">I see the main benefit of a MR in increasing code quality and reducing the number of bugs, but no less important thing is that everyone involved learns thanks to a MR. They learn to use technology, they get to know the project.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">From my experience, I can tell you that everyone makes mistakes. Seniority doesn&#8217;t matter. One can still learn something new.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Code review can also be used for an internal workshop. E.g. <\/span><a href=\"https:\/\/blog.bart.sk\/stano-svidran-je-super-ze-v-ramci-firmy-sa-je-vzdy-kde-posuvat\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-weight: 400;\">Stano<\/span><\/a><span style=\"font-weight: 400;\"> recently did a workshop where he explained to us on a relatively large MR how he migrated code to the latest Angular, commit after commit.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>What a good MR looks like<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">It&#8217;s usually true that a MR should have an excellent name and an excellent description so that even a new teammate would be able to do a code review.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If it&#8217;s bug fixing, describe how the bug manifests, in which environment, on what account and what the exact steps to replicate it are. With a new feature, it&#8217;s great if the description includes e.g. design, specification, requirements and other specifying information. Then the reviewer can get a good overview of what they&#8217;re going to check.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Pay attention to the range as well. Personally, as a reviewer, I prefer to have ten MRs with one change to one MR with ten changes. Then I lose focus a little. In other words:<\/span><\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p><i><span style=\"font-weight: 400;\">10 lines of code = 10 issues.<\/span><\/i><\/p>\n\n\n\n<p><i><span style=\"font-weight: 400;\">500 lines of code = \u2018looks fine\u2019.<\/span><\/i><\/p>\n\n\n\n<p><i><span style=\"font-weight: 400;\">Every code review<\/span><\/i><\/p>\n<\/blockquote>\n\n\n\n<p><span style=\"font-weight: 400;\">A good MR not only fixes a bug or adds a feature, but improves what&#8217;s already on the project.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In my opinion, however, the best MR is the one that takes away from the project instead of adding to it. If you fix a bug or add a feature while you&#8217;re at it, you deserve an extra plum dumpling for lunch.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/blog.bart.sk\/wp-content\/uploads\/2021\/11\/Screenshot-2021-11-15-at-18.43.42.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8250\" src=\"https:\/\/blog.bart.sk\/wp-content\/uploads\/2021\/11\/Screenshot-2021-11-15-at-18.43.42-300x192.png\" alt=\"\" width=\"400\" height=\"257\"><\/a><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><b>How to give feedback and not be a jerk<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">Many times I&#8217;ve encountered the view of junior programmers that they even like their code being criticised. From my point of view, this is a great mindset where the &#8220;hunger&#8221; to learn is greater than the ego. ? But be careful not to overdo it with criticism.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The most important principle of feedback giving is <\/span><span style=\"font-weight: 400;\">\u2013<\/span><span style=\"font-weight: 400;\"> don&#8217;t be a jerk. It&#8217;s usually enough to leave your ego at home and remember what gems you once coded. Everyone learns.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">At the beginning of the code review, try to absorb as much information about the code as possible. Mainly why it was created and what it has to solve.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">When you start evaluating and see that your colleague, in your opinion, has written complete nonsense, take a break and don&#8217;t write the review right away. If it doesn&#8217;t work for you even after a few minutes, and you&#8217;ve already checked the circumstances of that code, write in questions or at least don&#8217;t command. Offer improvements, suggestions. &#8216;Do you think it would be better if you used\u2026?&#8217;, &#8216;What if you tried this\u2026 algorithm&#8217;, &#8216;I think this could be solved this way&#8230;&#8217; At all times, try to be objective and try to keep your emotions in check.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If you do comment, insist on a satisfactory answer. The answer should never be that &#8216;this is just how we do it here&#8217; or &#8220;I copied it from the stack overflow&#8217;, or &#8216;we&#8217;ll fix it when it&#8217;s time&#8217; (spoiler alert: you won&#8217;t).<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">For programmers, communicating with other human beings is usually the reason why they prefer to communicate with computers. However, during code review, we must restore (or find) this forgotten soft skill. Text doesn&#8217;t carry much emotion, so use emoticons and communicate your criticism. Don&#8217;t be afraid to praise your colleague, it will be appreciated.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>When someone does a code review for you,<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">don&#8217;t take the comments personally.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">As programmers, we&#8217;re artists in a way, and when we create something, we&#8217;re proud of it and it isn\u2019t always easy to accept criticism. Especially after we&#8217;ve been working on something for hours or days. Anyway, it happens that we have errors in there or someone has a better idea or a better algorithm.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">We just have to take it humbly and learn something new. Welcome criticism with open arms. Feedback, even critical, is for the good of the project, you and your customer.<\/span><\/p>\n\n\n\n<blockquote class=\"wp-block-quote\">\n<p>To avoid criticism, do nothing, say nothing, and be nothing.<\/p>\n\n\n\n<p>Elbert Hubbard<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><b>How long should a code review last<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">This is a common question even in more experienced teams. Of course, if you&#8217;re expecting to receive a specific number, you&#8217;re waiting in vain.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">But try to think about what precedes the code review.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Usually, requirements are written, design is created, functional specifications and technical analysis are written and finally, programming starts.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The programmer must understand why they&#8217;re going to code something, what the context is, what the limitations, dependencies and requirements are. They usually code something, then rewrite it, find a better solution, rewrite it again and finally submit their code, which they worked on for two days, for code review.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Ask yourself, how much time do you need to understand the problem and check if the code delivers the promised value? Sometimes you even need to run the code, test it yourself and write valuable feedback. I don&#8217;t know how much time you need, but it will probably be a significant part of those two programming days.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Don&#8217;t waste time<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">There are many examples of how to waste time with code review. For example, you can search for missing semicolons or argue for weeks whether to use tabs or spaces, or whether to put a parenthesis in a new line or in the same one.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Try to fine-tune as many things as possible mechanically before the reviewer sees the code for the first time. Try to automate everything you know how to automate. But be careful not to let it slip out of your hands.<\/span><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/imgs.xkcd.com\/comics\/automation.png\" alt=\"\"\/><\/figure><\/div>\n\n\n<p class=\"has-text-align-center\"><span style=\"font-weight: 400;\">Source:<\/span> https:\/\/xkcd.com\/1319\/<\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In our company, we&#8217;ve arranged this so that after each push event in the merge request (meaning in the branch from which the MR is created) a pipeline is started (more about GitLab pipelines <\/span><a href=\"https:\/\/blog.bart.sk\/automaticky-deploy-aplikacie-cez-gitlab-cicd\/\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"font-weight: 400;\">here<\/span><\/a><span style=\"font-weight: 400;\">) where the following is checked:<\/span><\/p>\n\n\n\n<ul>\n<li><span style=\"font-weight: 400;\">whether the code is formatted according to the agreed code style,<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">whether it passes static analysis (set of rules for best practices),<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">whether unit tests pass,<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400;\">whether the project can be built.<\/span><\/li>\n<\/ul>\n\n\n\n<p><span style=\"font-weight: 400;\">Such a &#8220;clean&#8221; MR is then checked by two people, who can now fully devote themselves to looking for errors in logic, potential bugs, bottlenecks and inconsistencies, or moaning about wrong naming of variables for at least a little while.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">In the case of a MR of lower importance, one reviewer is enough.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Bonus: connection with issue tracker<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">You can program a connection with your favourite issue tracker in a few hours and it will save the programmers hundreds of hours.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Our automated link with JIRA ensures that a link to a specific JIRA issue is added to the MR description, which describes &#8216;what&#8217; and &#8216;why&#8217;. Programmers don&#8217;t have to write MR descriptions manually, all details, whether about a bug or a feature, are in the JIRA issue. The bonus is that issues in JIRA are automatically moved based on MR status. So the programmer doesn&#8217;t waste time on &#8220;bureaucracy&#8221;.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">This connection also allows us to create tables (below), which we show on daily stand-<\/span><span style=\"font-weight: 400;\">ups <\/span><span style=\"font-weight: 400;\">\u2013<\/span><span style=\"font-weight: 400;\"> the<\/span><span style=\"font-weight: 400;\">y show who has how many MRs assigned and in which version. Thanks to them, we have a quick overview of how busy we are and which MR needs to be prioritized.<\/span><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/blog.bart.sk\/wp-content\/uploads\/2021\/11\/image.png\"><img decoding=\"async\" src=\"https:\/\/blog.bart.sk\/wp-content\/uploads\/2021\/11\/image.png\" alt=\"\" class=\"wp-image-8254\"\/><\/a><\/figure><\/div>","protected":false},"excerpt":{"rendered":"The success of a project can be assessed based on the hours worked or from the managerial point&hellip;","protected":false},"author":27,"featured_media":6578,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":""},"categories":[199,211],"tags":[229,230,231],"_links":{"self":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts\/6563"}],"collection":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/comments?post=6563"}],"version-history":[{"count":8,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts\/6563\/revisions"}],"predecessor-version":[{"id":7373,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/posts\/6563\/revisions\/7373"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/media\/6578"}],"wp:attachment":[{"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/media?parent=6563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/categories?post=6563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bart.sk\/en\/wp-json\/wp\/v2\/tags?post=6563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}