"with" should be deprecated with extreme prejudice

bearophile bearophileHUGS at lycos.com
Mon May 18 01:33:18 PDT 2009


Andrei, I agree that "with" is dangerous when it shadows outer names (Python designers have not added a "with" because of this).

------------------

Rainer Deyke:

> Implicit access to members of 'this' should also be banned.  I always
> use explicit 'this->' in C++ and explicit 'this.' in D.  It makes the
> code much easier to read.

I too usually add "this." in my D code to increase readability. But it's quite long (as "self." in Python), so the solution used by Ruby may be better: @ before instance attributes (Ruby also uses @@ before class attributes, that are absent in D. D has static variables that are something different and more primitive).

-------------------

Derek Parnell:

> int x, y;
> with (p as "somevery.long.struct.or.class[17].name") {
>       y += p.x;
>       ++p.x;
> }

I also use alias to create a shorter name, so it may be used an extension of the alias syntax (to allow to use {} to define where such alias exists. Also notice the "as" keyword, used in renamed imports too):

int x, y;
alias somevery.long.struct.or.class[17].name as s {
      y += p.x;
      ++p.x;
}

Bye,
bearophile



More information about the Digitalmars-d mailing list