The "loop and a half"

Steve D'Aprano steve+python at pearwood.info
Wed Oct 4 20:16:45 EDT 2017


On Thu, 5 Oct 2017 02:56 am, Paul Moore wrote:

> On 4 October 2017 at 16:35, Steve D'Aprano <steve+python at pearwood.info>
> wrote:
>> I've been programming in Python for twenty years, and I don't think I have
>> ever once read from a file using a while loop.
> 
> Twenty years isn't long enough :-) The pattern the OP is talking about
> was common in "Jackson Structured Programming" from back in the 1980s.

In context, I was replying to a quoted author who claims this pattern is
universal in Python code. I don't doubt that pattern exists *at all*, only
that it is common in Python.

That pattern wasn't even universal in the 80s. In Pascal, for example, you
read from a file using something very close to this:

reset(infile);
while not eof(indeck) do
  begin
    read(indeck, buffer);
    {now process the buffer}
  end;


I recall that the Pascal compiler had to do some clever behind the scenes
jiggery-pokery to get eof() to work, but that's what compilers are supposed
to do: make common tasks easy for the programmer.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list