digitalmars.D - Gripe about 'with'
- Scott Egan (26/26) May 01 2004 Since Walter converted his game I thought I should do mine - good reason...
- Scott Egan (7/33) May 01 2004 Of cause this stuffs up the module scope operator, so maybe it should be
- J Anderson (12/39) May 01 2004 Personally I don't see much problem with not including the dot because
- J Anderson (5/14) May 01 2004 Of course the dot could be made optional (use it to avoid collision) but...
- Scott Egan (8/61) May 01 2004 I'm not too concerned about typing so much as readability and accuracy. ...
- James McComb (38/51) May 01 2004 It annoys me to have to rename arguments to get this to work,
- Unknown W. Brackets (8/19) May 01 2004 And JavaScript has always worked without the .'s. If you just base
- James McComb (20/32) May 01 2004 Fair enough. I didn't know about JavaScript with blocks.
- J Anderson (4/7) May 01 2004 Good point but that still doesn't show why it can't be optional.
- J C Calvarese (10/60) May 01 2004 I think it's kind of late in the game to be changing D with respect to
- Scott Egan (6/7) May 01 2004 James, I agree with your arguments completely.
- Andy Friesen (10/12) May 01 2004 .x already has meaning in D: is an explicit reference to the global scop...
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
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 reasontoplay 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 Iwasrefering 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 canreferto '.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
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
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
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:toSince Walter converted his game I thought I should do mine - good reasonwasplay 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 Ireferrefering 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 canto '.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
Scott Egan wrote:J Anderson wrote: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).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
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 consistencyJust 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.xOr is bad.... makes things confusing I say. If it means just one thing, it is more logical. Not less. -[Unknown]
May 01 2004
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.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 McCombIf 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.xOr is bad.... makes things confusing I say. If it means just one thing, it is more logical. Not less.
May 01 2004
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
James McComb wrote:Unknown W. Brackets wrote: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.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.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 scopeIf 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.xOr is bad.... makes things confusing I say. If it means just one thing, it is more logical. Not less.James McComb-- Justin http://jcc_7.tripod.com/d/
May 01 2004
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
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