khurshid:

D language have like Pascal/Delphi "with statement", which very useful for writing readable code.

It's a quite useful statement, especially with enumerations or associative array literals, to avoid repeating many times their name:

switch (en) with (MyEnum) {
  case foo: ...
  case bar: ...
}

int[MyEnum] myAA;
with (MyEnum) {
  myAA = [foo: ...,
          bar: ...,
         ];
}

Instead of:

switch (en) {
  case MyEnum.foo: ...
  case MyEnum.bar: ...
}

int[MyEnum] myAA = [
  MyEnum.foo: ...,
  MyEnum.bar: ...,
];

And D with is better than Pascal one, because it removes its main pitfall.


Maybe I'm wrong, but, I never saw where using this statement in phobos source codes, what problem using this statement?

I think it's not used much in Phobos because it's a statement not present in C/C++, and D/Phobos devs are more used to C/C++ languages than to Pascal/Ada ones.

Bye,
bearophile

Reply via email to