Code reviewing is a vital part of the coding process. It’s basically a software quality assurance activity during which a person reviews the source code of any program. When it comes to code reviewing, what are the broad level considerations?
- Better code quality: Is the code readable, uniform and understandable?
- Defects: Is the code correct? Or, are there performance problems, security vulnerabilities or malware? There could be both accidental errors (e.g. typos), as well as structural errors (e.g. dead code, logic or algorithm bugs, performance or architecture concerns), explains an article in Medium.
- Finding better solutions: A good code review will generate ideas for new and better solutions to the specific problems at hand.
A code reviewer is ultimately helping with knowledge transfer to the author of the code. Valerie Moyo, aged 25, works as a code reviewer for CoGrammar. What does she get up to on a day-to-day basis, and what tips can she offer for new coders?
Valerie has a Masters in Computer Science. This is fairly unusual for a coder. According to the 2018 Stack Overflow Developer Survey, only 1,2% have a PhD in computer science (or a related field), whereas most developers, 69% to be precise, are self-taught.
Her job as a code reviewer involves facilitating the learning process of students who are enrolled on one of HyperionDev’s bootcamps – Software Engineering, Full Stack Web Development or Mobile Development – and guiding them towards writing code that meets good coding practices. ‘I’ve always believed that anyone could code,’ says Valerie. ‘I have a passion for teaching, so when I read up about what code reviewing involved, I knew that CoGrammar was the right place. I then pursued code reviewing as a potential career path.’
Code Reviewing: What Do You Look For?
Valerie explains that there are three things she looks for when code reviewing her students’ work:
(1) Code Correctness
This is about writing code that is structured correctly and conforms to the syntax (or structural) rules of a programming language.
(2) Code Style
This aspect looks at whether the code is readable, modularized and well-documented.
Here’s an example of code correctness and style, using a JavaScript program that simply adds two numbers together and displays the result.
You would write something like this:
console.log(23 + 45);
To generalise your program, you would need to avoid using hard-coded values and find a way of storing those two numbers and using them in the calculation – that way, if you want to change the numbers to add, you would change them at one place in your program as opposed to several places throughout your program. Although this example is simple, imagine if you hard-coded values in a program with thousands of lines of code! Therefore, the program needs to be improved by creating two variables, which allow you to store values, before performing the addition and displaying the result via the console.
var x = 23; var y = 45; console.log(23 + 45);
Although this code is correct, you can improve the code correctness by removing the hard-coded addition and storing the result of the addition in a variable as follows:
var z = x + y; console.log(z);
Now we want to improve on code style by using variable names that are meaningful and descriptive – to improve readability.
var firstNumber = 23; var secondNumber = 45; var addition = firstNumber + secondNumber; console.log(addition)
Although this is a trivial example, it illustrates the general process we follow when reviewing code and ensuring that code meets best practice.
(3) Code Efficiency
Code efficiency is about ensuring that the code is implemented in a manner that requires fewer computational resources. This process can be rather complex when reviewing code as it involves determining the efficiency of your code using tools such as the Big(O) notation. However, the idea is that your code performs reliably, faster and optimally especially when developing programs for large-scale applications.
The Challenge of Code Reviewing
Code reviewing is a challenging yet fulfilling job. Says Valerie: ‘I really enjoy working with students who are learning to code for the first time. It’s intriguing to follow their thought processes. Sometimes, this even helps me to look at something differently. As a code reviewer, you must be prepared to review code that follows a completely different thought pattern or process from your own, which I do, because I enjoy discovering different ways of doing the same thing.’
In conclusion, code reviewing is not without its tricky components. ‘Developing a programming mindset can be challenging for novice programmers,’ says Valerie, ‘and I need to be able to deal with any frustration that may arise from this. If a student is overwhelmed and frustrated, I must be patient and gentle during those moments.’ If you want to become a code reviewer, Valerie advises that you have a ‘passion for teaching and learning’ as well as ‘patience’. Of course you also need to know the ins and outs of coding. Lastly, check out CoGrammar, where people can apply to become code reviewers.