Python handles globals badly.

Steven D'Aprano steve at pearwood.info
Tue Sep 8 23:23:25 EDT 2015


On Wed, 9 Sep 2015 09:55 am, Michael Torrie wrote:

> On 09/08/2015 09:56 AM, Steven D'Aprano wrote:
>> http://exple.tive.org/blarg/2013/10/22/citation-needed/
>> 
>> It's a wonderful read.
> 
> I read this article, but I'm still uncertain to what his point actually
> is.  It's a great review of the history of C, some batch computing, and
> IBM's CEO's penchant for boat racing.  He tries to say that 0-based
> indexing made for faster compiling, but given the runtime nature of
> BCPL's ! operator, I don't see how it wouldn't affect runtime also.  He
> also says that saying pointers are the reason for 0-based indexing then
> you're wrong, except that BCPL's creator says in this same article that
> array variables are essentially pointers.

You know about the boat races, so you obviously read the article... so how
did you miss the part where the author explicitly raises the exact
objection you do?

   [quote]
   “Now just a second, Hoye”, I can hear you muttering. “I’ve looked at
   the BCPL manual and read Dr. Richards’ explanation and you’re not 
   fooling anyone. That looks a lot like the efficient-pointer-arithmetic
   argument you were frothing about, except with exclamation points.” 
   And you’d be very close to right. That’s exactly what it is – the
   distinction is where those efficiencies take place, and why.
   [end quote]


> A few people tried to point 
> this out in the comments but the author simply lambasted them, saying
> thinks like, "Thanks for leaving a comment. I'm sure it's made you feel
> clever."  

If people raise an objection that is already raised and covered in the text,
I'd be a tad snarky too. Like the guy who objects, tells the author he
ought to read Dijkstra, and *utterly failed* to notice that the article
links to the same paper.

Or the guy who somehow decided that the length of a 1-based array wasn't
end-start, but "there’s always a +1 or -1 to be strewn in there". O rly?

0-based indexes: [0|1|2|3|4], end-start = 4-0 = 4
1-based indexes: [1|2|3|4|5], end-start = 5-1 = 4

And yes, the fellow Joe who completely missed the point of the blog post,
and made the comment "You don’t think you’re wrong and that’s part of a
much larger problem, but you’re still wrong" completely deserved to be
called out on his lack of reading comprehension and smugness.


> Like I say I guess I must have missed his point in there 
> somewhere.  I suppose his point is C is 0-based because BCPL was, and
> I'm sure that's true, but I'm also sure K&R saw some benefits to keeping
> this in C.

The post has *nothing* to do with why languages today might use 0-based
arrays. It's not a post about which is better, or an attack on 0-based
languages. It's about the historical forces that lead to design decisions
being made, and how computer science is almost completely blind to those
forces. Lacking real insight into why decisions are made, the IT field is
dominated by superstitious post-hoc rationales being given as "the reason"
why things are the way they are, when the truth is far more interesting.


> In any case, 0-based indexing in Python makes a lot of sense when you
> bring in the slicing syntax. Especially if you think of slicing as
> operating on the boundaries between cells as it were.
> 
> I used a 1-based indexed language (BASIC) for many years, and I was
> always having to subtract 1 from things.  So 0-based is simply more
> convenient for me.

There are certainly advantages to 0-based indexing. But there are also
advantages to 1-based. For example, many mathematical algorithms are best
written in terms of 1-based indexes, or at least are described as such. For
example, quartile calculations. I'm constantly having to adjust such
algorithms to work with Python.



-- 
Steven




More information about the Python-list mailing list