February 27, 2014
On Thursday, 27 February 2014 at 14:56:22 UTC, Namespace wrote:
> On Thursday, 27 February 2014 at 14:52:00 UTC, Szymon Gatner wrote:
>> On Thursday, 27 February 2014 at 14:42:43 UTC, Dicebot wrote:
>>> There is also one complex and feature-reach implementation of uniqueness concept by Sonke Ludwig : https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/concurrency.d#L281 (Isolated!T)
>>>
>>> Priceless for message passing concurrency.
>>
>> Tbh it only looks worse and worse to me :(
>>
>> Another example of code necessary to overcome language limitations.
>
> Do you know Rust? http://www.rust-lang.org/

I do. Do you want me to go away? ;)

February 27, 2014
On Thursday, 27 February 2014 at 15:09:39 UTC, Szymon Gatner wrote:
> On Thursday, 27 February 2014 at 14:56:22 UTC, Namespace wrote:
>> On Thursday, 27 February 2014 at 14:52:00 UTC, Szymon Gatner wrote:
>>> On Thursday, 27 February 2014 at 14:42:43 UTC, Dicebot wrote:
>>>> There is also one complex and feature-reach implementation of uniqueness concept by Sonke Ludwig : https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/concurrency.d#L281 (Isolated!T)
>>>>
>>>> Priceless for message passing concurrency.
>>>
>>> Tbh it only looks worse and worse to me :(
>>>
>>> Another example of code necessary to overcome language limitations.
>>
>> Do you know Rust? http://www.rust-lang.org/
>
> I do. Do you want me to go away? ;)

