I took over some code that hadn't been developed since 2002 and I looked through the patches sent against it over time. All these patches were in unified diff format, which apparently is the de facto standard for submitting code improvements. Here's what one patch looked like:
@@ -365,7 +385,10 @@
return () unless defined $op_sym;
$a_or_b = $op->[OPCODE] ne "+" ? 0 : 1 unless defined $a_or_b;
- return ( $op_sym, $seqs->[$a_or_b][$op->[$a_or_b]] );
+ my $line = $seqs->[$a_or_b][$op->[$a_or_b]];
+ my @ret = ( $op_sym, $line );
+ return @ret;
}
How exactly am I supposed to figure out what this change does in context? The patch doesn't tell me what subroutine it affects. I'd have to open the original file, go to line 365, and mentally replace the existing lines there that correspond to '-' lines in the patch file with the '+' lines in the patch file. WTF?
To preserve my sanity, I ended up creating a copy of the original file
as file.orig
, running patch
on file
, then using a visual diff tool on file.orig
and file
to actually see what the patch was doing.
My question is: why don't people spare each other the effort and just send the entire files they've changed?
Can most developers who accept patches figure out instantly what the patch refers to in their code? What if it removes a line that appears often in the file? Will they know which occurrence, in which subroutine, the patch affects?
Maybe patches made sense back in the day when bandwidth was precious, but come on: a source code file normally has under 10,000 lines of code, which means less than 50k. 50k of text get transferred even through the crappiest connection in seconds, even without text compression. I agree that patch files are good for simple changes, like typo fixes.
However, I have yet to see a developer asking for significant code contributions the via whole files. Everyone says "patches welcome" and they expect unified diff. Do they not end up comparing the files side-by-side in a visual diff tool? What about character-level intra-line differences? A patch file doesn't show those.
Am I the only one who prefers to visually diff?