Live data from Hacker News

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

web.eecs.utk.edu

161–170 of 424 posts

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

#161

Earlier quoted context omitted.

If I have to commit my whole undo history then I’m using git very wrong. I commit (even temporarily) to save progress, but only when it makes sense to so. Sometimes I don’t know whether I’ll need this specific version again in the future.

Git doesn't mandate to only commit useful stuff.

This is correct, not sure why you’re getting downvotes. Feature branch for WIP makes sense.

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

#162

Earlier quoted context omitted.

I do the same - both commenting out and viewing the file in parallel at different spots - vim vertical splits are great for that. In fact, one of my colleagues remarked that he never thought to view the same file alongside itself when he saw me do that when we were pairing.

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.

A common code style rule for C# is // for comments and //// for commented out code (/// is reserved for documentation generation). StyleCop analyzers can enforce this during code analysis passes.

While this isn’t a language construct (a comment is a comment after all), Visual Studio can key off these stylistic differences to show code comments vs commented code differently. I find it to be a neat trick to improve code readability.

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

#163
post #50

Reading the comments, I'm stunned and disillusioned. Are most modern developers struggling to write code without this? If so, there is a fundamental problem that has nothing to do with levels of undo.

Likewise. This whole thread is totally bizarre. The closest imaginable thing I might do is wrapping some block of code in an if(false) {..} or #ifdef it out, when I'm refactoring and feeling unsure about my changes. But is that even the same thing that we're talking about here?

It’s amazing how many developers don’t have a working knowledge of fundamental tools - like version control and debuggers. I honestly don’t know how you could get hired without this basic knowledge.

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

#164
I'm fairly used to using basic undo/redo as a timeline already. I spam "undo" often in vim just to yank something into a scratch window. I might accidentally make a change that breaks my redo path back to the present, but thankfully that's a pretty rare occurrence for me (and I can always recover with "g-"). Good enough for me!

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

#165

When making changes to a block of code or block of text, I frequently just comment out the code and rewrite it anew. I might copy-paste existing code (just to avoid stupid transcription errors). If its too large to see both what I'm writing, and the old code, at the same time, I just use two windows on the same file. This is relevant to writing fiction or non-fiction as well. For example, I didn't like this, so I com…

Shouldn't it be "had he looked."? Also the second rendition makes doesn't include what the rest of the joggers are doing, yet the first one does. Not sure if intentional. At first I gasped at your practice, because I never do that, but I see the point now. Mastery of language.

Yes, I had a typo. I was editing in place, and then decided that I had made some poor choices and needed to start over. I didn't bother to fix the typo.

Yes, there is a shift in point of view between the two versions. But the story is mostly written in third-person limited, and so my first version deviated from that.

But I rewrite everything every time I read it, so who knows what will happen tomorrow.

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

#167

I'm fairly used to using basic undo/redo as a timeline already. I spam "undo" often in vim just to yank something into a scratch window. I might accidentally make a change that breaks my redo path back to the present, but thankfully that's a pretty rare occurrence for me (and I can always recover with "g-"). Good enough for me!

Vim is the only editor I’ve used that has a branching undo model. I know there’s a UX problem there but I don’t understand why more editors don’t support this.

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

#168
In Git you don’t have to actually commit, you can use the staging area. It’s something I do rather often. I’m going to make a non-trivial change and I’m not sure if it’s the right approach, so I `git add -A` first, make my change, and then `git diff —-cached` to review it. This is especially useful when doing things like running formatting tools, so I can see what the tool just did. And it doesn’t require making any commits.

Having said that, this approach only works if I know up front that I’m going to want to compare the code. Far more often is making a change and then realizing I want to see the old version. A history timeline would be extremely useful here.

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

#169

In Git you don’t have to actually commit, you can use the staging area. It’s something I do rather often. I’m going to make a non-trivial change and I’m not sure if it’s the right approach, so I `git add -A` first, make my change, and then `git diff —-cached` to review it. This is especially useful when doing things like running formatting tools, so I can see what the tool just did. And it doesn’t require making any…

Even commits are malleable until you push them somewhere. I do this a lot - create commits of any meaningful checkpoint, then rearrange/squash/remove commits later that I don’t want , to create a well-formed commit that I push.

Git stash can handle your use cases too, but commits are more powerful as they let you compose multiple pieces together

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

#170

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…

Development often times entails a lot of trial and error, and there is nothing wrong with that. If you have fast iteration cycles, you can fail many times before you settle on an optimal solution.
Post reply on HN