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


Groups > comp.lang.python > #61225

Re: One liners

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'variables': 0.07; 'string': 0.09; 'appropriate.': 0.09; 'dan': 0.09; 'oop,': 0.09; "people's": 0.09; 'worse': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'language.': 0.14; 'cc:name:python list': 0.16; 'choice,': 0.16; 'clear.': 0.16; 'culturally': 0.16; 'fine.': 0.16; 'get,': 0.16; 'imo,': 0.16; 'names?': 0.16; 'nod.': 0.16; 'pythonic': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; '\xa0what': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'cc:addr:python.org': 0.22; 'beauty': 0.24; 'cc:2**0': 0.24; '&gt;': 0.26; 'long,': 0.26; 'nearly': 0.26; 'header:In-Reply-To:1': 0.27; 'dec': 0.30; 'direction': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'getting': 0.31; 'lines': 0.31; 'clever': 0.31; "d'aprano": 0.31; 'multiline': 0.31; 'perl': 0.31; 'steven': 0.31; 'anyone': 0.31; 'this.': 0.32; 'probably': 0.32; 'becomes': 0.33; 'fri,': 0.33; 'style': 0.33; 'could': 0.34; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done': 0.36; 'too': 0.37; 'turn': 0.37; 'being': 0.38; 'whatever': 0.38; 'pm,': 0.38; 'skip:& 20': 0.39; 'does': 0.39; 'bad': 0.39; 'even': 0.60; 'issues,': 0.61; "you're": 0.61; 'first': 0.61; 'more': 0.64; 'temporary': 0.65; 'beautiful': 0.68; 'subject:One': 0.74; 'complex,': 0.84; 'stretch': 0.91; 'from.': 0.93; 'imagine': 0.93; 'refuse': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=vZuJrNBEOC1cnL+NtpffeOVU+JFNTPkCcKyIEFnULJo=; b=cgVBq0WDXkEQ2hau3tEo0bL5ly+KUqB/BLQVX701sXKpoPSaT5/CAYSWYM1Tw+dunQ /CmWTMQ0FOWU4nkEAlC3mOpMFzUhs3XH9JRiHjtMuesCUORbC+J8f5DR9lP+AmY9AaNe n++szFGhnUmnKHbMIRlM6VWYL3ApiF+4GOOrPoBvB7/f8IAIkMlmOyO2vHUOEsriHq/8 IcxkjOyXC6LyqgOeZcO8N5kwfn5+3jEZkApaePS2KwVaxjGNNDiQOCBkdsRBTTv8d+1R Q4PRNGJCTLWiMx2Ii3asboVjOLjbczzK5YqoPB068RiICdeCHUA54RXnXziTmb7W0aXv ELgw==
MIME-Version 1.0
X-Received by 10.194.78.77 with SMTP id z13mr6154528wjw.27.1386386407511; Fri, 06 Dec 2013 19:20:07 -0800 (PST)
In-Reply-To <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com>
References <mailman.3674.1386374070.18130.python-list@python.org> <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com>
Date Fri, 6 Dec 2013 19:20:07 -0800
Subject Re: One liners
From Dan Stromberg <drsalists@gmail.com>
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Content-Type multipart/alternative; boundary=047d7bfcfc98575bc804ece93d75
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3695.1386386415.18130.python-list@python.org> (permalink)
Lines 152
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386386415 news.xs4all.nl 2829 [2001:888:2000:d::a6]:49618
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61225

Show key headers only | 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