Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eteration - explanation and example

Can someone explain what exactly is Eteration and show an example?

source: Long running tasks YUI blog by Douglas Crockford

like image 667
Bakudan Avatar asked Aug 25 '11 03:08

Bakudan


People also ask

What is iteration explain with example?

Iteration is the process of repeating steps. For example, a very simple algorithm for eating breakfast cereal might consist of these steps: put cereal in bowl. add milk to cereal. spoon cereal and milk into mouth.

What's a real life example of iteration?

Here are some iteration examples: Apple has released multiple different versions of each model of its iPod products. The Nano, for example, has evolved from an original slim mP3 player with a very small screen to a tiny square touch-screen version to a longer, thinner touch screen version.

What do you mean by iterates?

Definition of iterate transitive verb. : to say or do again or again and again : reiterate.

What is iteration explain with syntax?

Iteration statements cause statements (or compound statements) to be executed zero or more times, subject to some loop-termination criteria. When these statements are compound statements, they are executed in order, except when either the break statement or the continue statement is encountered.


1 Answers

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).

like image 87
luvieere Avatar answered Oct 13 '22 17:10

luvieere