Thomas Leonard
2011-10-20 12:12:28 UTC
People often try to use return inside when blocks. Currently, this just
produces confusing "Ejector must be enabled" errors.
How about requiring the use of "return" to return a value from a when block?
There are a few places where this would be useful:
- Often you will move a whole block in to or out of a when() block. It's
useful if you don't have to change all return lines when you do this.
- People sometimes don't notice that the value of the last expression is
used, and put something after it.
e.g. they change
return when (foo) -> {
foo.invoke()
}
to
return when (foo) -> {
foo.invoke()
traceln("here")
}
and then wonder why they're getting null pointer exceptions elsewhere.
- You can accidentally return a value, when all you intended was to tell
the caller when you were done.
Patch to add #pragma.enable("easy-when-binds-return"):
http://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/c10e7bc99bbfbabbbb28ea714e19855fbca8c389
--
Dr Thomas Leonard
IT Innovation Centre
Gamma House, Enterprise Road,
Southampton SO16 7NS, UK
tel: +44 23 8059 8866
mailto:***@it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk/
produces confusing "Ejector must be enabled" errors.
How about requiring the use of "return" to return a value from a when block?
There are a few places where this would be useful:
- Often you will move a whole block in to or out of a when() block. It's
useful if you don't have to change all return lines when you do this.
- People sometimes don't notice that the value of the last expression is
used, and put something after it.
e.g. they change
return when (foo) -> {
foo.invoke()
}
to
return when (foo) -> {
foo.invoke()
traceln("here")
}
and then wonder why they're getting null pointer exceptions elsewhere.
- You can accidentally return a value, when all you intended was to tell
the caller when you were done.
Patch to add #pragma.enable("easy-when-binds-return"):
http://gitorious.org/~tal-itinnov/repo-roscidus/it-innovation/commit/c10e7bc99bbfbabbbb28ea714e19855fbca8c389
--
Dr Thomas Leonard
IT Innovation Centre
Gamma House, Enterprise Road,
Southampton SO16 7NS, UK
tel: +44 23 8059 8866
mailto:***@it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk/