index & value (was Re: inclusive-lower-bound, exclusive-upper-bound (was Re: Range Operation pre-PEP))

Alex Martelli aleaxit at yahoo.com
Tue May 15 04:05:55 EDT 2001


"Quinn Dunkan" <quinn at retch.ugcs.caltech.edu> wrote in message
news:slrn9g0v90.kg2.quinn at retch.ugcs.caltech.edu...
    ...
> Do methods that take an index and a value use the order 'index, value', or
> 'value, index'?  Standard eiffel is 'value, index', but standard python is
> 'index, value'.  I prefer python, but can't articulate why.

Well, if the argument that comes later is the one that can
be defaulted, I think the Python style is better -- you're
more likely to want to default the value than the index.

E.g.

    mydict.get(akey)

returning None if akey is not in mydict, with

    mydict.get(akey, 23)

returning 23 in that case.


If default-valued arguments are not allowed, there may
still be a small stylistic advantage to index-first in
consistency between different but 'similar' methods:
    acollection.getAt(index)
vs
    acollection.setAt(index, value)

I.e., there may be methods that ONLY accept the index
(so that having the index always first is consistent --
it's gotta be first if it's the only argument:-), more
likely than methods that only accept the value (not that
the latter case is impossible -- just less prevalent).


Alex






More information about the Python-list mailing list