I think the best way to prevent cheating, at least for in class timed tests, is to make them non-trivial.
Multiple choice, simple fact recall -> easy to cheat
Real idea synthesis, non-trivial 'show your work' calculation required -> hard to cheat
It comes down to amount of data that needs to be moved surreptitiously to mimic a correct answer. When you frame it that way it almost looks like a problem in the security domain (secret keys, side-channel data leak, time bound attack)
Unfortunately it's also the case that: simple fact recall -> less need to cheat. Non-trivial calculation -> more need to cheat.
There are other reasons to not use simple fact recall type tests, of course. Like actually testing transfer.
But, in support of what you said: I went to Uppsala University in Sweden, and all exams were 6h long and happened in a giant special-purposed exam hall with 6 feet spaces between each desk. Cheating by communicating was a lost cause and even if you could, the amount of info you'd need to transfer to make a dent in a 6h-long test would be way too large. I don't recall anyone trying to cheat, but if it was to happen, it would have been done by adding notes to the bible-sized book of tables and formulae that we almost always were allowed to use.
> Real idea synthesis, non-trivial 'show your work' calculation required -> hard to cheat
And also harder to evaluate and grade; the professor or TA must be willing to invest an hour or several in reading through the longer answers to see where the students went right or wrong. That would be no problem in a hypothetical ideal educational framework, but realistically TAs (even at Stanford) aren't always that dedicated.
Multiple choice, simple fact recall -> easy to cheat
Real idea synthesis, non-trivial 'show your work' calculation required -> hard to cheat
It comes down to amount of data that needs to be moved surreptitiously to mimic a correct answer. When you frame it that way it almost looks like a problem in the security domain (secret keys, side-channel data leak, time bound attack)