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

as a language designer.. im still stuck wether ownership is a good or bad idea. I like ownership because that's how we handle things in the real world. Eg. 2 people grabbing potato chips out of a bag at the same time is a bad idea. We pass the bag along. wait turns. But for some reason, we dont do this with computer programs. So.. should we do this with computers or not? Feel free to reply.

My instinct says 'yes'. But i also have a feeling that im going to run into problems that current languages dont have. Such as being forced to copy data or have complex systems like in rust to make the compiler happy.



> But for some reason, we dont do this with computer programs

I'm unsure what you mean here. It's pretty foundational to the structuring of programs hierarchically (eg, trees own their children, functions own their variables, closures own their environments, and so on).

The classic argument against ownership as a language semantic is that it doesn't play well with graphs and circularly linked lists, where there isn't a meaningful hierarchy and therefore no one ancestor is the "owner" of any descendant. The counterargument is that these datastructures are both rare and better represented with a single owner of the data and the relationships represented through indirection even if your implementation language doesn't enforce ownership (for example, adjacency lists/matrices for graphs, vectors for lists, etc).


I just meant that 99% of software was written without the idea of ownership. Sure, we had objects containing other objects, but i dont see that as "ownership".

Interesting arguments. Thanks.


The term might be a bit new now that we have some work that seeks to establish a formalism for it, but the concepts are very old.

A modern definition could be that ownership semantics define how aliases to data are created and shared. This includes things like variable binding and class members, but also encapsulates pointers and references - which have formal semantics in every language that uses them (and therefore, bake in ownership, even if it is implicit).

In systems programming languages like C and C++ the word "owner" and "ownership" are often used to describe which data structures and calling contexts are responsible for managing data lifetimes, since aliases to that data are used to control memory allocation and deallocation. The semantics are not baked into the language, but most software in these ecosystems has to be written with ownership in mind to be sound - and indeed, has been for many years, with that verbiage ("lifetime", "owner", etc).


I think ownership is necessary to understand as a programmer when designing systems, regardless of whether or not the language has explicit enforcement of it. Having a clear idea of ownership and accommodating it in your data structures is the best way to know when to free an object in C.

Similarly, having a clear idea of ownership can help in writing GC friendly code.


True. But doing this yourself can result in bugs. It would be nice if we didnt have to think about it.


I think some variant of it is a must in low-level languages like Rust, even if as vague as “this given arena owns this and will free these objects”.

For a higher level hobby language I’m designing, I’m thinking of doing a similar concept, but with runtime overhead - basically every object would be “synchronized” in Java’s parlance, but to make it efficient most lockings would be elided at compile time via move semantics. So data races couldn’t happen (also, could possibly do a better job at escape analysis).

The primary reason I’m thinking about that is that we really shouldn’t be using non-thread safe primitives anymore — Clojure did get this right. That should be left as a compiler optimization if it can prove that that given code runs inside a “alone”.


> I like ownership because that's how we handle things in the real world.

Not if you live in a communist society.

I think it would be better if there was no ownership, because everybody would be happy.


That's distributed ownership. Basically you get ownership of certain objects for no reason. And if you question the Goverment Class about this behaviour, you get freed from memory. Not a good strategy in my opinion.


Communism does not mean “no ownership” – Marx never said he was going for your toothbrush.

It means no private ownership of the means of production, which another can of worms.


> It means no private ownership of the means of production, which another can of worms.

Coincidentally, worms are an excellent source of protein in this communist, Marxist society. By eating worms instead of beef, it will also help to stop climate change by eliminating the greenhouse gases from cows, thus saving the planet. You will eat ze bugs!




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

Search: