I did mention previously that I'd write up the use cases we've been discussing wrt blocks:
1) Closure - A block of code that has access to its lexical scope. Code within it is effectively normal code with the single rule that return returns to the invoker of the closure (avoiding non-local return issues)
2) With blocks - A declaration construct which allows variables in the current scope to be assigned to fields of the referenced object. The LHS of assignments refers to the fields of the object, the RHS of assignments refers to the current scope.
2a) Construction - Used during construction. Const fields may be set. Private fields may not be set.
2b) Normal - Used at any time after construction. Neither const nor private fields may be set.
2c) Deserialize - Used during deserialization. Const and private fields may be set.
2d) Duplication - Used after duplicating an object to allow for changing field on immutable objects. Const fields may be set. Private fields may not be set.
I think this captures the main essence of the cases we currently have. Although I may have missed some details? Perhaps with-blocks have more power than just declaration?
brianTue 12 Aug 2008
Yeap I think you've captured it pretty well (although where ever you mention private fields, is really normal protection scoping applies: private, protected, and internal). And this is pretty much the design I'm thinking we ought to stick with.
I've been debating about serialization since by definition that means fields are public (especially with a format designed to be read/written by humans). I'm almost thinking that only public fields can be serialized.
And of course the big open issue is validation. On that one I've been thinking more along the lines of fields which just can't be set in a with-block at all and require constructors.
jodastephen Mon 11 Aug 2008
I did mention previously that I'd write up the use cases we've been discussing wrt blocks:
1) Closure - A block of code that has access to its lexical scope. Code within it is effectively normal code with the single rule that
return
returns to the invoker of the closure (avoiding non-local return issues)2) With blocks - A declaration construct which allows variables in the current scope to be assigned to fields of the referenced object. The LHS of assignments refers to the fields of the object, the RHS of assignments refers to the current scope.
2a) Construction - Used during construction. Const fields may be set. Private fields may not be set.
2b) Normal - Used at any time after construction. Neither const nor private fields may be set.
2c) Deserialize - Used during deserialization. Const and private fields may be set.
2d) Duplication - Used after duplicating an object to allow for changing field on immutable objects. Const fields may be set. Private fields may not be set.
I think this captures the main essence of the cases we currently have. Although I may have missed some details? Perhaps with-blocks have more power than just declaration?
brian Tue 12 Aug 2008
Yeap I think you've captured it pretty well (although where ever you mention private fields, is really normal protection scoping applies: private, protected, and internal). And this is pretty much the design I'm thinking we ought to stick with.
I've been debating about serialization since by definition that means fields are public (especially with a format designed to be read/written by humans). I'm almost thinking that only public fields can be serialized.
And of course the big open issue is validation. On that one I've been thinking more along the lines of fields which just can't be set in a with-block at all and require constructors.