To confuse matters further, the file saving strategy differs not only between text editors but within the same text editor depending on the context. There are basically two robust strategies for file saves:
1. Write new version to newly created foo.txt~ and atomically rename foo.txt~ to foo.txt.
2. Copy backup of foo.txt to foo.txt~, overwrite foo.txt in place with new version, delete foo.txt~.
Option 1 has better transactional properties (new file has no concurrent readers, original version doesn't have to be restored after crash) and requires less IO but breaks hardlinks.
I haven't surveyed the implementation of different editors to check under which circumstances they choose which strategy but at least in vim's case I know from straces that it defaults to 1 but switches to 2 if the file has multiple hardlinks to avoid breaking them. Some editors always do 1 and others always do 2.
@pervognsen Vim has an option for this ('backupcopy').
Also, some tools (IIRC 'crontab -e' is one of them) break if you use the wrong backup strategy.
I was a much happier person before I knew any of that.
@pervognsen @bcantrill Oh, I'm aware of that, I still think Windows got this right and the people pointing at *that infamous issue* got it wrong.
The only issue there is with UI.
POSIX file handling semantics are *fundamentally broken and you can not build correctness on top of them*.
@pervognsen @bcantrill No, I'd still argue they made the right choice, because there is no fundamentally correct way to implement that semantic.
It isn't just UI, it's also developer education, but there's a reason why Windows is pretty much the only OS used in environments with strict regulations around file-based records.