<div class="gmail_quote">On 8 February 2012 00:33, Sean Kelly <span dir="ltr"><<a href="mailto:sean@invisibleduck.org">sean@invisibleduck.org</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 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 language". I should read it from beginning to end before posting questions here. I know ... But I'm just too impatient. The issue seems not to be that simple, nevertheless. The code below compiles with Visual Studio.<br>

><br>
> I want to have something like my actor class that I can start running in it's own thread like in Scala or other languages that 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>
</div>This should work:<br>
<br>
void runActor(shared MyActor a) { (cast(MyActor)a)).run(); }<br>
<div class="im">MyActor myActor = new MyActor();<br>
</div>auto tid = spawn(cast(shared MyActor) myActor, &runActor);<br></blockquote><div><br></div><div>See, my conclusion is, whenever using this API, you inevitably have dog ugly code. That code is barely readable through the casts... I can only draw this up to faulty API design.</div>
<div>I understand the premise of 'shared'-ness that the API is trying to assert/guarantee, but the concept is basically broken in the language. You can't use this API at all with out these blind casts, which is, basically, a hack, and I am yet to see an example of using this API 'properly'. The casts are totally self defeating.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">std.concurrency really should allow unique references to a non-shared type to be passed as well, using something similar to assumeUnique.</blockquote>
</div><div><br></div><div>Something like that should exist in the language (... or shared should just not be broken). Using a template like assumeUnique is no better than the ugly cast. What does it offer over a cast?</div>