I really love the with-block syntax. However, I keep running into an annoying inconsistency with it: you can't perform variable substitution when using the sugar for add().
What I mean by that is I would expect the following snippets of code to work the same:
win := Window
{
title = "test"
Text.make
}
and
text := Text.make
win := Window
{
title = "test"
text
}
Obviously, there are semantic reasons for this. The with block is looking for a field named text. But it would be incredibly useful to allow for this kind of substitution when building up complex UIs. You would start off filling the with block with widgets until it became too nested to read, and then you could simply break the code up by named variables to make it more readable.
Just something to consider. It's more of an aesthetics thing than anything else, since you can always throw an .add(test) after the constructor (though perhaps maybe not if the object is immutable).
I know you guys are still working out the kinks on constructors, so this may not be a problem when a consensus on the best construction syntax.
brianSat 21 Feb 2009
Yeah that one bites me a lot too, and I find it annoying. As you guessed it is really just a grammar issue. But I think I have been convinced we should really clean that bit of grammar up and use a comma for future proofing. In which case that problem goes away.
You mentioned adding add after the with-block, but you can also do this as a work around:
text := Text.make
win := Window
{
title = "test"
add(text)
}
The problem with that is if you have a simple container object, the syntax would be
Container {[ thingOne, thingTwo ]}
which while it isn't the end of the world, still feels a little clunky.
What are the semantics of a line in a with-block when there is no equals sign? That is, if we have a class Foo with a slot named bar, what does this code mean?
myFoo := Foo
{
bar
}
Unless that has some special significance, it seems like it should be able to grab everything in a with block without an equals sign and apply add() to it.
tactics Sat 21 Feb 2009
I really love the with-block syntax. However, I keep running into an annoying inconsistency with it: you can't perform variable substitution when using the sugar for add().
What I mean by that is I would expect the following snippets of code to work the same:
and
Obviously, there are semantic reasons for this. The with block is looking for a field named text. But it would be incredibly useful to allow for this kind of substitution when building up complex UIs. You would start off filling the with block with widgets until it became too nested to read, and then you could simply break the code up by named variables to make it more readable.
Just something to consider. It's more of an aesthetics thing than anything else, since you can always throw an .add(test) after the constructor (though perhaps maybe not if the object is immutable).
I know you guys are still working out the kinks on constructors, so this may not be a problem when a consensus on the best construction syntax.
brian Sat 21 Feb 2009
Yeah that one bites me a lot too, and I find it annoying. As you guessed it is really just a grammar issue. But I think I have been convinced we should really clean that bit of grammar up and use a comma for future proofing. In which case that problem goes away.
You mentioned adding add after the with-block, but you can also do this as a work around:
jodastephen Sat 21 Feb 2009
I just proposed in the other thread:
tactics Mon 23 Feb 2009
The problem with that is if you have a simple container object, the syntax would be
which while it isn't the end of the world, still feels a little clunky.
What are the semantics of a line in a with-block when there is no equals sign? That is, if we have a class Foo with a slot named bar, what does this code mean?
Unless that has some special significance, it seems like it should be able to grab everything in a with block without an equals sign and apply add() to it.