Inspecting someone’s code with an eye towards improvement
6 March 2023
Inspecting someone’s code with an eye towards improvement
Inspecting someone’s code with an eye towards improvement
It’s not unlike peer review of scientific publications
Author: writes the code and sends it for review
Reviewer: reads the code and makes comments/suggestions
Author and reviewer should be clear on roles & expectations
f()
on lines 11-20”)Be honest and direct
f()
affect g()
?)“Be tough on the code, but easy on the author”
What you said:
easy
”What you said:
easy
”What they heard:
Consider these 2 statements:
“Change A
to a
”
“Perhaps we could change uppercase parameter names to lowercase?”
#1 is combative whereas #2 is cooperative
Attach reasons to requests
Receiving feedback can be tough, so offer concrete solutions to soften the blow
%>%
instead of nested functions?”Begin reviews with high-level comments
f()
into g()
and h()
”Begin reviews with high-level comments
f()
into g()
and h()
”and then focus on details
b <- a + 1
”You’re asked to review function f()
g()
if it affects f()
f()
looks great but I found a bug in h()
”Imagine easy
is misspelled everywhere
eesy
to easy
”eesy
to easy
”a <- 1 b <- 2 a + b c <- 3 (c - a) / b
becomes
## parameter definitions a <- 1 b <- 2 c <- 3 ## step 1: addition a + b ## step 2: division (c - a) / b
Nitpicks can be microaggressions
[P]rogrammers are very unlikable people… In aviation, for example, people who greatly overestimate their level of skill are all dead.
– Philip Greenspun
By design, reviews target faults
Litter your review with the things you like
Most code reviews are done asynchronously (eg, pull request on GitHub)
Newcomers can be overwhelmed with styles, culture, people
Organizations or labs should set clear expectations and guidelines
Improvements should not be limited to code, but to processes as well
Embrace collaboration platforms like GitHub
Options include:
code snippet in an email
post to Slack
Recall our discussion of minimal working examples
“fosters a culture that values open and reproducible research using shared data and reusable software”
Uses GitHub’s infrastructure with a focus on issues for package reviews
Be kind
Be thorough
Be honest
Be supportive
Be timely