Author:halw

Date:2010-02-04T22:27:19.000000Z


git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@437 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
halw
2010-02-04 22:27:19 +00:00
parent 8a53f20b29
commit 1e05b9bbcf
2 changed files with 35 additions and 11 deletions

View File

@@ -60,7 +60,7 @@ First let's look at the loop in what is probably its most common usage. This is
<code>Initialization</code> and <code>Loop_body</code> are sequences of zero or more instructions; <code>Exit_condition</code> is a boolean expression.
The effect is to execute <code>Initialization</code>, then, zero or more times until <code>Exit_condition</code> is satisfied, to execute <code>Loop_body</code>. (If after <code>Initialization</code> the value of <code>Exit_condition</code> is already true, <code>Loop_body</code> will not be executed at all.)
The effect is to execute <code>Initialization</code>, then, zero or more times until <code>Exit_condition</code> is satisfied, to execute <code>Loop_body</code>. (If after <code>Initialization</code> the value of <code>Exit_condition</code> is already true, <code>Loop_body</code> will not be executed at all.) So, at the risk of stating the obvious, the key to loops that always complete is to ensure that there is something in the loop body that will always cause the exit condition eventually to become true.
This form of the loop is used commonly to traverse data structures. For example, suppose that we wished to print every element in a linked list of strings. We can do so with this usage of the loop construct, as shown below.
@@ -78,20 +78,42 @@ This form of the loop is used commonly to traverse data structures. For example,
my_list.forth
end
</code>
Loop example 1.
The <code>Initialization</code> part will attempt to set the cursor at the first item of the list. The loop will exit when there is no active list item. Then, in the <code>Loop_body</code>, the current list item will be printed, and the cursor advanced.
So, this usage of the loop construct has been the traditional mechanism for traversing data structures. However, extensions to Eiffel's loop construct have provided a more concise way of expressing the same traversal:
So, the usage of the loop construct in Loop example 1 above has been the traditional mechanism for traversing data structures. However, extensions to Eiffel's loop construct have provided a more concise way of expressing the same traversal:
<code>
across my_list as c loop print (c.item) end
across my_list as ic loop print (ic.item) end
</code>
Loop example 2.
Here the <code>across</code> indicates an iteration process across the structure <code>my_list</code>. The <code>as c</code> indicates that a cursor object referenced by the name <code>c</code>, and available only for the scope of the iteration, will be created to effect the iteration. The element of <code>my_list</code> which is currently referenced by the cursor <code>c</code> is <code>c.item</code> as you see in the call to <code>print (c.item)</code> in the loop body. The loop body does not contain the call to the structure's <code>forth</code> feature, as our more traditional example did. Neither do you see the call to <code>start</code> nor the check of <code>off</code> in the exit condition. The semantics of the iteration abstract these for you, relieving you of their burden ... while eliminating some opportunities for error.
Concerning cursors, both ways of using the loop construct to traverse a structure employ a cursor. In the traditional usage, the cursor is internal to the structure object. In the case of the example, that would be the instance of <code>LINKED_LIST [STRING]</code> called <code>my_list</code>. Applying the feature <code>item</code> to <code>my_list</code> retrieves the list element currently referenced by the cursor. In the iteration version of traversal, the variable <code>c</code> holds the iteration cursor, external to the list object. So, you apply <code>c.item</code> to get the current list element. The advantage to the external cursor is that multiple traversals of the structure can occur simultaneously without interfering with one another. This is possible in the traditional usage, but only by saving and restoring the structure's cursor.
Here the <code>across</code> indicates an iteration process across the structure <code>my_list</code>. The "<code>as ic</code>" indicates that an iteration cursor object referenced by the name <code>ic</code>, and available only for the scope of the iteration, will be created to effect the iteration. The element of <code>my_list</code> which is currently referenced by the cursor <code>ic</code> is <code>ic.item</code> as you see in the call to <code>print (ic.item)</code> in the loop body. The loop body does not contain the call to the structure's <code>forth</code> feature, as our more traditional example did. Neither do you see the call to <code>start</code> nor the check of <code>off</code> in the exit condition. The semantics of the iteration abstract these for you, relieving you of their burden ... while eliminating some opportunities for error.
At first observation, it may not appear that both traversal examples are using the same language construct. But, indeed they are simply two different forms of a single language construct. In order to see this more clearly, it will help now to examine (almost) the entire anatomy of the loop construct.
Concerning cursors, both ways of using the loop construct to traverse a structure employ a cursor. In the traditional usage, the cursor is internal to the structure object. In the case of the example, that would be the instance of <code>LINKED_LIST [STRING]</code> called <code>my_list</code>. Applying the feature <code>item</code> to <code>my_list</code> retrieves the list element currently referenced by the cursor. In the iteration version of traversal, the variable <code>ic</code> holds the iteration cursor, external to the list object. So, you apply <code>ic.item</code> to get the current list element. The advantage to the external cursor is that multiple traversals of the structure can occur simultaneously without interfering with one another. This is possible in the traditional usage, but only by saving and restoring the structure's cursor.
At first observation, it may not appear that both traversal examples are using the same language construct. But, indeed they are simply two different forms of a single language construct. In order to see this more clearly, it will help now to examine the specific parts of the loop construct.
====Two basic loop forms====
The two basic forms of use of the Eiffel loop construct can be differentiated by the parts of the construct with which they begin.
The form shown in Loop example 1 above begins with an ''Initialization'' part ( <code>from my_list.start</code> ). Let's call this form the ''traditional'' form.
The form shown in Loop example 2 above begins with an ''Iteration'' part ( <code>across my_list as c</code> ). We'll call this form the ''iteration'' form.
The iteration form is special in the sense that it is designed to work with objects which are ''iterable'', usually data structures. The iteration form always targets a particular object, usually a data structure, based on a class that inherits, either directly or indirectly from the library class <code>ITERABLE</code>.
Every valid loop must have at least an ''initialization'' part or ''iteration'' part. An ''iteration'' part always precedes an ''initialization'' part. So, it is possible for loops in the iteration form (but not possible for traditional loops) to have both. Suppose we wanted to compute the sum of the lengths of all the strings in the list <code>my_list</code>. We could write an iteration loop with an initialization setting the sum to zero:
<code>
across my_list as ic from sum := 0 loop sum := sum + ic.item.count end
</code>
Loop example 3.
===Debug===

