how to get the ordinal number in list

Chris Angelico rosuav at gmail.com
Mon Aug 11 07:06:36 EDT 2014


On Mon, Aug 11, 2014 at 8:46 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> The main thing is that the definitions must be clear. I must be able to
> look up the precise description quickly, and in fact, I always have the
> Python Library Reference in a browser tab or two because I have to
> review even familiar functionality over and over again. Less often, I
> also have to review the Python Language Reference.
>
> You don't have to like the = sign or the trailing comma of 1-tuples.
> What matters is that you know how to use them.

Fair enough. I'd say that there are two "main things", of nearly equal
importance: one is clear definitions, as you describe, and the other
is memorable definitions (so you don't have to keep going back to the
reference for every little thing). The consistency you describe as
your second priority is really part of memorability, because you can
learn one principle and have it work for everything. Contrast the PHP
standard library, where there's very little consistency in naming, so
you're constantly going back to the docs - see examples here [1] - I
can fully understand that switching from language to language will
have me doing this sort of thing (often with very good justification -
map() in Python takes func,iter,... but map() in Pike takes
iter,func,...; this is because Python's map() takes multiple
iterables, while Pike's takes exactly one iterable and will pass any
other args through to the function unchanged - which is consistent
with a lot of other Pike callback-calling functions), but within a
single language, it's more reasonable to expect consistency.

There are innumerable facets to the memorability of definitions,
though, and consistency's just one of them. The ELIZA effect factors
heavily in memorability; if you see "a + b" in code, you'll expect it
to be, in some way, adding a and b. If you know what HTTP means from
other places on the internet, you'll have some fairly strong
expectations about the functionality of BasicHTTPServer. If you've
worked with any of a huge bunch of languages, you'll not at all be
surprised that "asdf" is a string containing those four letters. And
that latter is true even though lots of languages have their
variations - biggest one being that Python 3's "asdf" is a string of
four Unicode codepoints, while C's "asdf" is a pointer to a buffer of
four bytes (plus the 0, so five really); it's still a string
containing four lowercase letters. And that's a Good Thing.

ChrisA

[1] http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/#standard-library



More information about the Python-list mailing list