Is it good practice to have applications remove old AppData files when they're no longer needed?
https://softwareengineering.stackexchange.com/questions/419553
-
18-03-2021 - |
Pergunta
I have a Desktop application that was saving some data to %AppData%\MyApp\old.txt
(roughly 1KB).
I have decided to rename the file that I write to to new.txt
.
If I push out this change, customer machines will now have a redundant old.txt
on their systems that won't be used for anything.
Is it good practice to add logic to my application like:
if exists("old.txt"):
if exists("new.txt"):
delete("old.txt")
else:
rename("old.txt", "new.txt")
...proceed using new.txt
Or is it not worth it?
In my case:
- The file is small so leaving it on the disk isn't that concerning
- In my particular situation, customers aren't even widely using the application yet, so this doesn't really affect many machines in practice
I guess the downside I'm thinking of is eventually this logic will become unnecessary since all machines will use the new file, so at some point, I'd then need to remove this logic. And I guess I don't have a good idea of when that would be.
Solução
IMHO chances are high it is not worth it - at least in this particular case.
Why?
First, the typical desktop machine gets either a complete reinstall of the operating system and installed software every few years, or it will be sorted out completely at its "end of life" - which means after some time, the file will vanish "automatically".
Second, as you wrote in a comment, the file is just used to restore the window bounds from the last session, so in case there will be an old file and a new file in parallel, chances are pretty low to cause any confusion or errors from this.
Note, if the file would be
larger
contain more important data
could pollute the MyApp folder with waste hindering to find the more important files
could disturb debugging scenarios
then the cost/effort balance might become different.
Outras dicas
You can schedule a scan and delete old files after a transient time to avoid potential backward incompatible issues. So in your current version you handle the case where new file does not work then fails over to the old file.