Live data from Hacker News

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

web.eecs.utk.edu

321–330 of 424 posts

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

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

> I'm stunned and disillusioned.

I think you simply don't understand the workflow... when and why people do this.

Generally, the idea of referring to an older version of code while working on a later version is good and useful, is it not?

This is just one way of doing this.

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

#323

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…

My approach is similar to this, except for whole functions/classes I tend to just create a new one with a version number. e.g. DataContext => DataContext2. When I'm satisfied that DataContext2 does everything that DataContext does, I delete old one and rename DataContext2 => DataContext. The risk here, is that sometimes it's not possible to migrate everything to the new version and you end up with multiple old versio…

I do this too! A big benefit is gradual migration - for example, if I'm injecting DataContext into a bunch of different places, I can implement part of the functionality of DataContext. Once I have just enough functionality implemented to support one of the places it's injected, I update that place to take DataContext2. Then I can test, and move on to the next place.

If you're using a language with strong typing and good refactoring support (right now that's C#/Visual Studio for me), the eventual rename from DataContext2 to DataContext is a non-event.

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

#324
Advantages to this approach to referring to an older version of code that alternatives may not have:

* works well entirely through keyboard shortcuts (especially useful when editing code)

* the shortcuts are standard so you already know them and have them committed to memory

* works across editors

* high granularity of control over exactly which version of the old code to refer to

Undo trees seem like the best alternative, since it can be done strictly as an extension to convention undo/redo... a little HUD can let you see your current location in the tree and the normal keys can be used to navigate it, with the addition of one more shortcut to change branch.

The "separate window with panning control" suggested in the article seems awful to me.

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

#325

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…

"Sounds like trial and error" Isn't that what coding is?

Maybe to some extent, but most of coding in my experience is planning things out, figuring out exactly what you're trying to do and then just writing it.

Bug fixes have a bit more trial and error to them obviously, but it's usually not reading entire code blocks.

If some function becomes too gordian I start working on a refactoring branch to fix it.

I also use 2+ monitors so I experience very little of the code deletion issues referenced here.

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

#326

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…

I do the same. Many people comment about commiting frequently but that doesn't work for me: delete code + commit => I don't see the code anymore and my brain magically forgets about it. I need the quick feedback loop: commented code + uncommented code (all in one screen) => new code is going to look like a mix of both. If I have to use git to see commented code then the feedback loop is broken.

I get this for tracking down a bug or working on speeding a block up. But why does the unused code need to be committed? Yes it helps you with your one problem but it clutters the document with extra information for others. So I guess I phrased my question a little accusatory, commented out code is a pet-peeve of mine, but I'm still genuinely interested why the two different blocks need to be committed. Or i guess more importantly, if they need to be pushed to the mainline for others to recieve

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

#327

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…

I do it very occasionally, usually when I realize I need some form of code that I've deleted. I'll undo, copy the code, redo up to where I'm at, then paste and edit as necessary.

But I don't do this every 5 minutes, that's just mind boggling. And my reason for doing it isn't that I can't remember or couldn't recreate, it's that I use copy/paste a lot to avoid errors from typo's and the like.

It just seems weird to have to do this that often.

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

#328

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…

I do the same. Many people comment about commiting frequently but that doesn't work for me: delete code + commit => I don't see the code anymore and my brain magically forgets about it. I need the quick feedback loop: commented code + uncommented code (all in one screen) => new code is going to look like a mix of both. If I have to use git to see commented code then the feedback loop is broken.

Commiting frequently also has a substantial cost of needing to think of a commit message.

If you don't think of a commit message, you'll never be able to find this version again. If you think up a message every 2 minutes, you'll quickly find you spend more time thinking of commit messages than writing code.

I wish there was some kind of auto generated commit message. Things like:

"Added function xyz()" or "Adjusted constant FOO to 27" or "Made lots of changes in file a.c,, b.c and c.c".

These could be auto generated, and then commits could happen in the background every time the code is compiled.

It would be nice for git to have some kind of "commit of commits" which allows a hierarchical representation of commits. Ie. the "Add new printscreen feature" could have as subcommits "Create print renderer" and "Hook up print UI".

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

#330

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.

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

I thought //// was psuedo reserved for documentation. and then // was for general comments. I usually use block comments for commenting out code or I just use VS hotkeys which I think are //
Post reply on HN