Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104946
| 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 | 2016-03-15 18:34 +0100 |
| Organization | None |
| 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> |
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