Remix.run Logo
chhs 9 hours ago

For those curious what ownership and borrowing looks like in D: https://dlang.org/blog/2019/07/15/ownership-and-borrowing-in...

fooker 8 hours ago | parent | next [-]

This is a somewhat simplistic view of ownership and borrowing for modern programming languages.

Pointers are not the only 'pointer's to resources. You can have handles specific to your codebase or system, you can have indices to objects in some flat array that the rest of your codebase uses, even temporary file names.

An object oriented (or 'multi paradigm') language has to account for these and not just literal pointers.

This is handled reasonably well both in Rust and C++. (In the spirit of avoiding yet another C++ vs Rust flamewar here, yes the semantics are different, no it doesn not make sense for C++ to adopt Rust semantics)

tgv 5 hours ago | parent [-]

How does Rust (or C++) treat array indices as resources? And won't that defy the reason to use indices over pointers?

randfur 9 hours ago | parent | prev | next [-]

I don't know D so I'm probably missing some basic syntax. If pointers cannot be copied how do you have multiple objects referencing the same shared object?

andsoitis 8 hours ago | parent [-]

> If pointers cannot be copied

They can.

uecker 9 hours ago | parent | prev [-]

Is there any experience on how this works in practice?