www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Gripe about 'with'

reply "Scott Egan" <scotte tpg.com.aux> writes:
Since Walter converted his game I thought I should do mine - good reason to
play with D.

I've just tried to use the 'with' statement, and now I'm disappointed.

Firstly I tried made the mistake of putting '.' infront of the members I was
refering to (aka VB) - fail.

OK so I learnt that its just a way of changing the search scope in the
symbol table.

But then I discover that it only works for Objects not structs (or
interfaces I assume).

Walter,  please change the syntax to include the '.'; that way one can refer
to '.x' and 'x' as two different things.

And please, please make it work with anything that uses the '.' operator.

A trite example:

struc A {
    int x;
    int y;
    func1() { return x + y; }
}

int f2(int x, int y)
    A a;

    with(a) {
        .x = x;
        .y = y;
        return .func1();
    }
}
May 01 2004
next sibling parent "Scott Egan" <scotte tpg.com.aux> writes:
Of cause this stuffs up the module scope operator, so maybe it should be
'::'.



"Scott Egan" <scotte tpg.com.aux> wrote in message
news:c706ro$5s9$1 digitaldaemon.com...
 Since Walter converted his game I thought I should do mine - good reason
to
 play with D.

 I've just tried to use the 'with' statement, and now I'm disappointed.

 Firstly I tried made the mistake of putting '.' infront of the members I
was
 refering to (aka VB) - fail.

 OK so I learnt that its just a way of changing the search scope in the
 symbol table.

 But then I discover that it only works for Objects not structs (or
 interfaces I assume).

 Walter,  please change the syntax to include the '.'; that way one can
refer
 to '.x' and 'x' as two different things.

 And please, please make it work with anything that uses the '.' operator.

 A trite example:

 struc A {
     int x;
     int y;
     func1() { return x + y; }
 }

 int f2(int x, int y)
     A a;

     with(a) {
         .x = x;
         .y = y;
         return .func1();
     }
 }
May 01 2004
prev sibling next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Scott Egan wrote:

Since Walter converted his game I thought I should do mine - good reason to
play with D.

I've just tried to use the 'with' statement, and now I'm disappointed.

Firstly I tried made the mistake of putting '.' infront of the members I was
refering to (aka VB) - fail.

OK so I learnt that its just a way of changing the search scope in the
symbol table.

But then I discover that it only works for Objects not structs (or
interfaces I assume).

Walter,  please change the syntax to include the '.'; that way one can refer
to '.x' and 'x' as two different things.

And please, please make it work with anything that uses the '.' operator.

A trite example:

struc A {
    int x;
    int y;
    func1() { return x + y; }
}

int f2(int x, int y)
    A a;

    with(a) {
        .x = x;
        .y = y;
        return .func1();
    }
}



  
Personally I don't see much problem with not including the dot because if you have a collision like in the case your present, its a local collision, so it's easily fixable. Just use px, py -> and there is not much more typing involved in doing that (if typing is an issue here). As to the structs. Big W as said that this was an oversight, I think he'll eventually get around to fixing it. Its on the http://www.prowiki.org/wiki4d/wiki.cgi?PendingPeeves, page. I do a lot of code with structs and keep coming to situations where I wish I could use "with". -- -Anderson: http://badmama.com.au/~anderson/
May 01 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
J Anderson wrote:

 Personally I don't see much problem with not including the dot because 
 if you have a collision like in the case your present, its a local 
 collision, so it's easily fixable.  Just use px, py -> and there is 
 not much more typing involved in doing that (if typing is an issue here).
Of course the dot could be made optional (use it to avoid collision) but that may be to complicated.
 As to the structs.  Big W as said that this was an oversight, I think 
 he'll eventually get around to fixing it.  Its on the 
 http://www.prowiki.org/wiki4d/wiki.cgi?PendingPeeves, page.

 I do a lot of code with structs and keep coming to situations where I 
 wish I could use "with".
-- -Anderson: http://badmama.com.au/~anderson/
May 01 2004
prev sibling next sibling parent "Scott Egan" <scotte tpg.com.aux> writes:
I'm not too concerned about typing so much as readability and accuracy.  It
is not obvious in a with block where the variables are comming from.  I
found this a bit off putting.




"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:c70eli$gv7$1 digitaldaemon.com...
 Scott Egan wrote:

Since Walter converted his game I thought I should do mine - good reason
to
play with D.

I've just tried to use the 'with' statement, and now I'm disappointed.

Firstly I tried made the mistake of putting '.' infront of the members I
was
refering to (aka VB) - fail.

OK so I learnt that its just a way of changing the search scope in the
symbol table.

But then I discover that it only works for Objects not structs (or
interfaces I assume).

Walter,  please change the syntax to include the '.'; that way one can
refer
to '.x' and 'x' as two different things.

And please, please make it work with anything that uses the '.' operator.

A trite example:

struc A {
    int x;
    int y;
    func1() { return x + y; }
}

int f2(int x, int y)
    A a;

    with(a) {
        .x = x;
        .y = y;
        return .func1();
    }
}
Personally I don't see much problem with not including the dot because if you have a collision like in the case your present, its a local collision, so it's easily fixable. Just use px, py -> and there is not much more typing involved in doing that (if typing is an issue here). As to the structs. Big W as said that this was an oversight, I think he'll eventually get around to fixing it. Its on the http://www.prowiki.org/wiki4d/wiki.cgi?PendingPeeves, page. I do a lot of code with structs and keep coming to situations where I wish I could use "with". -- -Anderson: http://badmama.com.au/~anderson/
May 01 2004
prev sibling parent reply James McComb <alan jamesmccomb.id.au> writes:
Scott Egan wrote:

 int f2(int x, int y)
    A a;

    with(a) {
        .x = x;
        .y = y;
        return .func1();
    }
 }
