On 05/03/2017 20:16, Ed Kellett wrote:
On Sun, 5 Mar 2017 at 19:54 David Mertz <me...@gnosis.cx
<mailto:me...@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


Patches are always welcome. If you insist that it's needed, you do the work. Hopefully it's easier with the move to github.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to