Edit: I realize that Java doesn't have delegates, but I would say that's a point against Java, not a point in favor of this method.
Edit: I realize that Java doesn't have delegates, but I would say that's a point against Java, not a point in favor of this method.
I'm not sure what you mean by delegates, but it sounds like you're saying that you don't need special syntax for conditions when you have first-class functions and simpler control-flow primitives. True, but sugar is nice sometimes; I'd often rather have a list comprehension than a pile of gotos and assignments.
As for sugar, I agree that it's nice sometimes, but I disagree with extending exception handling specifically. Exceptions are for errors, such as sending data over a closed stream, or indexing an array out of bounds. This "condition system" pattern encourages using exceptions for logic flow. Because why pass a function all the way down the call stack when you can just throw an exception to request that data from higher in the call stack, right?
Exceptions are errors, and they should be treated as such in all cases.
This sounds an awful lot like a semantic argument.
If you have resumable exceptions, and can raise an exception deep in the stack to ask higher-stack callers for more information then that's an query.
If you raise an exception in non-exceptional circumstances then that's a scoped announcement.
The mere fact that in some languages they use the same run-time hooks as exceptions is irrelevant.
Exceptions, where I first learned of them in Smalltalk derive from a prototype class that isn't named Exception, and I've seen all manner of uses of the same machinery in stack-twisting.
After all once you have full closures, and full control over your stack and context why shouldn't you use it for higher order abstractions involving the stack-context?
----
in [1], tomp [2] posted:
That's one way to look at it, and it certainly is valid, to some extent.
Another way to look at it is that exceptions are fundamentally limited, and conditions provide a whole new sea of possibilities.
His example is rather awkward and actually confuses the reader, rather than excites. The point of conditions actually is to allow flexibility without all the if statements and delegates. His final getVal() function should look like this Object getVal() { try { if (val == null) throw new NoValException(); else return val; } catch (UseValRestart r) { return r.getVal(); } } and the high-level code should handle how the value is provided (either some specific value, user input, web request, random bits, etc...). So, one only has to write the code for getVal() once and can customize it indefinitely.
----