Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Useless expressions [was Re: Undefined behaviour in C] Date: Mon, 28 Mar 2016 12:38:19 +1100 Lines: 36 Message-ID: References: <56f02196$0$1588$c3e8da3$5496439d@news.astraweb.com> <56f42d9f$0$1618$c3e8da3$5496439d@news.astraweb.com> <56f55e2e$0$1619$c3e8da3$5496439d@news.astraweb.com> <87wpoq1omm.fsf@elektro.pacujo.net> <56f5f81d$0$1585$c3e8da3$5496439d@news.astraweb.com> <87io0a6j1w.fsf@nightsong.com> <56f67ee3$0$1583$c3e8da3$5496439d@news.astraweb.com> <87poug5t0c.fsf@nightsong.com> <56f887c1$0$1598$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de 4HQ3MhLJVZgONPQSneryWQ4orikvYLSbjv7tXLdmZtiQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'warnings': 0.03; 'compiler': 0.05; 'discard': 0.05; 'strings.': 0.07; 'cc:addr:python-list': 0.09; 'okay': 0.09; 'languages.': 0.15; 'subsequent': 0.15; '2016': 0.16; 'buggy': 0.16; "compiler's": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imo,': 0.16; 'maintainer': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:expressions': 0.16; 'wrote:': 0.16; 'result,': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'not.': 0.27; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'looks': 0.29; 'node': 0.29; 'style.': 0.29; 'subject: [': 0.29; 'objects': 0.29; 'that.': 0.30; 'code': 0.30; "i'd": 0.31; 'probably': 0.31; "can't": 0.32; 'table': 0.32; 'functional': 0.32; "d'aprano": 0.33; 'instead,': 0.33; 'steven': 0.33; 'though.': 0.33; 'received:google.com': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209.85.213': 0.37; 'things': 0.38; 'received:209': 0.38; 'anything': 0.38; 'still': 0.40; 'mar': 0.65; 'cast': 0.66; 'legal': 0.66; 'chrisa': 0.84; 'dsl': 0.84; 'to:none': 0.91; 'drops': 0.91; 'poorly': 0.93 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:cc; bh=zuHziUWNybWwmJy+GviUd/osPF0FQLxK3UUFDmmcy7U=; b=uFwCusoVqFKK3btDELIR4QInPdQ6Nl9qWb6WMaNEdy16CSUx0+CXJ8ecUo/iEQq8+G aaJa8HcvpnF5T/ZpVQr3HvTH1fKd1ClKlXaWech7ctWQPekvOBQ1QfJyGUCaKD0rLTWE Sq7Y4t4+a7yDHkpEqw64x1FQ/aQlefGHnD2geH9RLHXjpTlJE4NPjl3+6ZkM8PC2ouyH JkuHLm80PWebMYIWsDWw6E9XXmMsEpWadpbSJQ2XWotjmrYKUTe4ZxNO/iCzSLfzqEqm ffWvaEbtBS81OgvnTQR+DRIx9Hnrw2BIFI914y51BH1UXmzNonE8pn4ER4LpzzC/ogah SaZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=zuHziUWNybWwmJy+GviUd/osPF0FQLxK3UUFDmmcy7U=; b=G79152S3wzKYuMnAYiFn7E71efKUBHV6cW3sTJwf/vKzNwYTTN6XvRBid4DrSmHVKi FW0bD4HNKEOB4vB1/tEOfmOeBKopk2FgJOvtH9lJG6K52YBFcOlOhsTE4x2E7lkweDeb DYoszPfiS6wUyxYRL0/egUgp7GQYJMakVsc65x83iBU1iHbkCoHtYhprvBao5IQcSTMs nprh1twWrgmGJv7uPNG74zDEMPtI9ecPp1UM+vsnCLamzijcY1+7Blx0er6Z+7wn5q/i Y3P0VzTOulM3ekZJS1Rutukf8kVvTDZrSFlXhXSOyVV0eK1jd7Z5ctR5sN1insejpZt6 rSvQ== X-Gm-Message-State: AD7BkJJK5PCz+yrD8C0+tAG7qUjRTxpU8IKIcikPx7f3gRAS2DaN18aEnokXyxVj0GoLZBKtMh5QkAAXL71ufA== X-Received: by 10.50.138.233 with SMTP id qt9mr7241615igb.13.1459129099161; Sun, 27 Mar 2016 18:38:19 -0700 (PDT) In-Reply-To: <56f887c1$0$1598$c3e8da3$5496439d@news.astraweb.com> 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:105891 On Mon, Mar 28, 2016 at 12:24 PM, Steven D'Aprano wrote: >> >> f() # Probably OK >> g() # Probably OK >> f()+g() # Probably not OK > > You don't and can't know what's "probably not" okay unless you know what > type of object both f and g return. > > Don't think about floats and ints and strings. Think of complex objects with > operator overloading. You're probably thinking of `x + y`. Instead, think > of things like: > > graph + node > database + table > > in a procedural style instead of a functional style. With operator > overloading, we have the ability to write domain-specific little languages. I would still look askance at code that adds two things and drops the result, though. The compiler can't discard it, but if a linter complains, I'd support that. A DSL that requires you to do this is, imo, poorly designed. It'll make every subsequent maintainer wonder if the code is buggy or not. But it's still... > ... not the compiler's job to cast value judgements on what is good or > likely style, it must accept anything legal. If you want something to make > value judgements about style, or get warnings about what looks like legal > code but might be an error, then you should use a linter like PyChecker, > Pylint, Jedi or similar. That's not the compiler's job. Exactly. ChrisA