I know I wax lyrical about comments a lot. Like, a lot. But they aren’t a button you can just push to make code better. So let’s take a look at some not-useful comments.
This month’s paper: Ding, Y et al. OvFilter: Unique k-mer guided overlap verification for long-read assembly in repetitive genomic regions. Bioinformatics 2026. doi: 10.1093/bioinformatics/btag886
Original code
The code for this paper is on GitHub.
Critique
Standard disclaimer: issues with published code are not necessarily anyone’s fault, and often are due to nothing more nefarious than time constraints.
Comments shouldn’t repeat the obvious
The first comment in ovfilter.cpp (the main part of a tool named
OvFilter) is for a struct:
// Filter stats structure
struct FilterStats {
long long self = 0;
long long contained = 0;
long long short_align = 0;
long long low_identity = 0;
long long overhang = 0;
long long no_unikmer = 0;
long long u_no_shared = 0;
long long u_min_shared = 0;
long long u_no_valid_seed = 0;
long long u_chain_break = 0;
long long u_tolerance = 0;
long long u_max_sd = 0;
long long unknown = 0;
void add(const FilterStats& o) {
self += o.self;
contained += o.contained;
short_align += o.short_align;
low_identity += o.low_identity;
overhang += o.overhang;
no_unikmer += o.no_unikmer;
u_no_shared += o.u_no_shared;
u_min_shared += o.u_min_shared;
u_no_valid_seed += o.u_no_valid_seed;
u_chain_break += o.u_chain_break;
u_tolerance += o.u_tolerance;
u_max_sd += o.u_max_sd;
unknown += o.unknown;
}
};
Okay. That tells me nothing. I know that this is a struct because C++ is picky
about making you declare stuff, so there’s that keyword struct right there.
And I know it’s for “filter stats” given the name FilterStats. Thus the
comment is repeating the obvious.
What else could it have done? Well, it could’ve summarized how and when to
create/manipulate an instance. Or it could’ve gone into more detail about what
kinds of stats it has. Or how those are “filter stats” specifically. I’ve looked
at this struct and I could not, for example, say what self means.
Basically, I’m looking for a comment to explain something useful to me. Blandly repeating something which is already plainly written isn’t useful.
English, please
// 计算悬垂比例和重复区比例,两者相乘得到一个“重复区惩罚分数” (Repeat Penalty Score, RPS)。
// RPS 越低越好(代表更符合真实比对特征),只有低于阈值 (rps_threshold) 才能被特赦。
// 真比对 (FN):悬垂小,能覆盖大部分重复区 -> RPS 低,被捞回。
// 假比对 (FP):悬垂大,深陷巨大的重复区 -> RPS 高,被拒绝。
double overhang_ratio = static_cast<double>(max_overhang) / align_len;
double repeat_ratio = static_cast<double>(rl_tag) / align_len;
I realize that all of the authors here have Chinese affiliations, but this is an English-langauge paper published in an English-language journal for an English reading audience. The global research community runs on English. For other people to understand the comments here, they should be written in English.
Remember, comments aren’t only for yourself. They’re also, much more, for everyone else. Even people who you don’t work with directly. Maybe especially for those people.
Useful comments explain the why
Let’s end on a positive note. Here are a few comments that I liked
// Load unique k-mers into a sorted vector (faster lookup, less memory than unordered_set)
vector<uint64_t> load_unikmers(const string& filepath, int k) {
// Check overhang using Minimap2's definition:
// A true overhang is the minimum of the unaligned lengths at the same side of the alignment.
// If one sequence aligns to its end, the overhang on that side is 0 (or small), which is valid.
bool check_overhang(int q_len, int q_start, int q_end, int t_len, int t_start, int t_end, char strand, int tol) {
// Only apply Repeat Rescue to cases where valid shared seeds were found but fell outside
// the boundary (NoValidSeed). This targets collinear signals truncated by repetitive regions.
if (fail_reason == "UnikmerFail_NoValidSeed" && rps_threshold > 0.0) {
Note that here the comments are explaining the thought process behind the code in a way that makes it easier to follow. Since people generally are incapable of mind-reading across the internet[citation needed] this is useful, non-obvious information for a reader. These are the kind of comments that add value to code. The other kinds… well, so long as they’re not wrong/confusing they’re of non-negative value. 0 is a non-negative number. I think it’s not unreasonable to aim for positive value, in general.
If there’s a recent paper you’d like me to look through, shoot me an email. Address in my CV.