3 ms·
Really like how the additions are formatted: "put this code here" is pretty nice. Plus your handwriting is really neat :) A couple of comments: > The right—or
by saagarjha 8y ago
Really like how the additions are formatted: "put this code here" is pretty nice. Plus your handwriting is really neat :)
A couple of comments:
> The right—or wrong depending on how you look at it—set of bytecode instructions could jump into the middle of a block, or from one scope into another.
> The VM will happily execute that, even if the result leaves the stack in an unknown, inconsistent state.
The JVM (mentioned earlier) prevents this by not offering the tools to do this, because its semantics ensure that the stack is always in a valid state.
> Have you ever noticed that the ( after the if keyword doesn’t actually do anything useful? The language would be just as unambiguous and easy to parse without it, like:
> if condition) print("looks weird");
> The closing ) is useful because it separates the condition expression from the body. Some languages use a then keyword instead. But the opening ( doesn’t do anything. It’s just there because unmatched parentheses look bad to us humans.
Note that many modern languages drop the parentheses altogether.
> That is, if you can get past Dijkstra’s insufferable faux-modest self-aggrandizing writing style…Ah, yet another one of my many discoveries. I couldn’t even be bothered to write it up until the clamoring masses begged me to.
I know that a lot of people in computer science can be self-absorbed, and I'm all for more modesty, but I think Dijkstra is prolific enough to get a bit of a pass ;)
> You have two computers with the same program running on the same exact same inputs—so totally deterministic. You pause one of them at an arbitrary point in its execution. What data would you need to send to the other computer to be able to stop it exactly as far along as the first one was?
Just look at a modern scheduler and see what it saves whenever it context switches: that's your minimum set.
- frabert 8y ago> Just look at a modern scheduler and see what it saves whenever it context switches: that's your minimum set. I'd call that an upper bound on the size of the minimum set, one that is guaranteed to work with any kind of program. With more info on the executing program you could probably save less state and still keep the program running fine
- nybble41 8y agoIt's not an upper bound either since the data saved on context-switch doesn't include the contents of the stack or data segment or other global process state. It's not sufficient to save and restore only the thread context. One upper bound, mentioned in the article, would be the inputs fed to the program thus far and the total number of instructions executed. Another would be the current thread context plus all working memory and other process state, excluding any data which can be proven not to be accessed for the remainder of the program. Which of these is smaller would depend on the program and where it was stopped; at the beginning you just have a (small) counter and no inputs consumed, but then again you may have fed the program gigabytes of inputs and stopped it just before it returned a small amount of summary data.
- andreareina 8y agoWell I was going to say that if you were only concerned with stopping execution, you could just count the number of instructions executed but alas TFA mentions that already. I'm not familiar with modern schedulers but it seems to me that to continue execution from a stopping point you'd need to restore (and therefore save) at least the instruction and stack pointers, plus maybe a couple other pointers for stuff like the global and current environments. Obviously if you're operating a register machine you'd need to stash/restore the state of all the registers as well, IIRC x86 uses the stack for that.
- pjc50 8y ago> You have two computers with the same program running on the same exact same inputs—so totally deterministic. You pause one of them at an arbitrary point in its execution. What data would you need to send to the other computer to be able to stop it exactly as far along as the first one was? What Dijkstra is really getting at here is that there is an "approximate computer" in the programmer's head whenever they are reasoning about the program, and that minimising the amount of information that needs to be transferred into the programmer's head (and keeping it local, rather than scattered about the program!) helps hugely.
- skybrian 8y agoI think he might also have been thinking about how to prove a program correct? To do that in imperative code, it might be useful to have some concept of a program location that's rigorous enough to represent mathematically.