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: References: <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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104946 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") ;)