Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104946
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. |
| Date | Tue, 15 Mar 2016 18:34:48 +0100 |
| Organization | None |
| Lines | 93 |
| Message-ID | <mailman.164.1458063313.12893.python-list@python.org> (permalink) |
| References | <fcd34352-44d2-4912-b76c-7b3860c4fe1e@googlegroups.com> <b5cae758-d246-4fdb-b5ce-0961d9d409c6@googlegroups.com> <mailman.156.1458030609.12893.python-list@python.org> <18e54ae4-0471-4c3f-842c-da67eedeff02@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de FGHLXE7BdqsY6Ex+NgfuTA5LfxwdWzKK4QvOtQidbLoA== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'modify': 0.04; 'expressions': 0.07; 'familiarity': 0.07; 'assumed': 0.09; 'beginners': 0.09; 'contexts': 0.09; 'expression:': 0.09; 'likewise': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'recommends': 0.09; 'statements': 0.09; 'bug': 0.10; 'url:blog': 0.10; 'python': 0.10; '"this': 0.13; 'value.': 0.15; "'this": 0.16; '2016': 0.16; 'attributes:': 0.16; 'basic.': 0.16; 'convey': 0.16; 'crammed': 0.16; 'grasp': 0.16; 'guilty': 0.16; 'partly': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'syntactic': 0.16; 'wrote:': 0.16; 'example.': 0.18; '>>>': 0.20; 'versions': 0.20; 'fix': 0.21; '(the': 0.22; 'saying': 0.22; 'beauty': 0.22; 'minor': 0.22; 'referring': 0.22; 'programming': 0.22; 'code.': 0.23; '(or': 0.23; '(like': 0.23; '(you': 0.23; "python's": 0.23; 'second': 0.24; 'thus': 0.24; 'sort': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'distribute': 0.27; 'helpful': 0.27; 'function': 0.28; 'clever': 0.29; 'prints': 0.29; 'print': 0.30; '15,': 0.30; 'compared': 0.30; 'programmers': 0.30; 'probably': 0.31; 'another': 0.32; 'getting': 0.33; 'problem': 0.33; 'usually': 0.33; 'point,': 0.33; 'charged': 0.35; 'but': 0.36; 'too': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; '(and': 0.36; 'basic': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'beyond': 0.37; 'wanted': 0.37; 'things': 0.38; 'difference': 0.38; 'version': 0.38; 'anything': 0.38; 'someone': 0.38; 'sure': 0.39; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'received:de': 0.40; 'some': 0.40; 'questions': 0.40; 'software': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'default': 0.61; 'eye': 0.61; 'impact': 0.61; 'yes': 0.62; 'course': 0.62; 'more': 0.63; 'march': 0.64; 'world': 0.64; 'between': 0.65; 'elsewhere': 0.66; 'readers': 0.66; 'cultural': 0.76; '"most': 0.84; 'not)': 0.84; 'otten': 0.84; 'subject:Sets': 0.84; 'terrible': 0.84; 'universally': 0.84; 'url:2016': 0.84; 'utc+5:30,': 0.84; 'subject:Lists': 0.91; 'serious': 0.97 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd9927.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| 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> |
| Xref | csiph.com comp.lang.python:104946 |
Show key headers only | View raw
Rustom Mody wrote:
> On Tuesday, March 15, 2016 at 2:00:25 PM UTC+5:30, Peter Otten wrote:
>> Rustom Mody wrote:
>>
>> > Others have answered some parts
>> >>>> if x in x_list:
>> > ... print("That is a fruit.")
>> > ... else:
>> > ... print("That is not a fruit.")
>> > ...
>> >
>> > However one can distribute the print out of the if; Thus
>> >
>> >>>> "This is %s a fruit" % ("" if x in x_list else "not")
>>
>> Which of the two versions will most readers grasp at first sight?
>> Which one is easier to modify so that it works for arbitrary attributes?
>> Which one is easier to internationalize?
>
> I think you are saying that my (last) version is clever in a rather stupid
> sort of way. Yes?
Well, yes ;)
> Well if that is what someone recommends for serious programming then
> guilty as charged
>
> But there is a world of difference between
> - What one SHOULD (or not) do
> - What one CAN do
>
> The first is about serious|professional software engineering
> The second is about getting an education beyond basic to some more
> familiarity
>
> I assumed that OP is in the noob stage and was welcome some learning.
> So what I wanted to convey is not so much that such expressions are nice
> to have in serious code. Rather that
> 1. Like algebra has laws so does programming
> 2. That these laws can be used to massage one program into another
> 3. That expressions (like %-format) can occur elsewhere than in prints
That (the % part) is a lesson for C programmers rather than newbies ;)
> 4. That prints are usually unnecessary (and an abomination)
They aren't. They are often misused by beginners when they occur where a
function should return a value.
> Not that 3 and 4 come out so well as 1,2 in the above example.
>
> However to answer your questions specifically.
>
> Internationalization: Terrible
> Arbitrary attributes: not sure what you are referring to
> Readability: Very much like beauty -- in the eye of the beholder
> Some things are universally beautiful; some only in some cultural contexts
> Likewise readability
>
> Partly people find if-expressions unreadable because they are not used to
> them.
> This is backward because expressions are as basic than statements -- if
> anything more basic.
I think the problem is not that you prefer a programming paradigm that is
not Python's default -- it's that you crammed too many ideas into one
example. It's probably most helpful to concentrate on your main point, e. g.
(You can) Use an expression:
>>> x = "flying saucer"
>>> "This is a fruit" if x in x_list else "This is not a fruit"
'This is not a fruit'
> It is *symmetric* Unfortunately understood as lopsided
> More such symmetries in this table:
> http://blog.languager.org/2016/01/primacy.html#expstat
>
> Partly python if-expressions are unreadable because they are backward
> compared to if-statements. A minor syntactic nuisance but yes it does
> impact readability
Indeed. It's still better than
"This is %s a fruit" % (x in x_list and "" or "not")
The bug is intentional; the fix is of course
"This is %s a fruit" % (x in x_list and "most likely" or "probably not")
;)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Use of Lists, Tupples, or Sets in IF statement. jj0gen0info@gmail.com - 2016-03-14 17:26 -0700
Re: Use of Lists, Tupples, or Sets in IF statement. Joel Goldstick <joel.goldstick@gmail.com> - 2016-03-14 20:31 -0400
Re: Use of Lists, Tupples, or Sets in IF statement. Chris Angelico <rosuav@gmail.com> - 2016-03-15 11:33 +1100
Re: Use of Lists, Tupples, or Sets in IF statement. Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 00:38 +0000
Re: Use of Lists, Tupples, or Sets in IF statement. jj0gen0info@gmail.com - 2016-03-14 18:32 -0700
Re: Use of Lists, Tupples, or Sets in IF statement. jj0gen0info@gmail.com - 2016-03-14 18:24 -0700
Re: Use of Lists, Tupples, or Sets in IF statement. Steven D'Aprano <steve@pearwood.info> - 2016-03-15 13:10 +1100
Re: Use of Lists, Tupples, or Sets in IF statement. Rustom Mody <rustompmody@gmail.com> - 2016-03-14 23:30 -0700
Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Peter Otten <__peter__@web.de> - 2016-03-15 09:29 +0100
Re: Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Rustom Mody <rustompmody@gmail.com> - 2016-03-15 04:08 -0700
Re: Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Peter Otten <__peter__@web.de> - 2016-03-15 18:34 +0100
Re: Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement. Rustom Mody <rustompmody@gmail.com> - 2016-03-15 19:54 -0700
csiph-web