No ;) But maybe Rust has your needed features. ;)
If you want to stay at D, you can use the shared and unique pointer of Dgame.Internal if you want.
February 27, 2014
On Thursday, 27 February 2014 at 14:58:50 UTC, bearophile wrote:
> Szymon Gatner:
>
>> Tbh it only looks worse and worse to me :(
>
> Perhaps for your use case it's better for you to stick with C++11? While I have written a good amount of D code (perhaps 200_000 lines or more), I still use Python a lot, etc.
>

For now I don'r really see alternative. Isn't resource a management a crucial part of everyday programming? Or is it really just me?

I do use Python for simple tools and work mainly in C++11(ish as it is really just Microsoft's dialect).

Thing is, I really want to use D. I want "Modern convenience", "Modeling power" and "Native efficiency". I want to feel like home wrt to syntax and at the same time I want for some problems to just go away. I think I am just not getting something being so deeply rooted in C++.

February 27, 2014
On Thursday, 27 February 2014 at 15:09:39 UTC, Szymon Gatner wrote:
> On Thursday, 27 February 2014 at 14:56:22 UTC, Namespace wrote:
>> On Thursday, 27 February 2014 at 14:52:00 UTC, Szymon Gatner wrote:
>>> On Thursday, 27 February 2014 at 14:42:43 UTC, Dicebot wrote:
>>>> There is also one complex and feature-reach implementation of uniqueness concept by Sonke Ludwig : https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/concurrency.d#L281 (Isolated!T)
>>>>
>>>> Priceless for message passing concurrency.
>>>
>>> Tbh it only looks worse and worse to me :(
>>>
>>> Another example of code necessary to overcome language limitations.
>>
>> Do you know Rust? http://www.rust-lang.org/
>
> I do. Do you want me to go away? ;)

I have looked at Rust and Go but I still prefer D2 :)
D2  CTFE, templates and mixin are great.
Another advantage of D is the 'easy' porting from C and C++.

But this problems with structs and classes...
I am also missing Rvalue references (move semantics) from C++11.


February 27, 2014
On Thursday, 27 February 2014 at 15:15:06 UTC, Szymon Gatner wrote:
> On Thursday, 27 February 2014 at 14:58:50 UTC, bearophile wrote:
>> Szymon Gatner:
>>
>>> Tbh it only looks worse and worse to me :(
>>
>> Perhaps for your use case it's better for you to stick with C++11? While I have written a good amount of D code (perhaps 200_000 lines or more), I still use Python a lot, etc.
>>
>
> For now I don'r really see alternative. Isn't resource a management a crucial part of everyday programming? Or is it really just me?

Resource management is important part, but part but not every language handles it the same way.
Apparently some peoples prefers that the language do almost all of this by it self no mater how bad/slow it is.

> I do use Python for simple tools and work mainly in C++11(ish as it is really just Microsoft's dialect).

What do you mean by Microsoft's dialect?
February 27, 2014
On Thursday, 27 February 2014 at 15:36:02 UTC, Remo wrote:
>
> What do you mean by Microsoft's dialect?

I mean half-implemented buggy version of C++11 in VC2012 ;)

February 27, 2014
On Thursday, 27 February 2014 at 15:39:48 UTC, Szymon Gatner wrote:
> On Thursday, 27 February 2014 at 15:36:02 UTC, Remo wrote:
>>
>> What do you mean by Microsoft's dialect?
>
> I mean half-implemented buggy version of C++11 in VC2012 ;)

Or in VC2013, but if you can use Intel compiler then it is better.
February 27, 2014
On Thursday, 27 February 2014 at 14:37:14 UTC, Szymon Gatner wrote:
> They actually don't have all the necessary features in D afaiu. They do have value semantics but can't represent uniqueness because of missing move d-tor.

struct MovingStruct {
    @disable this(this);
    typeof(this) release() {
        auto p = this.payload;
        this.payload = null;
        return typeof(this)(p);
    }
}


That does moving via an explicit release call which is statically forced upon you by the disabled copy.

MovingStruct s = some_payload;
// MovingStruct s2 = s; // compile error
MovingStruct s2 = s.release;
assert(s.payload is null); // passes
assert(s2.payload is some_payload); // we good


You can also easily do structs with reference semantics:

struct RefStruct {
    private struct Impl {
      // implementation here
    }
    Impl* payload;
    alias payload this;
}

RefStruct is now just a thin wrapper over a pointer and thus inherits the pointer's semantics.

You can add a destructor to RefStruct to free it deterministically with RAII as well. To avoid double free, you can use the move technique or refcounting:


struct RefCountingStruct {
    private struct Impl {
      // implementation here

      int refcount;
    }
    Impl* payload;
    alias payload this;

    @disable this(); // disable default constructor to force factory
    static RefCountingStruct create() {
         RefCountingStruct t = void;
         t.payload = new Impl();
         t.payload.refcount = 1;
         return t;
    }
    this(this) { if(payload !is null) payload.refcount++; }
    ~this() {
          if(payload !is null) {
              payload.refcount--;
              if(payload.refcount == 0)
                   whatever_free(payload);
          }
    }
}



i wish my book was out but it is still only half done... but i wrote a chapter with like eight different struct tricks like this. structs rock.
February 27, 2014
On Thursday, 27 February 2014 at 16:10:34 UTC, Adam D. Ruppe wrote:
> On Thursday, 27 February 2014 at 14:37:14 UTC, Szymon Gatner wrote:
>> They actually don't have all the necessary features in D afaiu. They do have value semantics but can't represent uniqueness because of missing move d-tor.
>
> struct MovingStruct {
>     @disable this(this);
>     typeof(this) release() {
>         auto p = this.payload;
>         this.payload = null;
>         return typeof(this)(p);
>     }
> }
>
>
> That does moving via an explicit release call which is statically forced upon you by the disabled copy.
>
> MovingStruct s = some_payload;
> // MovingStruct s2 = s; // compile error
> MovingStruct s2 = s.release;
> assert(s.payload is null); // passes
> assert(s2.payload is some_payload); // we good
>
>
> You can also easily do structs with reference semantics:
>
> struct RefStruct {
>     private struct Impl {
>       // implementation here
>     }
>     Impl* payload;
>     alias payload this;
> }
>
> RefStruct is now just a thin wrapper over a pointer and thus inherits the pointer's semantics.
>
> You can add a destructor to RefStruct to free it deterministically with RAII as well. To avoid double free, you can use the move technique or refcounting:
>
>
> struct RefCountingStruct {
>     private struct Impl {
>       // implementation here
>
>       int refcount;
>     }
>     Impl* payload;
>     alias payload this;
>
>     @disable this(); // disable default constructor to force factory
>     static RefCountingStruct create() {
>          RefCountingStruct t = void;
>          t.payload = new Impl();
>          t.payload.refcount = 1;
>          return t;
>     }
>     this(this) { if(payload !is null) payload.refcount++; }
>     ~this() {
>           if(payload !is null) {
>               payload.refcount--;
>               if(payload.refcount == 0)
>                    whatever_free(payload);
>           }
>     }
> }
>
>
>
> i wish my book was out but it is still only half done... but i wrote a chapter with like eight different struct tricks like this. structs rock.

Wow, that is pretty great stuff. Bit verbose, but gets the job done. Is there a way to factor it out for reuse? As a mixin probably? Thanks! Will surely try this. And I want your book.
February 27, 2014
On Thursday, 27 February 2014 at 15:56:26 UTC, Remo wrote:
> On Thursday, 27 February 2014 at 15:39:48 UTC, Szymon Gatner wrote:
>> On Thursday, 27 February 2014 at 15:36:02 UTC, Remo wrote:
>>>
>>> What do you mean by Microsoft's dialect?
>>
>> I mean half-implemented buggy version of C++11 in VC2012 ;)
>
> Or in VC2013, but if you can use Intel compiler then it is better.

VC2013 at least has variadics... I will not spend another 400 bucks just for that tho, and only a year after previous release. But that is OT ;)