Live data from Hacker News

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

web.eecs.utk.edu

261–270 of 424 posts

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

#261
post #203

Earlier quoted context omitted.

Or indeed if rewriting a block of code: #if 1 ....new code... #else ....old code... #endif Esp. for tricky stuff, it's then possible to just flip the 1/0 to easily test/compare/profile the new/old code. Some IDE's will even work out which block of code to colour and which to dim.

Why have I never thought of that?

I do the same, even in languages without a preprocessor.

You can just use a life if-else, most compilers will optimize the test-on-a-constant away. Even when the code is kept in, I doubt it will have a major performance impact during testing in most cases.

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

#262

Earlier quoted context omitted.

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.

I am one of those "not willing" people. I encounter the same issue discussed here without even thinking about it, and solve it as such: 1. Realize I need to check how my new code looked like 5 min back. 2. Copy full file into clipboard, undo by a few steps 3. Do a temp commit on GitHub desktop 4. Paste the new code back and look at the diff on GitHub desktop, and if needed undo the temp commit from above. Is this mor…

Not so sure about this, I think it depends on how frequently you have to do that task. If you're doing it every day or even every week you could potentially be saving a huge amount of time and effort by using a tool that does the job well. It's sort of like using a random heavy object as a hammer, sure it's fine in a pinch if you need to occasionally hang a picture but if you're working as a carpenter it's counter productive. Comparing it to the notorious abuse of excel spreadsheets in finance is not doing the argument any favours.

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

#264
post #206

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

This feature is absolutely outstanding, I use it all the time. Unfortunately they buried it in the "File" menu recently. It was so much easier to reach when it was unter "Version Control".

You can assign a custom shortcut to it via Settings > Keymap and then the action "Main Menu > File > Local History". I myself have assigned the shortcut control+shift+=

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

#265

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.

It's not a formal distinction, but in C++ code where all the ordinary comments use //, it can be handy to use /* ... */ to comment out a block.

(Of course, if there's a stray /* ... */ comment already in the area to be commented out, this will fail. But an editor with appropriate syntax colouring can make that immediately apparent.)

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

#266

Earlier quoted context omitted.

I would 100% use this! I do exactly what is described in the note. I use undo/redo a lot to traverse between two states of code and found this incredibly frustrating. Until this point I thought that was just a bad practice on my end, so never saw the need/opportunity for something like a state slider. Honestly never thought other people were using undo/redo like this.

I also use undo/redo like this and it has gotten me into frustrating locations on a couple of occasions... but still better than needing to break my flow to drop into making some well formed commit. I understand how to do WIP commits etc, but its helpful to do a rewind/fast-forward that includes all the character changes in-between the logical “blocks” of diffs. It often helps me recapture approaches to problems that…

I used to use the history function in NetBeans to do this. Has been around for several years apparently. Many other editors seems to have this function too.

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

#267

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 frequently just comment out the code and rewrite it anew

That still doesn't give you easy access to the state of the code _halfway through the rewrite_, which is what the article mentions.

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

#269

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.

VSCode also has a local history plugin. One of my default installs https://marketplace.visualstudio.com/items?itemName=xyz.loca...

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

#270
post #209

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.

I have the feeling JetBrains do not understand how important this feature is for some developers. It does not have a shortcut and recently got buried in the File menu, almost as if they are ashamed of it. I am using it all the time and life would be much harder without it.

In NetBeans there is two big buttons on top of every file view. Source and History. Very easy to get to and has been used a lot :-)
Post reply on HN