Programming languages and programs (as wells as individual functions, objects, etc.) are often described as being “safe” in one way or another. For example, they could be “type safe”, “memory safe”, “exception safe”, “thread safe” – even “reentrant”. Each of these concepts is about preventing erroneous or damaging code from executing, which makes them pretty important considerations in language and program design.
So if I wanted to be super-pedantic about safety, what are all the different kinds of safety I could consider? Or could there be any number of them, leaving me to hope that I know all the ones which could be important for me?
The context of the question involves comparing languages like Haskell to languages like C++: pure Haskell is great if you want to guarantee type, memory and thread safety. In C++, we can circumvent any of these. So I was thinking: “If we wanted to make a perfectly safe language, what are all the kinds of ‘safety’ that we could consider?”
2
Safety in all cases is about avoiding ambiguous state. If it’s memory it’s a question of “For a given unit of memory, what is stored there? How can one be sure?” Same with types. “For a given arbitrary piece of code, what rules does this code follow?”
The base idea is that you always want to be able to predict what output you will get, given a particular input.
2