Compare source code

Antoon Pardon Antoon.Pardon at rece.vub.ac.be
Thu Nov 4 10:08:13 EDT 2010


On Fri, Nov 05, 2010 at 06:29:11AM -0700, Ethan Furman wrote:
> Antoon Pardon wrote:
> >Unless, your code is split over different pages, as when it is printed in a book.
> >You also need to see the next piece of code to notice the dedention.
> >
> >e.g. I have the following code at the bottom of my editor.
> >
> >  for i := 0 to 9 do
> >    some(code);
> >    more(code);
> >  end;
> >
> >I can by just looking at this code notice that I'm looking at the whole for block.
> >
> >
> >But when I have similar python code at the bottom of the page.
> >
> >  for i in xrange(10):
> >    some(code)
> >    more(code)
> >
> >Then I can't make out whether I'm looking at the whole for suite or not.
> These code pieces are not equivalent -- you have four lines of code
> in the first piece, only three lines in the python piece; in other
> words, if the "end;" were not on screen, you would still have no
> idea if it was the whole block or not; in still other words, the
> "end;", just like the dedented line, provides the context.

That one piece of code is only three lines and the other is four
doesn't make them not equivallent. Adding a fourth (empty) line
to the python example wouldn't have changed things significantly.

These two pieces are equivallent in any significant way. Both
are examples of a for loop, one with its block the other with
its suite. They are both complete for-statements as defined by
the respective grammes. Both perform the same functionality.

The complete for-statement is all you need to see, to know
you are seeing the complete for-statement in the first example.
So all you need is in context information.

To know you see the complete for statement in python, you need
to see more than just the complete for-statement. You need out
of context information.

-- 
Antoon Pardon



More information about the Python-list mailing list