I think somebody could write a safe C++ library, but the STL hands out dangling references like candy at Halloween. It's very easy to get use-after-free problems with it.
I don't know what you are talking about. (What I meant was, the need for pointer arithmetic can be avoided by using iterators, and use-after-free, by using smart pointers.)
Iterators don't do what you think they do. A random access iterator on std::vector is practically indistinguishable from a pointer. It doesn't check for out of bounds, and if you resize the vector, your iterator can be "invalidated", meaning it quietly points to memory that has been freed already.
You can even do arithmetic on random access iterators the way you do with pointers.
That's because you actually haven't used C++ that much or you haven't used js that much or both. In practice, despite the type system, it is actually less safe. There are bugs in C++ that are so subtle nobody can find it for years.
Javascript is practically safer because each crash leaves an incredibly obvious stack trace about what caused the crash. It leads to programs with less bugs then C++.
Another really wacky part is this (Nombas ScriptEase) is the same JS engine used in BeOS NetPositive. Be licensed it, though the layout engine was in-house.
12 comments
[ 4.9 ms ] story [ 31.8 ms ] threadI can see that.
Iterators don't do what you think they do. A random access iterator on std::vector is practically indistinguishable from a pointer. It doesn't check for out of bounds, and if you resize the vector, your iterator can be "invalidated", meaning it quietly points to memory that has been freed already.
You can even do arithmetic on random access iterators the way you do with pointers.
I agree that smart pointers are nice.
Javascript is practically safer because each crash leaves an incredibly obvious stack trace about what caused the crash. It leads to programs with less bugs then C++.
It would be cool to see a style or testing guide to see how they prevented bugs from shipping.
[0] https://brent-noorda.com/nombas/us/index.htm
I used to find this surprising. I still do, but I used to, too.
[0] https://news.ycombinator.com/item?id=23403800