According to wikipedia COMEFROM flow control is considered a joke, unreadable or downright harmful. I'd imagine such a feature would be very useful in AOP scenarios (ie. adding logger to methods without adding logger calls to methods).
Does the downside of non-obviousness of such a contro开发者_开发百科l structure outweigh the potential usefulness? Are there any other downsides to consider?
Prompted to ask this question because of this.
For starters is basically useless in any modern language because you need to either:
- Reference the position to jump from by line number, and these are volatile.
- Place a marker or label in the code to denote a position that can be jumped from, thus destroying any possible benefits of not needing to do this.
Also:
- Makes any kind of debugging by inspection essentially useless.
- Can't really capture any context from where it jumped unless you keep variables persistant, which is asking for trouble.
A much better idea would be to instead:
- Write a hooking API.
- Call a function!
For the purpose you mention, Aspect Oriented Programming (wikipedia) seems a more organized solution than comefrom
. See the bottom of Motiviation and Basic Concepts (ibid) for an example of how logging can be added to a method in a separate textual unit.
In a sufficiently dynamic language, it is possible to handle this sort of thing using "wrap-around" modifiers to a method:
def do_something
...
end
log :do_something, "Something got done"
In this contrived example, the log
macro causes the do_something
method to be replaced by a new method which first calls the original do_something
method, and then writes something to the log.
精彩评论