Dnia 2015-01-15, o godz. 08:10:59
Ian Lance Taylor <
ia...@golang.org> napisał(a):
> Besides the obvious issue of spooky action at a distance
This is a valid concern. And strong argument against the 'watch'
construct. Though I got "the watch" idea while pondering on
current "too many ; err != nil" threads and proposed patterns.
Some of them much convulted.
> what should happen if the variable is changed in nested function.
I meant _preceding_*simple*_statement_, i.e. an Assignment. Nothing more.
So nothing should happen. Compiler will not put the watch check, as nested
function definition (and a deffered call to) are not simple statements.
> > // been assigned to in a preceding simple statement.
_______________________________________^^^^^^__________
>
> func F() (err error) {
> watch (err != nil) {
> return error.New("watch")
> }
> defer func() {
> err = error.New("defer")
> return err
> }()
> return
> }
>
> Now what happens? If the answer is not reasonably obvious, then there
> is something wrong with the construct.
Good example.
For me the answer is obvious: neither anonymous func definition is a
simple statement nor the call to it assigns to the being watched variable is.
So there is no place for an "invisible watch check".
As to whether deffered anonymous functions should be allowed to have inner
watchers: I sincerely do not know. Though likely it would be good for
consistency.
>
> Ian