3 ms·
This is literally one of the oldest problems in programming: returning the stack to its previous state before returning from a subroutine, or jumping back to th
by jameshart 3y ago
This is literally one of the oldest problems in programming: returning the stack to its previous state before returning from a subroutine, or jumping back to the start of a loop.
Specifically, the XML element example involves ‘pushing’ the context of a new element into the document - a context which MUST be ‘popped’ before continuing.
This problem is literally why GOTO was considered harmful, why old school programmers insist that subroutines should have one return statement, why functional programmers are right to despise mutation, and why iterators are preferable to loops.
So as a programmer, you shouldn’t be surprised that your language of choice has clever ways to solve this problem, or that you can think of a dozen ways of avoiding this. It’s like the ur-problem of writing code.