[Python-Dev] Lukewarm about range literals (original) (raw)

Charles G Waldman cgw@fnal.gov
Mon, 28 Aug 2000 17:47:30 -0500 (CDT)


I guess I'm in the minority here because I kind of like the range literal syntax.

Guido van Rossum writes:

I notice that:

for i in [:100]: print i

looks a bit too much like line noise. I remember that Randy Pausch once mentioned that a typical newbie will read this as:

for i in 100 print i

When I was a complete Python newbie (back around 1994) I thought that the syntax

l2 = l1[:]

for copying lists looked pretty mysterious and weird. But after spending some time programming Python I've come to think that the slice syntax is perfectly natural. Should constructs be banned from the language simply because they might confuse newbies? I don't think so.

I for one like Thomas' range literals. They fit very naturally into the existing Python concept of slices.

and they will have a heck of a time to reconstruct the punctuation, with all sorts of errors lurking, e.g.:

for i in [100]: print i for i in [100:]: print i for i in :[100]: print i

This argument seems a bit weak to me; you could take just about any Python expression and mess up the punctuation with misplaced colons.

Is there anyone who wants to champion this?

I don't know about "championing" it but I'll give it a +1, if that counts for anything.