<div class="gmail_quote">On 8 February 2012 01:53, Timon Gehr <span dir="ltr"><<a href="mailto:timon.gehr@gmx.ch">timon.gehr@gmx.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 02/08/2012 12:09 AM, Manu wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On 8 February 2012 00:33, Sean Kelly <<a href="mailto:sean@invisibleduck.org" target="_blank">sean@invisibleduck.org</a><br></div><div class="im">
<mailto:<a href="mailto:sean@invisibleduck.org" target="_blank">sean@invisibleduck.org</a><u></u>>> wrote:<br>
<br>
    On Feb 6, 2012, at 1:38 PM, Oliver Puerto wrote:<br>
<br>
     > Hello,<br>
     ><br>
     > I'm very new to D. Just started reading "The D programming<br>
    language". I should read it from beginning to end before posting<br>
    questions here. I know ... But I'm just too impatient. The issue<br>
    seems not to be that simple, nevertheless. The code below compiles<br>
    with Visual Studio.<br>
     ><br>
     > I want to have something like my actor class that I can start<br>
    running in it's own thread like in Scala or other languages that<br>
    support actors. So at best, I would like to do something like this:<br>
     ><br>
     >    MyActor myActor = new MyActor();<br>
     >    auto tid = spawn(&start, &myActor.run());<br>
<br>
    This should work:<br>
<br>
    void runActor(shared MyActor a) { (cast(MyActor)a)).run(); }<br>
    MyActor myActor = new MyActor();<br>
    auto tid = spawn(cast(shared MyActor) myActor, &runActor);<br>
<br>
<br></div><div class="im">
See, my conclusion is, whenever using this API, you inevitably have dog<br>
ugly code.<br>
</div></blockquote>
<br>
If it is combined with OO.</blockquote><div><br></div><div>The OO changes nothing, the casting is what I'm getting at.</div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">That code is barely readable through the casts... I can only<br>
draw this up to faulty API design.<br>
I understand the premise of 'shared'-ness that the API is trying to<br>
assert/guarantee, but the concept is basically broken in the language.<br>
</blockquote>
<br></div>
The concept is not broken at all. There are just too few type system features to conveniently support the concept.</blockquote><div><br></div><div>... I think you contradicted yourself one sentence after the other :)</div>
<div><br></div><div> </div><div>You can't use this API at all with out these blind casts, which is,</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
basically, a hack, and I am yet to see an example of using this API<br>
'properly'.<br>
</blockquote>
<br></div>
Passing value type and/or immutable messages works well.</blockquote><div><br></div><div>I guess so, but I think this would be relatively rare. Many immutable things may just be addressed directly/globally.</div><div>Maybe it's just my experience of threading, but I basically never spawn a thread where I don't intend to pass some sort of 'workload' to it... I shouldn't have to jump through hoops to achieve that basic task.</div>
<div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The casts are totally self defeating.<br>
</blockquote>
<br></div>
They indicate a potentially unsafe operation.<br></blockquote><div><br></div><div>Sure, but what's the point of 'indicating' such a thing, when the ONLY way to deal with it, is to add ugly blind casts? You are forced to ignore the warning and just cast the 'problem' away.</div>
<div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">   std.concurrency really should allow unique references to a<br>
    non-shared type to be passed as well, using something similar to<br>
    assumeUnique.<br>
<br>
<br></div><div class="im">
Something like that should exist in the language (... or shared should<br>
just not be broken).<br>
</div></blockquote>
<br>
How would you improve usability of the shared qualifier without some kind of ownership type system?</blockquote><div><br></div><div>I've thought about that... but I've got nothing. The shared concept seems basically broken to me. It's nothing more than a self-documentation keyword, with the added bonus that it breaks your code and forces casts everywhere you touch it.</div>
<div>It creates a boundary between 2 worlds of objects. Nothing shared can be used in an un-shared environment (ie. all your code), and nothing unshared can be passed to a shared environment... and there's no implicit(/safe) transfer between the 2 worlds.</div>
<div>The ONLY way to interact is explicit cast, which doesn't guarantee any safety, you just have to type it wherever the compile errors pop up. So what's the point? Without a way for the language to assert what transfers between worlds are safe or not, the whole premise is self defeating.</div>
<div><br></div><div>Passing args by value seems to be the only solution, but that doesn't work in an OO environment.</div><div><br></div><div>Do you have any ideas how to make it work?</div><div>I get the feeling, as I say, shared is a nice idea, but it's basically broken, and the language doesn't have any mechanism to really support it. As is, it's nothing more than an info-keyword that makes your code ugly :/</div>
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Using a template like assumeUnique is no better<br>
than the ugly cast. What does it offer over a cast?<br>
</blockquote>
<br></div>
Nothing. I prefer cast(immutable).<br></blockquote><div><br></div><div>I'd prefer to not have shared at all in it's current state. It adds zero value that I can see, and has clear negative side effects.</div></div>