Live data from Hacker News

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

web.eecs.utk.edu

221–230 of 424 posts

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

#221

Earlier quoted context omitted.

As an aside, I think I wouldn't mind if a programming language would include two commenting syntaxes, one for ordinary comments, and another for commenting out. These are two very different use-cases, and distinguishing them syntactically might facilitate certain kinds of work-flows.

In C, you can wrap the 'commented' code with #if 0 ... #endif

I would do a bit more by

   #if !defined(this_works_but_it_suck_memory_too_hard)
   ....
   #else
   ....
   #endif
That should give me a clue why I "disabled" it when I come back to it 5 minutes later.

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

#223
For this I use:

a) git add and git diff --cache

b) :w and git diff (or git diff HEAD to compare a+b)

c) nmap d :w !diff -u % -

so that’s three diffs / four different stages.

If I need more I also don’t refrain to use sequences of temporary commits I rework with git reset master + git add -p and/or git rebase -i

So overall there’s no fear of early commitment to be had.

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

#224

In Sublime Text I actually use a quick Undo-then-Redo to navigate , of all things. I'll be typing some code and realise I need to check whether the imports at the top of the file are correct. So I'll Cmd+Up (go to the top of the file) and see that yes, they are correct. Now I have to get back to where I was. A quick Cmd+Z,Cmd+Shift+Z does the trick - Undo (takes me back to the code I was editing, and undoes some of i…

Funny, I've been using the same trick in VSCode without reflecting on it.

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

#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 liberating.

Another vanilla feature I sometimes use to keep track of old code is the "kill ring". Just cut the old code and it will be available in there later if needed.

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

#227
post #172

Jetbrains IDEs have a local history feature that provides snapshots with diffs and allows partial rollbacks. I only use it when experimenting with different approaches. Mostly I only use the "Local Changes" tab in the Git panel that shows the diff compared to the last commit, or "Compare with branch" to see the overall changes relative to the base branch.

Local history saved my sorry butt yesterday when I thought I lost all my files due to a git-related accident. But Local History still had all my changes and restored my files. Unclear why this isn't baked into the OS nowadays. It's not like we don't have enough disk space ;)

I just saw something similar on Twitter[1]: a script that takes a ZFS snapshot after every command. This lets you jump back to the state of the whole filesystem after every single command that you ran, giving you a sort of global history.

I figure you could adapt that to something a bit more restrained that you could use on an ongoing basis to have a "Local History"-style feature for your whole OS :).

[1]: https://twitter.com/grhmc/status/1362222849662935041

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

#228

Sad to see so much judgement in this thread from developers who can't fathom why others would need this. "Sounds like trial an error." "Develop a better memory." Programming is not black and white, there is no right or wrong way to do it. OP discovered a problem they had and wrote a solution for it, believing that others might need to solve the same problem. Clearly they were correct based on plenty of others chiming…

> 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.

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

#230

Sad to see so much judgement in this thread from developers who can't fathom why others would need this. "Sounds like trial an error." "Develop a better memory." Programming is not black and white, there is no right or wrong way to do it. OP discovered a problem they had and wrote a solution for it, believing that others might need to solve the same problem. Clearly they were correct based on plenty of others chiming…

> 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…

It sounds like you are a software engineer. My advise for you being confronted with these metrics is to look around a bit at other workplaces. I am not saying that you should quit, but it doesn't need to be this way.
Post reply on HN