"with" still sucks + removing features + adding features
Johan Granberg
lijat.meREM at OVEgmail.com
Tue May 19 15:12:25 PDT 2009
Andrei Alexandrescu wrote:
> I personally still think it's a bad feature because it introduces
> long-distance coupling between symbols defined in two different places,
> both distinct from the place where the statement is used! Consider:
>
> import wyda; // defines symbol write
> import geeba; // defines struct S { ... }
>
> void main()
> {
> S s;
> with (s) {
> write(5);
> }
> }
>
> Machiavelly would jump in joy at such code. What did I achieve? I saved
> a few "s.". What did I lose? The ability so say anything, but absolutely
> anything on what the code does.
I understand the problem you are pointing out even if I don't belive it's a
significant issue. The problem with your assumption that it saves a few
"s." is that where I usualy use it is in cases like this.
with(listofdecentlysizedstructs[i].vector3d){
return x*x+y*y+z*z;
}
Maybe not an ideal example, usualy I have several lines of math algorithms
or physics formula in the with scope. The gain here is both that I dont
have to type long variable names (could be solved with an alias maybe) but
more importantly it allows me to keep pysics and math formula close to the
form they have in math or pysics. For example writing x y and z for the
parts of some point I'm currently working on instead of p[i].x p[i].y and
p[i].z can in a formula with lots of them make the code easier to read. For
a single use of symbols I see no important use of the with statement.
More information about the Digitalmars-d
mailing list