More evidence that memory safety is the future for programming languages

Sebastiaan Koppe mail at skoppe.eu
Tue Mar 31 07:26:38 UTC 2020


On Monday, 30 March 2020 at 19:25:53 UTC, Johan wrote:
> On Saturday, 28 March 2020 at 20:24:02 UTC, Walter Bright wrote:
>> https://news.ycombinator.com/item?id=22711391
>>
>> Fitting in with the push for @safe as the default, and the 
>> @live Ownership/Borrowing system for D.
>>
>> We can either get on the bus or get run over by the bus.
> Isn't it more interesting to find a comprehensive resource 
> management solution, instead of working on a solution only for 
> the special case of memory [*]. A double file close is also 
> bad, for example.
> Maybe RAII and move semantics isn't it, but at least it doesn't 
> single out one type of resource.

I have to agree with you, most of the time I don't care about 
memory, but rather whatever I am modelling within that memory. 
Yes, that 24 might look right a regular int, but to me it holds 
significance beyond the fact that it is a mere int.

For my web library spasm I am dealing with JS objects that I have 
to release at the right time. Things get hairy with delegates, 
callback and long lived references.

At first I tried reference counting, but found out there was 
significant bloat (I like to keep my web binaries small), 
eventually I settled for non-copyable objects so I get unique 
references, and release them on the JS side when the last and 
only reference goes out of scope.

Of course now I run into other issues. 'scope ref' helps a bit, 
but I find that I have to write `move` a lot. The parts where I 
am struggling a bit are where I get a handle to an JS object that 
is conceptually a sumtype, an optional or a base object and need 
to unwrap or up cast things. I have solved them, but with some 
rather gnarly @system code.

Remember, I want unique references (and borrow) to plain ints 
here. I know it might look to the compiler as a regular int it 
can simply copy (and it is), but to me it looks like a JS 
mouseevent object that needs clean up after the last reference is 
gone.



More information about the Digitalmars-d mailing list