www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - With block proposal

reply James McComb <alan jamesmccomb.id.au> writes:
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
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
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
prev sibling next sibling parent reply James McComb <alan jamesmccomb.id.au> writes:
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
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
"James McComb" <alan jamesmccomb.id.au> wrote in message
news:c7d7ph$1qfo$1 digitaldaemon.com...
 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! :)
That's a shame, as with the smileys I think you have a winning proposal. :-)
May 06 2004
prev sibling next sibling parent reply Ben Hinkle <bhinkle4 juno.com> writes:
 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
parent James McComb <alan jamesmccomb.id.au> writes:
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
prev sibling next sibling parent vathixSpamFix dprogramming.com (Vathix) writes:
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
prev sibling next sibling parent reply Joel Lucsy <jjlucsy usol.com> writes:
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
parent Ant <Ant_member pathlink.com> writes:
In article <c7djpb$2gfk$1 digitaldaemon.com>, Joel Lucsy says...
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; }
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...
May 06 2004
prev sibling next sibling parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
 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
prev sibling parent reply Freeman <ant108 aol.com> writes:
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
parent reply Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
Freeman wrote:

 Example:
 
 with(a)
 {
    :x = x;  // Unambiguously means a.x = x
    :x = .x; // Unambiguously means a.x = .x
 }
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 Helvensteijn
Aug 27 2009
parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Michiel Helvensteijn wrote:
 Freeman wrote:
 
 Example:

 with(a)
 {
    :x = x;  // Unambiguously means a.x = x
    :x = .x; // Unambiguously means a.x = .x
 }
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.
Unless a is a value-type member of something else.
Aug 27 2009
parent reply Michiel Helvensteijn <m.helvensteijn.remove gmail.com> writes:
Daniel Keep wrote:

 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.
That's why I said 'or similar'. Doesn't D have anything to create an alias/reference to a value-type variable? -- Michiel Helvensteijn
Aug 27 2009
parent Bill Baxter <wbaxter gmail.com> writes:
On Thu, Aug 27, 2009 at 10:13 AM, Michiel
Helvensteijn<m.helvensteijn.remove gmail.com> wrote:
 Daniel Keep wrote:

 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.
That's why I said 'or similar'. Doesn't D have anything to create an alias/reference to a value-type variable?
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; } --bb
Aug 27 2009