Profile cover photo
Profile photo
Guido van Rossum
65,441 followers -
Creator of the Python programming language.
Creator of the Python programming language.

65,441 followers
About
Posts

Post has attachment
My son goes to school here. I know many of those kids.
Add a comment...

Post has attachment
Commenting is disabled for this post.

Post has attachment
Add a comment...

I just love the flowery language in this spam comment that Blogger intercepted for me:

"Its such as you learn my thoughts! You seem to grasp so much approximately this, such as you wrote the ebook in it or something. I think that you simply can do with some% to force the massage house a bit, however other than that this is magnificent blog. An excellent read. I will certainly be back." [link suppressed]
Add a comment...

I was asked on Twitter why Python uses 0-based indexing, with a link to a new (fascinating) post on the subject (http://exple.tive.org/blarg/2013/10/22/citation-needed/). I recall thinking about it a lot; ABC, one of Python's predecessors, used 1-based indexing, while C, the other big influence, used 0-based. My first few programming languages (Algol, Fortran, Pascal) used 1-based or variable-based. I think that one of the issues that helped me decide was slice notation.

Let's first look at use cases. Probably the most common use cases for slicing are "get the first n items" and "get the next n items starting at i" (the first is a special case of that for i == the first index). It would be nice if both of these could be expressed as without awkward +1 or -1 compensations.

Using 0-based indexing, half-open intervals, and suitable defaults (as Python ended up having), they are beautiful: a[:n] and a[i:i+n]; the former is long for a[0:n].

Using 1-based indexing, if you want a[:n] to mean the first n elements, you either have to use closed intervals or you can use a slice notation that uses start and length as the slice parameters. Using half-open intervals just isn't very elegant when combined with 1-based indexing. Using closed intervals, you'd have to write a[i:i+n-1] for the n items starting at i. So perhaps using the slice length would be more elegant with 1-based indexing? Then you could write a[i:n]. And this is in fact what ABC did -- it used a different notation so you could write a@i|n.(See http://homepages.cwi.nl/~steven/abc/qr.html#EXPRESSIONS.)

But how does the index:length convention work out for other use cases? TBH this is where my memory gets fuzzy, but I think I was swayed by the elegance of half-open intervals. Especially the invariant that when two slices are adjacent, the first slice's end index is the second slice's start index is just too beautiful to ignore. For example, suppose you split a string into three parts at indices i and j -- the parts would be a[:i], a[i:j], and a[j:].

So that's why Python uses 0-based indexing.
Commenting is disabled for this post.

Do not send me email like this:

"""
Hi Guido,
 
I came across your resume in a Google web search. You seem to have an awesome expertise on Python. I would be glad if you can reply my email and let me know your interest and availability.
 
………………………..
Our client immediately needs a PYTHON Developers at its location in *, NJ. Below are the job details. If interested and available, kindly fwd me your updated resume along with the expected rate and the availability.

[...]
"""

I might reply like this:

"""
I'm not interested and not available.
"""
Commenting is disabled for this post.

Post has attachment
Commenting is disabled for this post.

I am at my wits' end. In Office 2011 on the Mac, specifically Powerpoint, how do I turn off the automatic substitution of a smiley graphic when I type ":-)" ? I have turned off every single option under AutoCorrect and it still does this. :-(
Commenting is disabled for this post.

Bad user experience with Google wallet and Google apis console: getting monthly bills for $0.00. Worse user experience: being threatened with suspension of the account when the credit card expires.
Commenting is disabled for this post.

OH on python-dev: "This has come up before.  Classes have metaclasses (and _prepare_). Modules have loaders.  Poor, poor functions.  Because of the same concerns you've already expressed regarding the criticality of function performance, they miss out on all sorts of fun--inside their highly optimized box looking out at the other types showing off their cool new features all the time. It just isn't fair. :)"
Commenting is disabled for this post.
Wait while more posts are being loaded