4 ms·
Type safety isn't binary but a spectrum. It's obvious that C++ is more type-safe than JS but less than Rust, which is less than Haskell.
by maleldil 2y ago
Type safety isn't binary but a spectrum. It's obvious that C++ is more type-safe than JS but less than Rust, which is less than Haskell.
- eru 2y agoWell, at some points it becomes even more complicated than just a spectrum. Your types in different languages just track different things. Eg Haskell's types (normally) don't track lifetimes nor ownership, but Rust does that. In contrast, Haskell likes to track whether side-effects like IO can occur at all, while Rust is happy to just let you eg open a file almost anywhere.
- chuckadams 2y agoHaskell has linear types now, so there's your lifetime and ownership, though thankfully they're optional... wrangling linear types makes Rust look friendly and lenient.
- eru 2y agoNice! I've only used linear types in Clean ages ago, but haven't checked them out in Haskell, yet.
- JonChesterfield 2y agoC++ is obviously hilariously less type safe than JavaScript. JavaScript will convert values from one type to a other at runtime but it's always absolutely sure what the type of the value is. C++ will compile code that looks reasonable, decide it's UB, not tell you about that and proceed to do abject nonsense at runtime. Considering C++ the more "type safe" one of the two is so far from accurate that I wonder if you've mistyped the name of one of the languages.
- eru 2y agoI have a lot of sympathy for your point of view. Though have a look at Rust: it's generally considered much more typesafe than both JavaScript and C++, but it also has (some) dark corners of undefined behaviour with approximately all the same baggage as C++. See also https://news.ycombinator.com/item?id=8206562 https://news.ycombinator.com/item?id=8206562 for a different point of view: dynamically typed languages are equivalent to statically typed languages with just a single static type.