One liners

Dan Stromberg drsalists at gmail.com
Fri Dec 6 22:20:07 EST 2013


On Fri, Dec 6, 2013 at 6:07 PM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> On Fri, 06 Dec 2013 15:54:22 -0800, Dan Stromberg wrote:
>
> > Does anyone else feel like Python is being dragged too far in the
> > direction of long, complex, multiline one-liners?  Or avoiding temporary
> > variables with descriptive names?  Or using regex's for everything under
> > the sun?
>
> All those things are stylistic issues, not language issues. Yes, I see
> far too many people trying to squeeze three lines of code into one, but
> that's their choice, not the language leading them that way.
>

Yes, stylistic, or even "cultural".


> I refuse to apologise
> for writing the one-liner:
>
> result = [func(item) for item in sequence]
>
> instead of four:
>
> result = []
> for i in range(len(sequence)):
>     item = sequence[i]
>     result.append(func(item))
>
IMO, this is a time when the one liner is more clear.  But if you start
trying to stretch that to extremes, it becomes worse instead of better.

>
> > What happened to using classes?  What happened to the beautiful emphasis
> > on readability?  What happened to debuggability (which is always harder
> > than writing things in the first place)?  And what happened to string
> > methods?
>
> What about string methods?
>
A lot of things people do with regex's, could be done with string methods
more clearly and concisely.

The beauty of Python is that it is a multi-paradigm language. You can
> write imperative, procedural, functional, OOP, or pipelining style (and
> probably more). The bad thing about Python is that if you're reading
> other people's code you *need* to be familiar with all those styles.
>

That's fine.  That's appropriate.   But I imagine any of these can be done
with the intention of being more clever than clear.

BTW, what's pipelining style?  Like bash?

> I'm pleased to see Python getting more popular, but it feels like a lot
> of newcomers are trying their best to turn Python into Perl or
> something, culturally speaking.

They're probably writing code using the idioms they are used to from
> whatever language they have come from. Newcomers nearly always do this.
> The more newcomers you get, the less Pythonic the code you're going to
> see from them.
>

Nod.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20131206/ff86e5cd/attachment.html>


More information about the Python-list mailing list