DConf 2013 Day 2 Talk 3: C# to D by Adam Wilson

Juan Manuel Cabo juanmanuel.cabo at gmail.com
Fri May 31 09:59:24 PDT 2013


On 05/31/2013 09:33 AM, Andrei Alexandrescu wrote:
> http://www.reddit.com/r/programming/comments/1feem1/dconf_2013_day_2_talk_3_from_c_to_d_by_adam_wilson/
> 
> {Enj,Destr}oy!
> 
> Andrei

Just watched it over lunch and I liked this talk very much.

For transforming pieces of code I very often write Vim regex,
(supports multiline with a flag) and when that is not
enough, writing a Vim function does the trick.

About streams: there is some phobos support for streams, though
it seems not finalized.

I wish something were done about the containers. Note that it
is very easy to write C# containers in a OOP style, based
on T[] and T[K] internally (though a concurrent hash map with
read/write locking would need to be done from scratch without
using AAs).

It is not true that Array!T is equivalent to List<T>.
Array!T wants to own their items (because it manages its own
memory), so it is only practically useable with structs.
Even duplicating the array is unsafe if the element type
is a class:

import std.stdio, std.container;

class A {
    int val;
    this(int v) {
        val = v;
    }
    ~this() {
        writeln("A destroyed");
    }
}

void func(Array!A list) {
}

void main() {
    A a = new A(3);
    Array!A list;
    list ~= a;
    writeln(a.val);    //prints 3
    func(list.dup);    //prints A destroyed
    //<-- The object cannot be used anymore, though it
    //    is still present in 'list')
    writeln(a.val);    //prints 0
}

And one cannot use RefCounted!A because RefCounted doesn't
work with classes.
I guess that RedBlackTree's suffer the same problem.

--jm






More information about the Digitalmars-d-announce mailing list