Windows crashes, Arduino file gone.

I see that this is not news. There are post from about six years ago and again earlier this year. Well here's another one as it happened to me just hours ago.

I run a pretty convoluted system in my workshop. Extraneous wires running hither and fro. I am undoubtedly my own worst enemy when it comes to the bizarre and frequently deal with events that no self-respecting hacker should even need to be aware of. So it came as no great surprise, to me, when fiddling with USB to TTL cables and adapters and power leads to stepper motors with logic coming from an Arduino connected to yet another serial port, a blue screen popped up and started a reboot.

What did surprise me was that when I restarted all my apps-that-were-in-use at the time, Arduino's IDE presented me with a file full of nulls. Nothing. Nada. Rien.

I've even examined it with a hex editor and its all zeros. So, the file is history.

Not such an issue for me as some hours earlier I unsuccessfully tried and new non-liner acceleration algorithm and saved that file under a separate name. The 4 or so hours of not insignificant edits since then however, went up in smoke.

Now correct me if I'm wrong, but it's my understanding the the IDE saves to disk the current work in progress each time you compile and upload. This is good. It seems though, that the file remains open for writing or appending all the time you're working with it. This is dangerous.

I like the concept of continuous backup, but not exclusively to a single file that is vulnerable. Allow me to introduce you to a method used by another software house that produces such glorious products as 3DSMax. My models quickly grow into the tens of megabytes and I truly say that I would be devastated if something like what just happened occurred to me while working in Max. What happens in that environment though, is every 10 minutes or sooner if I say so, the current work-in-progress is saved. It is saved however, in a file with a numerically sequential suffix added to it. OK, so your directory quickly fills with multi-megabyte files 001 thru 999 but that just means a bit of housekeeping (And you can elect to turn it off). It's nice to be able to go back to a specific point in time and recover where you were at if everything goes pear-shaped. It's like a big UNDO button.

Something like this would be easy to implement within the Arduino IDE and with the file sizes being only a few K, the draw down of resources wouldn't be as noticeable. Maybe Arduino 2.0.0.

DKWatson:
Now correct me if I'm wrong, but it's my understanding the the IDE saves to disk the current work in progress each time you compile and upload.

Only if you have File > Preferences > Save when verifying or uploading checked.

DKWatson:
This is good.

I actually really don't like that behavior. It might be a useful feature but I don't think it should be turned on by default since it's unexpected that any application would automatically save your file. I frequently am tinkering around with sketches and uploading to see what the results are but don't want to save any changes I've made. It's almost caused me serious problems several times when my preferences were reverted due to me starting fresh for beta testing and I forgot to disable that behavior but luckily I'm very good about backups and version control so I was able to recover my previous code without too much work. Much better would be for the automatic backup to use a different filename, as you have suggested. This would need to have a different extension or be in a subfolder since any .ino file in the sketch folder will show up as a tab and be compiled which would cause all sorts of problems.