Eteration - explanation and example Eteration - explanation and example javascript javascript

Eteration - explanation and example


Initially, I thought it was just a typo of iteration, as searching online for eteration yields no significant results.

But, then, I came across references that state that the term is coined by Crockford himself, in one of his talks.
Online, the only place where I could find an explanation is on his page, in The Factorial Tutorial, an article where, in Act 2, as a comment to a code sample, he states:

Act 2a: message iteration (eteration)

This seems to be part of a related pair of terms, as his next code sample, that performs recursion without using a stack, contains the other member of the pair:

Act 2b: message recursion (ecursion)

So, it seems that eteration and ecursion are terms invented and defined by Crockford himself to refer to message iteration and recursion in the context of the E Programming Language, designed on top of Java for developers who write distributed applications.

The fact that the language is called E is perhaps a reason to give its specific iteration and recursion flavors the chosen terminology (**e***teration* and **e***cursion*).

If the context of Javascript, Crockford explains the term eteration as part of the talk Crockford on JavaScript -- Scene 6: Loopage, starting from minute 30:40:

Eteration means to break a task into multiple turns so that on each eteration, instead of going through a conventional loop, at the bottom of the loop we call setTimeOut, passing it a function which causes us to do the next eteration. That means that the turns are going to be short — the turn's only as long as one eteration – and we can do as many eterations as we want and not lock up the event loop.

The result is that, instead of a tight loop, blocking the interface if it takes too long, the eteration schedules each step of the loop, in a chain that only blocks the interface while the actual step executes, not between steps. This makes it possible to perform long-running tasks in the same thread as the interface (Javascript is single-threaded), while maintaining application responsiveness.

Check out the full talk in much better quality and accompanied by a full-text transcript here.

Also, for a reference on how such a technique might be implemented, consider the following scenario:

<html> <head>  <script type="text/javascript">   function testFeedback()   {      var feedbackDiv = document.getElementById("feedbackDiv");      feedbackDiv.innerHTML += "The Interface is Still Responsive!</br>";   }   var currentNumber = 0;   var loopStepDelay = 30;   function performLoopStep()   {     var numbersDiv = document.getElementById("numbersDiv");     numbersDiv.innerHTML = currentNumber++;     setTimeout("performLoopStep()", loopStepDelay);   }   setTimeout("performLoopStep()", loopStepDelay);  </script> </head> <body>  <div id="numbersDiv"></div>  </br>  </br>  <div id="feedbackDiv"></div>  </br>  </br>  <button onClick="testFeedback()">Try Me</button> <body></html>

There are two divs, one displaying the indices of the ongoing eteration, the other appending the text The Interface is Still Responsive! on each Try Me button press. As you can see from the code, the eteration steps are scheduled by setTimeout some time interval apart, allowing for user interaction to take place and be processed as well. Thus, the eteration steps will continue to run as the user clicks on the button and triggers the update of the second div, maintaining the page's responsiveness while doing real progress with the work it has to perform (in this case, simply displaying indices).