4 ms·
> 3. Values follow a strict rule: primitives pass by value, containers pass by read-only reference. This prevents accidental aliasing/mutation across scopes and
by amluto 8mo ago
> 3. Values follow a strict rule: primitives pass by value, containers pass by read-only reference. This prevents accidental aliasing/mutation across scopes and keeps ownership implicit but predictable.
There are plenty of languages where functions cannot mutate their parameters or anything their parameters reference — Haskell is one example. But these languages tend to have the ability to (reasonably) efficiently make copies of most of a data structure so that you can, for example, take a list as a parameter and return that list with one element changed. These are called persistent data structures.
Are you planning to add this as a first-class feature? This might be complex to implement efficiently on top of C++’s object model — there’s usually a very specialized GC involved.
- eager_learner 8mo agoComments like amluto's above, are the reason my time spent on HN is not wasted.
- paulddraper 8mo agoI don’t see the relevance of special GC. But yes you need immutable data structures designed for amortized efficient copy.
- cyber_kinetist 8mo agoI've seen some C++ libraries that implement persistent data structures like immer (https://github.com/arximboldi/immer https://github.com/arximboldi/immer) - but seems it requires the use of the Boehm GC (which is notorious to be slow, since it is a conservative GC and cannot exploit any of the specific semantics/runtime characteristics of the language you're making).
- hedayet 8mo ago[author here] ROX avoids implicit structural sharing and persistent data structures. Allocation and mutation are explicit - if I want a modified container, I construct one. This is intentionally more resource-intensive. ROX trades some efficiency for simplicity and predictability. The goal is clarity of logic and clarity of behavior, even at slightly higher cost. And future optimizations should preserve that model rather than hide it.
- amluto 8mo agoI would check your “slightly”. If I have an algorithm that operates on an n-element data structure through a helper function (this includes almost any nontrivial program - think managing caches, small databases or tables, lists of clients, etc), you get an extra multiplicative factor of n for each operation. All those nice linear-time or n-log-n algorithms turn into n^2, and accidentally quadratic programs can be bad news. And if the language offers no facility at all to get the factor of n back, users may be forced to use something else.
- pjmlp 8mo agoBrainstorming a bit, you could get into that via hazardous or deferred pointers, but yeah I guess it falls down into specialized GC kind of solution.