Tags:
There is always those quite obvious things such as "don't be a jerk". Those are not the ones I will be talking now.
I want to talk about what I learned in those many years reviewing code and getting my code reviewed.
Whoever wrote the code you are reviewing thought hard about that code. Hardly someone just writes carelessly some code, so if something is not clear, instead of saying the implementation is wrong or not ideal, try to understand and ask questions to clarify why it was done the way it was.
Sometimes when you read a code you don't like and ask the author of the commit to change to your way, they might find your alternative as bad you think the code was. IF there is a clear advantage of your alternative, write it down clearly. You are working in a team, not alone, so your way is not necessarily the right way. Also, not always you are seeing the big picture.
Examples of alternatives with data:
some_class get_operation(read_only_conn &db, const std::string &operation_id) {
return std::move(db.get_operation(operation_id));
}
Please remove std::move from get_operation to enable copy elision when returning the operation data.
Copy elision documentation from cppreference
Example 2:
some_class *get_operation(read_only_conn &db, const std::string &operation_id) {
return new Operation(db.get_operation(operation_id));
}
Please use unique_ptr
or shared_ptr
as our policy doesn't allow to use raw pointer unless it's necessary by external dependencies or there is a considerable performance impact by its use.
Please see policy documentation
Always understand the big picture, otherwise you're doing the work of a style checker/linter.
Given the code:
int totalize(const std::vector<int> &v, int pos) {
int total = 0;
for(int i=0; i < pos.size(); ++i) {
total += v[i];
}
return total;
}
Examples of a bad review comment:
size_t
for i instead of int as size_t
might be bigger then int and overflowExamples of good review comments:
either<int,error>
To wrap up: