🔗 COMEFROM
In computer programming, COMEFROM (or COME FROM) is an obscure control flow structure used in some programming languages, originally as a joke. COMEFROM
is roughly the opposite of GOTO
in that it can take the execution state from any arbitrary point in code to a COMEFROM
statement.
The point in code where the state transfer happens is usually given as a parameter to COMEFROM
. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROM
s referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal.
A simple example of a "COMEFROM x
" statement is a label x
(which does not need to be physically located anywhere near its corresponding COMEFROM
) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM
. This may also be conditional, passing control only if a condition is satisfied, analogous to a GOTO within an IF statement. The primary difference from GOTO is that GOTO only depends on the local structure of the code, while COMEFROM depends on the global structure – a GOTO transfers control when it reaches a line with a GOTO statement, while COMEFROM requires scanning the entire program or scope to see if any COMEFROM statements are in scope for the line, and then verifying if a condition is hit. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the line or label in question that control will mysteriously jump to another point of the program – one must study the entire program to see if any COMEFROM statements reference that line or label.
Debugger hooks can be used to implement a COMEFROM statement, as in the humorous Python goto module; see below. This also can be implemented with the gcc feature "asm goto" as used by the Linux kernel configuration option CONFIG_JUMP_LABEL. A no-op has its location stored, to be replaced by a jump to an executable fragment that at its end returns to the instruction after the no-op.
Discussed on
- "COMEFROM" | 2019-10-19 | 82 Upvotes 24 Comments
- "COMEFROM" | 2011-11-17 | 41 Upvotes 20 Comments