[Python-ideas] get() method for list and tuples

Ed Kellett edk141 at gmail.com
Sun Mar 5 15:16:12 EST 2017


On Sun, 5 Mar 2017 at 19:54 David Mertz <mertz at gnosis.cx> wrote:

> In terms of an actual use case, I can see it for "Lists no longer than 4".
>

That's an excessively hard limit.


> Any other use of this hypothetical method would be an anti-pattern
>

What really is the point of this? You (not uniquely) have been quick to
dismiss any uses for this as misguided. If you must do that, you might
stick to the reasons; meaningless labels don't add anything.


> Yes, programmers can do what they want, but providing a method is a hint
> to users (especially beginners, but not only) that that is the "right way"
> to do it.
>
>
> I really think that depends what it's a list of. If the positions of
> things in the list are important (as with an argument parser, or perhaps a
> lookup table) I fail to see why it would be wrong to peek.
>
>
> But the positions NEVER are important when you get to a 20 item list.  If
> you design an argument parser that is looking for "the 17th argument" you
> are doing it wrong.  I'm not saying that's impossible (nor even hard) to
> program, but it's not good practice.
>

That's probably true of argument parsers, certainly not lookup tables.


> Sure, I'm happy to take 20+ arguments, especially if they result from a
> glob pattern used at the command line, naming files.  But when I'm doing
> that, I want to deal with those filenames in a loop, handling each one as
> necessary.  In that pattern, I *never* want exactly 20 arguments, but
> rather "however many things there are to handle."
>
>
> If lists were really designed to be used only as you and some others in
> this thread are suggesting, I don't think they'd have indexed access at all.
>
>
> Actually, when I teach I make a big point of telling students (for me,
> professional scientists and programmers who have used other PLs) that if
> they are indexing a list they should look again and question whether that's
> the right pattern.  Of course there are times when it's needed, but they
> are fewer than C, Java, or Fortran programmers think.
>

I don't think that assessment applies neatly everywhere. Indexing is
generally unnecessary when it's being used instead of iteration, but this
thread is explicitly about cases where iteration isn't wanted.

Ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170305/aaf00ea8/attachment.html>


More information about the Python-ideas mailing list