3 ms·
Diff works best when things are single idea per line, and when control structures don't get in the way. One example - the use of the trinary (?:) operator as a
by zdw 15y ago
Diff works best when things are single idea per line, and when control structures don't get in the way.
One example - the use of the trinary (?:) operator as a replacement for if/else assignment statement can quick and easy when programming. The problem is that diffs with it can look like a total mess because a whole lot of things are happening in that one line.
Similarly, certain languages where program flow or control structures make it so that people are inclined to make many things happen in one line (inline regex, lisp or scheme syntax lanagues) can diff in a confusing manner.
Diff is great when everyone is using a coding/whitespace standard, and things tend to atomically happen on one line.
I'd encourage that when refactoring code that's not to the standard, you do two passes - one to clean up the code to the standard, then another to make the actual changes.
- gbog 15y agoYes, and commit on every smallest atomic refactorings.
- stcredzero 15y agoI've used environments with quick and reliable Undo/Redo stacks. To be completely compatible, one would have to treat code as data in a "nondestructive" editing scheme and save off the actual refactoring steps, which can then be committed automatically. Or maybe, a "quick snapshot" facility could be developed to make it easier to save off intermediate steps and commit the series of them automatically.
- makecheck 15y agoI definitely agree with doing formatting/nonfunctional changes independently from other changes. In general all commits should be as focused as possible: have one purpose, don't just change whatever else you happened to think of while editing the same file. A "diff" is also incredibly useful prior to a commit to make sure that you changed only what you thought you did. Programmers should go to great lengths to adopt a style that is "diff compatible" so they aren't likely to miss anything important.
- memset 15y agoGood point on making separate commits for "whitespace" versus "content" We currently have pep8 (python style checker) as a git commit hook, and the first few times we used it, we'd have 10 lines of legitimately modified code and then 100 lines of "style corrections." Usually I commit my changes first, and then do another pass with style changes. Maybe it would be easier if I did it the other way around - whitespace pull request first, followed by the actual change.
- cpeterso 15y ago> * Diff works best when things are single idea per line, and when control structures don't get in the way.* Has "coding to a diff" changed your coding style? When I know that I will have to prepare a diff for code review, I find myself writing code in a way that produces a cleaner diff. I use more vertical whitespace to collect related code into logical "paragraphs" and keep from stepping on other code when diffing.