View File

@@ -5,7 +5,7 @@
Often, when we speak about Eiffel to prospective users, we hear them repeat misinformation about the method, the language, or the tools. Most of the time, the stories are familiar to us … and untrue. Here are a few of the myths that we hear most often, as recounted and debunked by Eiffel Trainer Hal Webre in his [http://www.eiffel.com/developers/presentations/eiffel_introduction/player.html?slide= introductory online presentation] to the series entitled [http://eiffel.com/developers/presentations/ "Where Eiffel Fits"].
==Eiffel is an "academic" language only: ''Wrong ... twice!!''==
==Eiffel is an "academic" language only: ''Whoa, wrong! Twice!''==
Recently, I was offered the opportunity to speak to a local technology group about Eiffel for Microsoft .Net. The leader of this group is part of a small commercially-oriented software development company. Concerning Eiffel, he said, “All I know about Eiffel is that its an academic language.”
@@ -18,13 +18,13 @@ Secondly, Im not sure what “academic language” means exactly, but if it m
But Eiffel is also used successfully in many commercial and government endeavors. If you have any doubts, pay a visit to [http://eiffel.com/general/success-stories.html eiffel.com] and check out the success stories and customers testimonials.
==Eiffel is not for doing "real" work: ''Who told you that!?!''==
==Eiffel is not for doing "real" work: ''That's a joke, right?''==
Occasionally weve heard people say that Eiffel is only suitable for building “toy” systems.
This is similar to the "academic language" argument and is just as false.
We see Eiffel being used often in situations in which other technologies fail. If anything it is the other commonly used technologies that tend to break down under stress.
In actuality, we see Eiffel being used often in situations in which other technologies fail. If anything it is the other commonly used technologies that tend to break down under stress.
We see Eiffel being used instead of other technologies for systems in which scalability and reliability are essential.
@@ -55,7 +55,7 @@ First, almost all Eiffel people were proficient in some other technology before
Additionally, it is important also to understand that Eiffel developers are easy to create. Because Eiffel is simple, clean, and elegant, it doesnt take long to get people going with it. I teach a five-day course that contains fifteen programming exercises. Each time Ive taught the course, almost every student has finished every exercise. Students leave with a good foundation for how to begin saving time and money for their organization by constructing quality software with Eiffel. These people can be fluent in Eiffel in as little as a couple of months. This can be contrasted with the other extreme ... a well-known Microsoft Windows expert told me a couple of years ago that he estimates it to take 5 to 7 years to become truly fluent in C++/COM programming on Windows. Programmers who are proficient in other technologies often experience Eiffel as a breath of fresh air.
==Eiffel might not be around in five/eight/ten (choose one) years: ''Better clean your crystal ball, Nostradamus!''==
==Eiffel might not be around in five/eight/ten (choose one) years: ''Better recalibrate your crystal ball, Nostradamus!''==
I think the first time I heard this one, it was about 1989.
@@ -69,7 +69,9 @@ Its possible that twenty-five years from now, there will be a significantly b
Besides, Eiffel constantly implements refinements and new capabilities with minimal impact on existing software. [[Void-safe programming in Eiffel|Void-safe programming]] is an excellent example of this.
Dont worry about it. Eiffel will be here.
You can get a feel for this issue by watching [http://channel9.msdn.com/posts/Charles/Emmanuel-Stapf-Eiffel-and-Contract-Oriented-Programming/ this video on Microsoft Developers Network Channel9]. Here you'll see Emmanuel Stapf, an engineer at Eiffel Software, speak with Mads Torgersen, one of Microsoft's C# language designers. You'll hear how Eiffel stays fresh and continues to set a technological standard worthy of the aspirations of other technologies.
So, dont worry about it. Eiffel will be here.