[Chicago] Reading From a Directory

Martin Maney maney at two14.net
Tue May 10 15:51:59 CEST 2011


On Mon, May 09, 2011 at 11:35:49PM -0500, Clyde Forrester wrote:
> I don't think that you understand my objection. C has libraries for
> opening and reading directories. Python does not. I have no
> objection to modules, packages and libraries. What I'm objecting to

Well, of course I (and others) misunderstood you, since you made so
much about modules as a problem - or so it sounded.  When someone new
(and forgive me, but I don't recognize your name, so I have to guess at
what might be between the lines (1)) asks a question with so much chaff
surrounding it, well, that we guess wrong is hardly surprising.

> Most languages just treat directories as a special sort of file, and just
> don't get all that worked up.

In fact, all the scripting languages are relatively thin veneers over a
VM and runtime that is written in another language.  Even Java - the
JIT is a relatively recent optimization of its interpreted VM model. 
It is in fact one of Python's strengths that it's fairly easy to adapt
many foreign (C, mostly) libraries, or to provide a compatible binary
(C again, nearly always) replacement for a pure Python implementation
when the latter is actually a performance issue.

> done, it failed, no need to go on. But with directories, there isn't
> a situation where I don't want to examine the whole thing. That was
> a big blindspot in my mind, and that's what I'm getting used to.

Ah, right.  This is a small example of the sort of thing that gives
rise to the "Guido's time machine" theory.  Over and over, folks like
you and me discover that Python already does something that we thought
we'd have to assemble from parts, or that it just wouldn't have.  The
theory is that Guido went back in his time machine and made it so that
it was always so, 'cause how else could it have been in there all this
time?  Hmmm, let me see if I can find the .Sig item about that...


(1) I didn't think of it last evening, but I'll bet a lot of the "no,
you don't want to do that" that Google found you was about people who
asked (or seemed to ask) how to literally open and read a directory -
not the sensible readdir, but actually reading it like a file.  That is
something which, in fact, you almost never should wish to do, and
although it's been a long time since I've hung out in C-heavy areas, I
do recall that it used to be one of the fairly common queries.

-- 
To fix that one, I'd have to travel all the way back to the early eighties
and convince the BSD design team to improve the diagnostics abilities of
the Unix kernel in general, and of select(2) in particular.  And while I
could certainly do that, I'm worried of the consequences - the BSD vs.
System V split might never have happened, Unix would have ruled the world,
we'd all be programming in awk++, and Bill Gates would be an obscure
patent lawyer that no one had heard of.  -- Guido van Rossum


More information about the Chicago mailing list