Live data from Hacker News

Why is it so hard to see code from 5 minutes ago?

web.eecs.utk.edu

271–280 of 424 posts

Re: Why is it so hard to see code from 5 minutes ago?

#271

For me "Local History" feature in WebStorm solves the issue. https://www.jetbrains.com/help/webstorm/local-history.html

I've only recently started using JetBrains tools - and I did not know this feature existed!

Thanks for mentioning it - absolutely perfect!

Re: Why is it so hard to see code from 5 minutes ago?

#272
My goofy lil' homemade editor does it this way: If you go back in the past and change it, the future becomes the past. This might sound confusing, but effectively it means that the undo stack contains the actual history of "what happened". This means you can hop to any past or future state linearly with undo & redo alone. I just find this easier than navigating tree GUIs and things that aren't worth the trouble to me. It can still lead to a bit of mental gymnastics in extreme cases.

https://github.com/zaboople/klonk

Note that in theory this can cause an exponential growth of the undo/redo stacks because it makes an upside-down copy of the future when you change the past; but in practice it's never been an issue.

I was thinking of adding a feature to navigate back to "last change-the-past", which wouldn't be hard.

It at least makes more sense than most science fiction time-travel plots...

Re: Why is it so hard to see code from 5 minutes ago?

#273
post #226

For anyone that uses emacs, there is an excellent plugin "undo-tree" that solves this problem in a slightly different way. Everytime you undo a series of actions and then perform a new action, it creates a branch in the "tree". You can then visualize the tree and move through it quickly your entire buffer history.

Even without undo-tree, Emacs undo history is "persistent". By that I mean that changes aren't overwritten, so the statement in the article that undoing stuff and then making edits loses the undone changes is not true for Emacs. You just have to undo back through the new edits, then you will start to redo the old undone edits, and so on. It can be tedious, but just the knowledge that it's all there is quite liberatin…

And to get something closer to OP there is always undo-propose.el[1].

[1] https://github.com/jackkamm/undo-propose-el#screenshot

Re: Why is it so hard to see code from 5 minutes ago?

#274
post #250
post #16

> Why is it so hard to see code from 5 minutes ago while in the middle of a change? In vim you can do: :earlier 5m to see the code you had 5 minutes ago. > (1) If you go to a prior state and then make a new change, you can no longer redo and all those changes are lost. Vim makes a tree, so that doesn't happen with it. When you undo and make a new change, you're just making a new branch. u/Ctrl-r goes from leaf to tru…

> Most cool of all is that vim can persist the undo history. I don't know how common that is among editors, but in vim you can go to a file you haven't opened in years and undo it all the way to its beginning. I absolutely love this feature. I regularly open a file and undo/redo to figure out where I was editing last.

NetBeans also have this but it's set to 7 days as default. Never looked into this before, just thought it was broken but you can save it for eternity if you want :-)

Re: Why is it so hard to see code from 5 minutes ago?

#275

For anyone that uses emacs, there is an excellent plugin "undo-tree" that solves this problem in a slightly different way. Everytime you undo a series of actions and then perform a new action, it creates a branch in the "tree". You can then visualize the tree and move through it quickly your entire buffer history.

This was my first thought. A timeline is nice, but the problem with a linear undo history is that if you undo and then edit, you lose access to the state before you undid. A tree is clearly the right structure for undo history.

The tree structure is inherently flawed for storing undos when using features like undoing within a specific region, because the new state doesn't map to any previous node on the tree.

By default, Emacs has a linear undo structure, while still allowing you to never lose history.

Re: Why is it so hard to see code from 5 minutes ago?

#276
post #59

Earlier quoted context omitted.

Came here to post this. Tho most times my undo tree are single characters.

You should work on you long-term memory for the language's keywords, or on your variable naming ;-) EDIT: Or are you programming in APL?

guilty on the latter. tho only contributors to my packages and coworkers complain about it. I am fine with it.

Re: Why is it so hard to see code from 5 minutes ago?

#277
I've not seen it mentioned yet so I'd be remiss not to link to undo tree [1] for vim. I tend to put my list of plug-ins on a diet over time, but undotree is one I always kept! Having a visual of the history (like in the article) make it much easier to do a quick back and forth through time.

Also for fun, consider having your scroll wheel traverse time instead of space [2].

[1] https://github.com/mbbill/undotree [2] https://xkcd.com/1806/

Re: Why is it so hard to see code from 5 minutes ago?

#278
post #16

> Why is it so hard to see code from 5 minutes ago while in the middle of a change? In vim you can do: :earlier 5m to see the code you had 5 minutes ago. > (1) If you go to a prior state and then make a new change, you can no longer redo and all those changes are lost. Vim makes a tree, so that doesn't happen with it. When you undo and make a new change, you're just making a new branch. u/Ctrl-r goes from leaf to tru…

This is excellent... for Vim users. A lot of developers either are not willing or haven't gotten around to learning the complexities of Vim, and use other IDEs like JetBrains or Eclipse. This workflow won't work for them.

And there are a lot of people, like myself, who do use vim regularly and somehow completely missed this feature. For those people the OPs post is excellent.

Likewise, if you have any recommendations for your preferred workflow I'm sure some will find it useful. Hopefully those who don't use your preferred $EDITOR don't then rush to complain that not everyone uses $EDITOR. ;)

Re: Why is it so hard to see code from 5 minutes ago?

#279
post #111

Earlier quoted context omitted.

Hello from the bizarro universe of people who do this all the time and can't imagine the opposite. Do you never rewrite some code only to realize it didn't precisely capture all the edge cases of the thing you rewrote? In those cases I use the git gutter in VSCode to view what the old code looked like and compare and contrast to the new version to see what I missed. It seems to me that that's the same as what these e…

If there’s a specific implementation that’s especially hairy, I’ll just copy that block and comment it out before continuing. Instant reference. And if I’m rewriting more than 10 or so lines at a time of complex business logic, something is wrong. But also, `git diff`.

Thought the same, copy-pasting valuable blocks as a reference into a comment worked fine. If it exceeds a one block rewrite, make small dirty commits to keep track of things.

On one hand it's nice that there are tools to support devs who get lost in their undo-redo history, on the other I feel like it's a matter of good habits to not even have this problem.

of course changing habits is hard, so maybe tooling is justified in this case. I'm just happy I don't have nother "history" type mental model to deal with.

Re: Why is it so hard to see code from 5 minutes ago?

#280
post #228

Earlier quoted context omitted.

> the wrong way is not constructive. Well, open minded people can try other ways. Mine is sitting back and thinking instead of racing the keyboard to try out stuff until it works. Both ways (as I compare to my exclusively younger colleagues) reap results in about the same timespan, but I hardly type more than the actual code I need to type while my colleagues write and delete books ('iterate fast') in that time. It b…

> productivity of an employee by keystrokes, screen changes and # of commits. Aaargh, that's the most quality destroying metric possible.

[deleted]
Post reply on HN