4 ms·
https://en.wikipedia.org/wiki/Principle_of_least_astonishment#Formulation https://en.wikipedia.org/wiki/Principle_of_least_astonishmen... Here's another:
by thangalin 4y ago
https://en.wikipedia.org/wiki/Principle_of_least_astonishment#Formulation https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...
Here's another:
string path = "/tmp/filename.txt";
FileInfo f = new FileInfo( path );
File.CreateText( path ).Dispose();
Assert.True( f.Exists );
f.Delete();
Assert.False( f.Exists );
Astonishingly, the test fails because the result of Exists is cached. ¯\_(ツ)_/¯
My expectation is that if I put two things that are identical---for all intents and purposes---into a set, only one copy is added to the set. Likewise, upon deleting a file, I expect that testing for its existence always returns false. Both of these expectations are based on my mental models for math and file systems.
I haven't tested the behaviour of caching file states in Java, but I suspect it will return false if the file is deleted. Point being, in my limited time with C#, I've found it to violate the principle of least astonishment in ways that Java does not.