digitalmars.D - With block proposal
- James McComb (24/24) May 06 2004 I've said it before, I think that D-style with blocks lack the
- J Anderson (4/28) May 06 2004 If it where optional, it would be more then fine with me.
- James McComb (7/9) May 06 2004 I wrote a colon character, but because it happens to be
- Matthew (3/11) May 06 2004 That's a shame, as with the smileys I think you have a winning proposal....
- Ben Hinkle (12/17) May 06 2004 "with" is designed to make the code more readable by removing clutter an...
- James McComb (14/26) May 06 2004 Renaming variables is one technique. I have no problem with this
- vathixSpamFix dprogramming.com (Vathix) (9/33) May 06 2004 I think you need a different symbol, : doesn't go well with ?:
- Joel Lucsy (9/14) May 06 2004 How about being able to specify the symbol yourself:
- Ant (11/23) May 06 2004 that is the worst idea ever.
- Matthew (2/10) May 06 2004 I agree with that. I've never used with() for that reason, and don't eve...
- Freeman (1/34) Aug 27 2009
- Michiel Helvensteijn (10/17) Aug 27 2009 I think the plan is to get rid of 'with', and I can't say I disagree.
- Daniel Keep (2/25) Aug 27 2009 Unless a is a value-type member of something else.
- Michiel Helvensteijn (5/12) Aug 27 2009 That's why I said 'or similar'. Doesn't D have anything to create an
- Bill Baxter (19/29) Aug 27 2009 Yes you can do
I've said it before, I think that D-style with blocks lack the readability (and auto-complete editor support) of other languages. Example: with(a){ x = y; } This is ambiguous and could mean a.x = y or x = a.y or a.x = a.y or even just x = y. D-style with blocks actually *reduce* the readability of the code, which makes them a bit pointless, in my opinion. PROPOSAL: Introduce a symbol (for the sake of argument, :) that acts like a dot in with blocks in other languages. Then the code is no longer ambiguous, is more readable, and a list of properties can pop up in the editor automagically when you type :. Example: with(a) { :x = x; // Unambiguously means a.x = x :x = .x; // Unambiguously means a.x = .x } This syntax does not use the dot operator, which is already taken to indicate global scope. The syntax could even be optional (at the expense of a little ambiguity.) I don't mind if a different character than : is used. And then the language will be perfect. ;)
May 06 2004
James McComb wrote:I've said it before, I think that D-style with blocks lack the readability (and auto-complete editor support) of other languages. Example: with(a){ x = y; } This is ambiguous and could mean a.x = y or x = a.y or a.x = a.y or even just x = y. D-style with blocks actually *reduce* the readability of the code, which makes them a bit pointless, in my opinion. PROPOSAL: Introduce a symbol (for the sake of argument, :) that acts like a dot in with blocks in other languages. Then the code is no longer ambiguous, is more readable, and a list of properties can pop up in the editor automagically when you type :. Example: with(a) { :x = x; // Unambiguously means a.x = x :x = .x; // Unambiguously means a.x = .x } This syntax does not use the dot operator, which is already taken to indicate global scope. The syntax could even be optional (at the expense of a little ambiguity.) I don't mind if a different character than : is used. And then the language will be perfect. ;)If it where optional, it would be more then fine with me. -- -Anderson: http://badmama.com.au/~anderson/
May 06 2004
I wrote:PROPOSAL: Introduce a symbol (for the sake of argument, :) etc...I wrote a colon character, but because it happens to be followed by a left bracket, my newsreader is displaying it as a smiley! Just to be clear, I am not suggesting that with blocks contain smileys! :) James McComb
May 06 2004
"James McComb" <alan jamesmccomb.id.au> wrote in message news:c7d7ph$1qfo$1 digitaldaemon.com...I wrote:That's a shame, as with the smileys I think you have a winning proposal. :-)PROPOSAL: Introduce a symbol (for the sake of argument, :) etc...I wrote a colon character, but because it happens to be followed by a left bracket, my newsreader is displaying it as a smiley! Just to be clear, I am not suggesting that with blocks contain smileys! :)
May 06 2004
with(a) { :x = x; // Unambiguously means a.x = x :x = .x; // Unambiguously means a.x = .x }"with" is designed to make the code more readable by removing clutter and if a nice, unobtrusive symbol can be found then I'd say go for it but I'm guessing any symbol will look like clutter. Pascal "with" blocks didn't have a symbol and I used them with no problem. Also function members can have ambiguous symbols: class foo { int a; void bar(int a) { \\ two "a"s } } and the techniques to avoid the problem there also work for "with".
May 06 2004
Ben Hinkle wrote:"with" is designed to make the code more readable by removing clutter and if a nice, unobtrusive symbol can be found then I'd say go for it but I'm guessing any symbol will look like clutter. Pascal "with" blocks didn't have a symbol and I used them with no problem. Also function members can have ambiguous symbols: class foo { int a; void bar(int a) { \\ two "a"s } } and the techniques to avoid the problem there also work for "with".Renaming variables is one technique. I have no problem with this technique. But other techniques involve using scope resolution operators. For example, one might reduce the ambiguity of your function member example by writing: this.a = a And my proposal allows for code like this: with(this) { :a = a; :b = b; /* etc. */ } James McComb
May 06 2004
In article <c7d7da$1pq8$1 digitaldaemon.com>, alan jamesmccomb.id.au says...I've said it before, I think that D-style with blocks lack the readability (and auto-complete editor support) of other languages. Example: with(a){ x = y; } This is ambiguous and could mean a.x = y or x = a.y or a.x = a.y or even just x = y. D-style with blocks actually *reduce* the readability of the code, which makes them a bit pointless, in my opinion. PROPOSAL: Introduce a symbol (for the sake of argument, :) that acts like a dot in with blocks in other languages. Then the code is no longer ambiguous, is more readable, and a list of properties can pop up in the editor automagically when you type :. Example: with(a) { :x = x; // Unambiguously means a.x = x :x = .x; // Unambiguously means a.x = .x } This syntax does not use the dot operator, which is already taken to indicate global scope. The syntax could even be optional (at the expense of a little ambiguity.) I don't mind if a different character than : is used. And then the language will be perfect. ;)I think you need a different symbol, : doesn't go well with ?: with(foo) { :o = :u ? :c : :h; } LOL. I think it's fine the way it is. -- Christopher E. Miller
May 06 2004
James McComb wrote:PROPOSAL: Introduce a symbol (for the sake of argument, :) that acts like a dot in with blocks in other languages. Then the code is no longer ambiguous, is more readable, and a list of properties can pop up in the editor automagically when you type :.How about being able to specify the symbol yourself: with (this_long_variable) use (a) { a.dothis( b ); a.x = 3; } -- Joel Lucsy
May 06 2004
In article <c7djpb$2gfk$1 digitaldaemon.com>, Joel Lucsy says...James McComb wrote:that is the worst idea ever. "with" is a mistake of D. I thought "with" was created to avoid checking the type of a variant type variable (what ever is called) multiple type for the same variable. How about just type in the correct symbol? Ant PS I'm starting to believe that the use of "break" in a foreach loop might be a good thing...PROPOSAL: Introduce a symbol (for the sake of argument, :) that acts like a dot in with blocks in other languages. Then the code is no longer ambiguous, is more readable, and a list of properties can pop up in the editor automagically when you type :.How about being able to specify the symbol yourself: with (this_long_variable) use (a) { a.dothis( b ); a.x = 3; }
May 06 2004
I've said it before, I think that D-style with blocks lack the readability (and auto-complete editor support) of other languages. Example: with(a){ x = y; } This is ambiguous and could mean a.x = y or x = a.y or a.x = a.y or even just x = y. D-style with blocks actually *reduce* the readability of the code, which makes them a bit pointless, in my opinion.I agree with that. I've never used with() for that reason, and don't ever intend to in its current guise.
May 06 2004
James McComb Wrote:I've said it before, I think that D-style with blocks lack the readability (and auto-complete editor support) of other languages. Example: with(a){ x = y; } This is ambiguous and could mean a.x = y or x = a.y or a.x = a.y or even just x = y. D-style with blocks actually *reduce* the readability of the code, which makes them a bit pointless, in my opinion. PROPOSAL: Introduce a symbol (for the sake of argument, :) that acts like a dot in with blocks in other languages. Then the code is no longer ambiguous, is more readable, and a list of properties can pop up in the editor automagically when you type :. Example: with(a) { :x = x; // Unambiguously means a.x = x :x = .x; // Unambiguously means a.x = .x } This syntax does not use the dot operator, which is already taken to indicate global scope. The syntax could even be optional (at the expense of a little ambiguity.) I don't mind if a different character than : is used. And then the language will be perfect. ;)
Aug 27 2009
Freeman wrote:I think the plan is to get rid of 'with', and I can't say I disagree. If you can say with(a) { :x = f(); :x = g(); } you can also say { auto w = a; w.x = f(); w.x = g(); } or similar. Hardly any longer, and without the need for a whole language construct. -- Michiel HelvensteijnExample: with(a) { :x = x; // Unambiguously means a.x = x :x = .x; // Unambiguously means a.x = .x }
Aug 27 2009
Michiel Helvensteijn wrote:Freeman wrote:Unless a is a value-type member of something else.I think the plan is to get rid of 'with', and I can't say I disagree. If you can say with(a) { :x = f(); :x = g(); } you can also say { auto w = a; w.x = f(); w.x = g(); } or similar. Hardly any longer, and without the need for a whole language construct.Example: with(a) { :x = x; // Unambiguously means a.x = x :x = .x; // Unambiguously means a.x = .x }
Aug 27 2009
Daniel Keep wrote:That's why I said 'or similar'. Doesn't D have anything to create an alias/reference to a value-type variable? -- Michiel Helvensteijnyou can also say { auto w = a; w.x = f(); w.x = g(); } or similar.Unless a is a value-type member of something else.
Aug 27 2009
On Thu, Aug 27, 2009 at 10:13 AM, Michiel Helvensteijn<m.helvensteijn.remove gmail.com> wrote:Daniel Keep wrote:Yes you can do alias a w; w.x = f(); w.x = g(); But you can't do alias a.b.c w; ... And you can't create a ref local variable. But you can make a pointer local variable, of course, and for most purposes that's just as good since there's no need for -> in D. If structs get real constructors I'll be ok with saying goodbye to with(). It's just too useful for writing opCall pseudo-constructors: static T opCall() { T R; with(R) { x = 0; y = 1; z = getZValue(); } return R; } --bbThat's why I said 'or similar'. Doesn't D have anything to create an alias/reference to a value-type variable?you can also say { auto w = a; w.x = f(); w.x = g(); } or similar.Unless a is a value-type member of something else.
Aug 27 2009