J Anderson wrote:
 Personally I don't see much problem with not including the dot because 
 if you have a collision like in the case your present, its a local 
 collision, so it's easily fixable.  Just use px, py -> and there is not 
 much more typing involved in doing that (if typing is an issue here).
It annoys me to have to rename arguments to get this to work, but it's not because I'm concerned about having more to type. It's just that I'd like to be able to use the same variable names across the board, and not have to rename variables or give up the convenience (and readability) of with blocks. For what it's worth, I'd like to echo Scott's preference for the dots being used in the with block, for the following reasons. 1. Consistency with other languages Delphi did with blocks this way, and so did Visual Basic and other languages influenced by Delphi. 2. Logical consistency I believe that: int f(int x, int y) { with(a) { .x = x; .y = y; } } ...should be exactly equivalent to: int f(int x, int y) { a.x = x; a.y = y; } Note that no variable renaming is required. If this conflicts with the syntax for indicating global scope, I think it is the global scope syntax that should be changed: e.g. .x becomes ::x or global.x Then I could write: int f(int x) { with(a) { .x = ::x; // uses global x .x = x; // uses local x } } James McComb
May 01 2004
parent reply "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
James McComb wrote:
 1. Consistency with other languages
 
 Delphi did with blocks this way, and so did Visual Basic and
 other languages influenced by Delphi.
And JavaScript has always worked without the .'s. If you just base things off other languages, you have to pick which - and I would note that Delphi and Visual Basic are not as "C like" as JavaScript is.
 
 2. Logical consistency
Just your logic, though... maybe not everyone shares that logic.
 If this conflicts with the syntax for indicating
 global scope, I think it is the global scope syntax
 that should be changed:
 e.g. .x becomes ::x or global.x
 
Or is bad.... makes things confusing I say. If it means just one thing, it is more logical. Not less. -[Unknown]
May 01 2004
parent reply James McComb <alan jamesmccomb.id.au> writes:
Unknown W. Brackets wrote:

 And JavaScript has always worked without the .'s.  If you just base 
 things off other languages, you have to pick which - and I would note 
 that Delphi and Visual Basic are not as "C like" as JavaScript is.
Fair enough. I didn't know about JavaScript with blocks. Forget about other languages, then.
 Just your logic, though... maybe not everyone shares that logic.
Maybe they don't, but maybe they should. ;) Here are two other reasons why with block should have the dots. 1. Readability In the middle of a long function you come across: with(a) { x = y; } Without the dots, you can't tell at a glance whether this means a.x = y or x = a.y or even just x = y! 2. Auto-complete editor support Inside a with block, you type a dot. Lo and behold, up pops a list of methods for the containing with block.
 If this conflicts with the syntax for indicating
 global scope, I think it is the global scope syntax
 that should be changed:
 e.g. .x becomes ::x or global.x
Or is bad.... makes things confusing I say. If it means just one thing, it is more logical. Not less.
I am not suggesting that any construct have two meanings. I am suggesting something like: .x always means the scope of the with block ::x always means global scope James McComb
May 01 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
James McComb wrote:

 2. Auto-complete editor support

 Inside a with block, you type a dot. Lo and behold, up
 pops a list of methods for the containing with block.
Good point but that still doesn't show why it can't be optional. -- -Anderson: http://badmama.com.au/~anderson/
May 01 2004
prev sibling next sibling parent J C Calvarese <jcc7 cox.net> writes:
James McComb wrote:
 Unknown W. Brackets wrote:
 
 And JavaScript has always worked without the .'s.  If you just base 
 things off other languages, you have to pick which - and I would note 
 that Delphi and Visual Basic are not as "C like" as JavaScript is.
Fair enough. I didn't know about JavaScript with blocks. Forget about other languages, then.
 Just your logic, though... maybe not everyone shares that logic.
Maybe they don't, but maybe they should. ;) Here are two other reasons why with block should have the dots. 1. Readability In the middle of a long function you come across: with(a) { x = y; } Without the dots, you can't tell at a glance whether this means a.x = y or x = a.y or even just x = y! 2. Auto-complete editor support Inside a with block, you type a dot. Lo and behold, up pops a list of methods for the containing with block.
 If this conflicts with the syntax for indicating
 global scope, I think it is the global scope syntax
 that should be changed:
 e.g. .x becomes ::x or global.x
Or is bad.... makes things confusing I say. If it means just one thing, it is more logical. Not less.
I am not suggesting that any construct have two meanings. I am suggesting something like: .x always means the scope of the with block ::x always means global scope
I think it's kind of late in the game to be changing D with respect to these scope issues. Personally, I'm used to the with . convention that Visual Basic uses, but I like D's way, too. D's scope rules are already well-defined and they work. But keep these suggestions coming, D still has some weak spots and different perspectives can shed light on them.
 
 James McComb
-- Justin http://jcc_7.tripod.com/d/
May 01 2004
prev sibling parent "Scott Egan" <scotte tpg.com.aux> writes:
James, I agree with your arguments completely.

(I too didn't know about JavaScrip's behaviour; is there something missing
in my life....nope!)



"James McComb" <alan jamesmccomb.id.au> wrote in message
news:c71ift$27j5$1 digitaldaemon.com...
 Unknown W. Brackets wrote:
[snip - too much repartition]
May 01 2004
prev sibling parent Andy Friesen <andy ikagames.com> writes:
Scott Egan wrote:
 Walter,  please change the syntax to include the '.'; that way one can refer
 to '.x' and 'x' as two different things.
.x already has meaning in D: is an explicit reference to the global scope. int x; class A { int x; this() { x = .x; } } -- andy
May 01 2004