I'm surprised everyone is treating owned and unowned refs as if they were 
something new. C++ has owned and unowned refs. In C++, they're called 
"std::unique_ptr" and "dumb pointers." The semantics of the C++ version are 
almost exactly the same as the semantics of the nim version - the one 
difference is that in the newruntime, before you release the owned ref, you're 
required to manually clear out any dangling unowned refs - and it verifies that 
you have done that. In C++, you're not required to clear out the unowned refs. 
But, that means that in C++, you can end up with dangling unowned refs.

It would actually be very easy to implement the newruntime's semantics in C++, 
because C++ smart pointers are very flexible. Anybody could have done this at 
any time. But anybody considering this would have immediately understood the 
cost tradeoffs: you pay the performance penalty of maintaining the reference 
counts, and you pay the price of doing the extra work to clear out the unowned 
refs. In exchange, any code that would have accessed a dangling ref will access 
a nil pointer instead - which is better, because it's a caught error. I think 
it's telling that this is not a common thing to do - perhaps this indicates 
that most programmers don't consider these tradeoffs worthwhile.

Reply via email to