Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's not a result of `int` not being subtyped. It's a result of forcing reference semantics on everything (which is something most languages unfortunately do).

C++ doesn't need this kind of restriction because it makes the difference between references and values explicit, so it's actually possible to explicitly ask for a vector of values, rather than only being able to ask for a vector of references and artificially restricting the language so that it can be optimised to a vector of values.

(Yeah I know you can't derive from int in C++ but that's for other reasons.)



Julia also has reference semantics for everything. That said, it turns out that if you make it idiomatic to create immutable structs, the difference between reference semantics and copy semantics disappears, and lets the compiler pick the faster one (which fixes a common performance bug in C++ where users end up copying a ton of data around by accidentally copying a bunch of data)


Yeah I always thought that "make everything immutable!" was partly - maybe even mostly - a workaround for the fact that it's so hard to copy data in most languages.

I agree C++ makes it too easy to accidentally copy data, but at least you can copy data!


but the only reason you want to copy data is that it makes manual memory management easier. otherwise paying a reference is almost always cheaper.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: