News for hackers. Stuff that matters.

Ask HN: Why not edit all code in 'diff' view?

70% of coding is maintenance. Often you are replacing logic that might still be relevant, but requires a tweak. Why not show a live diff as you work? This keeps you in context without forcing you to comment out or write 'parallel' code.
( 10 comments | 26 points | on HN )
Re:Ask HN: Why not edit all code in 'diff' view? by hon on Thursday March 02, 2017 @02:22PM (#13777300)
Xcode has this except it's called Comparison view. It's one of the things I love about working in Xcode.
Re:Ask HN: Why not edit all code in 'diff' view? by gus_massa on Thursday March 02, 2017 @03:34PM (#13777928)
Re:Ask HN: Why not edit all code in 'diff' view? by z1mm32m4n on Thursday March 02, 2017 @08:03PM (#13779912)
In addition to the other tools people have mentioned, Vim supports this with tpope's vim-fugitive (:Gdiff)

To answer your question, "... why not?":

* oftentimes when I'm writing code I'd rather split the screen with another relevant file

* sometimes the diff is irrelevant (I started from scratch, or primarily added code instead of modifying or removing it)

* other times, it's enough to know only that a line has changed. I've configured Vim (with vim-git-gutter) to show symbols next to added and removed lines

Re:Ask HN: Why not edit all code in 'diff' view? by twitchard on Friday March 03, 2017 @01:08AM (#13781068)
If you tdd, you will write the test for the new code while the old code is still available, and you will use the test as a guide rather than the old code.

Even if you don't tdd, I would say that typically if you understand the code well enough to make a change, you should be able to write a replacement without referring to the old code. The diff should fit in your mind, so to speak. There are some exceptions, like when you're modifying a regex or some dense, opaque shell command, but in the course of modifying typical code I can't see a live diff being that useful to me

Re:Ask HN: Why not edit all code in 'diff' view? by tedmiston on Thursday March 02, 2017 @06:34PM (#13779394)
I constantly reference the Tower (https://www.git-tower.com/mac/) current diff view while coding a new feature or hotfix. It would be awesome to have that level of integration in Sublime. GitGutter is a great add-on package but way more limited in scope.
Re:Ask HN: Why not edit all code in 'diff' view? by miguelrochefort on Thursday March 02, 2017 @04:05PM (#13778211)
All IDEs provide that...
Re:Ask HN: Why not edit all code in 'diff' view? by jaimex2 on Thursday March 02, 2017 @07:29PM (#13779740)
my thoughts exactly.
Re:Ask HN: Why not edit all code in 'diff' view? by gus_massa on Thursday March 02, 2017 @02:10PM (#13777189)
Looks like a nice idea. I'd like an option to toggle between normal view and diff view. Perhaps you can write a plugin for your favorite text editor.
Re:Ask HN: Why not edit all code in 'diff' view? by ajeet_dhaliwal on Thursday March 02, 2017 @07:44PM (#13779822)
It's easy enough to diff and un-diff and I'd rather have the full window while editing, especially on a laptop.
Re:Ask HN: Why not edit all code in 'diff' view? by itamarst on Saturday March 04, 2017 @07:58AM (#13790709)
Anyone know of version of this for emacs?