Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61225

Re: One liners

References <mailman.3674.1386374070.18130.python-list@python.org> <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com>
Date 2013-12-06 19:20 -0800
Subject Re: One liners
From Dan Stromberg <drsalists@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3695.1386386415.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Dec 6, 2013 at 6:07 PM, Steven D'Aprano <
steve+comp.lang.python@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

One liners Dan Stromberg <drsalists@gmail.com> - 2013-12-06 15:54 -0800
  Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 02:07 +0000
    Re: One liners Dan Stromberg <drsalists@gmail.com> - 2013-12-06 19:20 -0800
      Re: One liners Roy Smith <roy@panix.com> - 2013-12-06 22:53 -0500
      Re: One liners Steven D'Aprano <steve@pearwood.info> - 2013-12-10 03:36 +0000
    Re: One liners Neil Cerutti <neilc@norwich.edu> - 2013-12-09 13:49 +0000
    Re: One liners Chris Angelico <rosuav@gmail.com> - 2013-12-10 00:59 +1100

csiph-web