Search code examples
javascriptsyntaxdijkstragoto

Does Dijkstra's "Case against the GOTO statement" apply just as much to modern day calling of named encapsulations of code as functions?


I don't know how it worked back in the day, so I've no idea what he was referring to.

But, take JS:

var x = 5;
var foo = function(y) { console.log(2); };
var y = 6;
foo(); // is this not in essence a goto statement?

If not, then what was different about GOTO statements?

Would Dijkstra have opposed JS on these grounds?


Solution

  • In your example, you are calling a subroutine rather than unconditionally and permanently transferring the flow of control (which is what goto does).

    If you put code after foo();, that code would get executed after foo() is called.