IDE discovery - do not make copies of INO files in project folder!

I'm new to using the Arduino IDE for ESP8266 development.

I often make a copy of source files as a backup. Getting ready to make a big change to myprogram.c? Just copy it into myprogram-8-May-2020.c, right?

Definitely not with Arduino IDE! I created a backup .INO file, and later had all kinds of strange errors when I started compiling the project. No way the small change I made to the project would cause those errors. Examining the errors, I see that the backup file was also being compiled ?!?!?.

Anyway, removing the backup files solved the issue. So I conclude the rule is no other files in the project folder. Maybe this is well known Arduino IDE behavior but it threw me for a while. Hope this helps someone else!

It's a well-known property of the IDE: all .ino files in the sketch directory are concatenated and compiled as a single entity. You should have ended up with multiple "tabs" displayed, which would have been a clue (though perhaps not until after the IDE had been restarted?)

The Arduino IDE will only compile source files in the root of the source folder and under the src subfolder, so you could create a subfolder of the sketch to put your backups in. One tricky thing is that the Arduino IDE will discard non-source files and any files outside the sketch root folder when you do a "File > Save as". The exception is the subfolder named "data" the entire contents of that folder will be brought along with the source files when you do a "Save as", so you might put your backup folder under the data subfolder if you want the backups to persist in all copies of the sketch.

For any serious development work, I highly recommend using Git for version control. It does have a bit of a learning curve, so probably not something to for people just getting started, but it's really a game changer from my old "caveman" version control system of having a bunch of copies of files I used to use. Git client software makes the learning curve a lot less steep by wrapping the common Git functionality in a GUI. I started with the GitHub Desktop client software, which was the most beginner friendly option at that time.

Copy the whole directory ("folder") instead - or just use github - so changes are tracked, experimental work can go into a branch, etc - plus then it's all backed up in the cloud and can easily be sync'ed between devices.

If using Windows then right click on sketch.ino and select 'Send to -> Compressed (zipped) folder'. The zipped file is created in the sketch folder root and is not included in the IDE. Another bonus is creating more than one copy of the sketch will result in sequential zip filenames so you can backup multiple times over the project and have crude versioning with zip filename.