Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen to use visual diffing vs. unified diff patch files?
    text
    copied!<p><strong>NOTE</strong>: This question was originally asked in the pre-GitHub era.</p> <hr> <p>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 <a href="http://en.wikipedia.org/wiki/Diff#Unified_format" rel="nofollow noreferrer">unified diff</a> format, which apparently is the de facto standard for submitting code improvements. Here's what one patch looked like:</p> <pre><code>@@ -365,7 +385,10 @@ return () unless defined $op_sym; $a_or_b = $op-&gt;[OPCODE] ne "+" ? 0 : 1 unless defined $a_or_b; - return ( $op_sym, $seqs-&gt;[$a_or_b][$op-&gt;[$a_or_b]] ); + my $line = $seqs-&gt;[$a_or_b][$op-&gt;[$a_or_b]]; + my @ret = ( $op_sym, $line ); + return @ret; } </code></pre> <p>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?</p> <p>To preserve my sanity, I ended up creating a copy of the original <code>file</code> as <code>file.orig</code>, running <code>patch</code> on <code>file</code>, then using a visual diff tool on <code>file.orig</code> and <code>file</code> to actually see what the patch was doing.</p> <p><strong>The question is: when does it make sense to send the entire file, and when does it make sense to send patch files?</strong></p> <p>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?</p> <p>Maybe patches made sense back in the day when bandwidth was precious, but bandwidth nowadays renders that concern obsolete. I agree that patch files are good for simple changes, like typo fixes.</p> <p>However, I have yet to see a developer asking for significant code contributions via whole files (even before GitHub or Google Code came along). Everyone said "patches welcome" and expected unified diff. Do they not end up comparing the files side-by-side in a visual diff tool? What about <a href="http://www.scootersoftware.com/images/TextMerge.png" rel="nofollow noreferrer">character-level intra-line differences</a>? A patch file doesn't show those.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload