2 Tags: en, d, opdispatch, dynamic, patch
4 From time to time, people suggested features to make easier to add some dynamic
5 capabilities to D__. `One of the suggestions`__ was adding a way to have
6 dynamic members. This is specially useful for things like ORM__\ s or RPC__\ s,
7 so you can do something like::
12 __ http://www.digitalmars.com/d/
13 __ http://www.digitalmars.com/d/archives/digitalmars/D/Fully_dynamic_d_by_opDotExp_overloading_88145.html
14 __ http://en.wikipedia.org/wiki/Object-relational_mapping
15 __ http://en.wikipedia.org/wiki/Remote_procedure_call
17 And it get automatically translated to some sort of SQL__ query or RPC call,
18 using some kind of introspection at **runtime**. To enable this, you can
19 translate the former to something like::
21 obj.dispatch!("foo")(5);
23 __ http://en.wikipedia.org/wiki/Sql
25 There was even a patch__ for this feature, but Walter__ didn't payed much
26 attention and ignore this feature `until a couple of days ago`__, when he got
27 bored and `implement it himself`__, on its own way =P
29 __ http://d.puremagic.com/issues/show_bug.cgi?id=2868
30 __ http://www.walterbright.com/
31 __ http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=102375
32 __ http://www.dsource.org/projects/dmd/changeset/268
34 I think this is a very bad policy, because it discourages people to contribute
35 code. There is no much difference between suggesting a feature and implementing
36 it providing a patch, unless you have a very good personal relationship with
37 Walter. You almost never will have feedback on your patch, Walter prefers to
38 implement things himself instead of giving you feedback. This way it's very
39 hard for people wanting to contribute to learn about the code and on how Walter
40 wants patches to be done; and this is what discourages contributions.
42 I won't write again about what are the problems in the D development model,
43 I already `done that`__ without much success (except for Andrei__, who is
44 writing better commit messages now, thanks for that! =). I just wanted to point
45 out another thing that Walter don't get about open-source projects.
47 __ https://llucax.com.ar/blog/blog/post/6cac01e1
50 Anyway, this post is about ``opDispatch()``, the new way of doing dynamic
51 dispatching. Walter proposed ``opDynamic()``, which was wrong, because it's not
52 really dynamic, it's completely static, but it enables dynamic dispatching with
53 a little extra work. Fortunately Michel Fortin suggested ``opDispatch()`` which
56 The thing is simple, if a method ``m()`` is not found, a call to
57 ``opDispatch!("m")()`` is tried. Since this is a template call, its
58 a compile-time feature, but you can easily do a dynamic lookup like this::
60 void opDispatch(string name)(int x)
62 this.dispatch(name, x);
65 void dispatch(string name, int x)
70 I personally like this feature, we'll see how all this turns out.
72 .. vim: set et sw=4 sts=4 :