Discussion on Go and D

Manu turkeyman at gmail.com
Sun Apr 8 17:35:20 PDT 2012


On 9 April 2012 03:21, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:

> On 4/9/12, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
> > and pass-by-alias
>
> Speaking of alias, one killer feature would be to enable using alias
> for expressions. E.g.:
>
> struct Window { struct Point { int x, y; } Point point; }
> void test() {
>    Window window;
>    alias window.point.x x;
>    // use 'x' here which is really window.point.x
> }
>
> It makes it simpler to manipulate nested structs and their fields by
> reference without involving pointers or using with statements. AFAIK
> C++ can use references for this purpose (ala &int x =
> window.point.x;), but I guess this isn't very efficient unless the
> compiler can optimize it.
>

I can't think of many cases where the compiler can't optimise it when used
in the context you describe.


Besides myself I've also seen other people request it (I think Nick S.
> wanted the feature).
>

I probably wouldn't have thought to use alias in that way, I probably would
have asked to be able to use 'ref' on any declaration...
I do also get a little annoyed having to use pointers in this situation. At
least they don't suffer a different dereference syntax like C, but it does
seem a bit flimsy that they can be reassigned, can also be null, and I have
to involve the & operator, which can often lead to parentheses spam.

(...why can't you use 'ref' in regular declarations? I frequently find
myself wanting to use ref locally for this exact reason.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120409/6959f104/attachment.html>


More information about the Digitalmars-d mailing list