[Python-ideas] The non-obvious nature of str.join (was Re: sum(...) limitation)

Stephen Hansen me+python at ixokai.io
Mon Aug 11 18:47:09 CEST 2014


On Mon, Aug 11, 2014 at 9:38 AM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:

>
> On Mon, Aug 11, 2014 at 12:21 PM, Stephen Hansen <me+python at ixokai.io>
> wrote:
>
>> Don't name variables 'x' and 'y'. If it were as simple as "x.split(sep)"
>> or "x.split('\t')" then I bet almost no one will need to consult the
>> documentation to know which is which
>
>
> Sure, but on the same token if someone writes sep.split(x), how likely
> will this error be caught on a quick review?  This is not theoretical.
>  I've seen people make this mistake and asking for help in debugging rather
> non-obvious behaviors.
>

I've seen people make innumerable mistakes in the past, I've seen certain
classes of mistakes repeated -- this isn't an argument for change by
itself. People make mistakes. Its going to happen.

That said, I find the idea that "x.split(sep)" as non-obvious to be...
weird, to say the least. But, obvious is subjective. Your obvious may not
be my obvious nor most people's obvious.

Yes, sep.join(list) is a bit of a weird construct, but its one thing to
learn, and its not a hard one to teach at that. In fact, it makes very
logical sense once you explain it and makes people think of things more
Pythonically after. I say from experience, not in theory. But,
string.split(sep) is very natural. You seem to think that they need to be
in the same order to be obvious but I don't see why nor do I think any of
the alternatives are not without problems that are bigger issues.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140811/e410cb2b/attachment.html>


More information about the Python-ideas mailing list