Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(at': 0.03; 'operator': 0.03; 'case.': 0.05; 'python)': 0.05; 'false.': 0.07; 'matches': 0.07; 'subject:code': 0.07; 'ambiguity': 0.09; 'correct,': 0.09; 'moreover,': 0.09; 'worse': 0.09; 'cc:addr:python-list': 0.10; 'sat,': 0.15; '"and"': 0.16; 'distinction': 0.16; 'syntax.': 0.16; 'unimportant': 0.16; 'wrote:': 0.17; 'certainly': 0.17; 'comparing': 0.17; 'equivalent': 0.20; 'mostly': 0.20; 'assuming': 0.22; 'closely': 0.22; 'latter': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(e.g.': 0.27; 'guess': 0.27; 'first.': 0.27; 'instead.': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; '"in': 0.29; '(since': 0.29; 'comparison': 0.29; 'case,': 0.29; 'usually': 0.30; 'week.': 0.30; 'evaluation': 0.30; 'point,': 0.33; 'turns': 0.33; 'languages': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'faster': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'beyond': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'matter': 0.61; 'face': 0.61; 'first': 0.61; '30,': 0.62; 'thomas': 0.62; 'more': 0.63; 'choose': 0.65; 'advantages': 0.71; 'obvious': 0.71; 'day': 0.73; 'common,': 0.84; 'regard.': 0.84; 'refuse': 0.93; 'imagine': 0.96; 'hand,': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=j1kRLpwG3ANct/KMJSXZ5fuN9AYRGjtsAu9WwxNo/bg=; b=Cn1FZFIwCcYDDYbFkJsFR4KEk4Xlp5W3sQe7PznYM6u0AX/NtK5dY3KaoJNyVcUTd8 8+Tp9VQDyX0jDGzMwzFZ50qP2xHApuwekGBHAp7+BT6CjeBbzEw2JuET+F9YEkKyb7yc IUx1uz8PelYOw3EreqMtTulmQA6OTzpVZMEy5JaSoj5sacMaRFC+KhMzMj6qAZimp7RZ F8Gvncc7FS2ACU0gX/gXq/C+jtosKp0uzZ9DoUw9Snvvxyjmc9HEz38ghR2BjrIprP81 xp6eWu8aViKkQnR4ABtojBnKeBAjpJsE3kBRW7gL32Sh5XUG8I/gQU8tcpFd9p7yl7eI CJ/w== MIME-Version: 1.0 In-Reply-To: <4FEF66A3.9040805@jollybox.de> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <4FEF66A3.9040805@jollybox.de> From: Ian Kelly Date: Mon, 2 Jul 2012 13:16:26 -0600 Subject: Re: code review To: Thomas Jollans Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1341256624 news.xs4all.nl 6853 [2001:888:2000:d::a6]:57170 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24786 On Sat, Jun 30, 2012 at 2:50 PM, Thomas Jollans wrote: > Which of the two comparisons is done first anyway? > "In the face of ambiguity, refuse the temptation to guess." I would consider that a pro, not a con, because the C-like way is much worse in this regard. Using operator chaining, is "1 < 2 < 3" equivalent to: 1 < 2 and 2 < 3 # assuming left-to-right evaluation order for "and" 2 < 3 and 1 < 2 The former seems pretty obvious to me (since it more closely matches the original syntax) and also turns out to be correct, but more to the point, most of the time it really doesn't matter which is evaluated first. It's only relevant if: a) your comparison operator has side-effects (bad programmer! bad!); or b) one of the comparisons is significantly faster than the other -- but since usually both comparisons will be of the same type (e.g. both comparing two numbers), this is also a corner case. On the other hand, using the C-like interpretation, is "1 < 2 < 3" equivalent to: (1 < 2) < 3 1 < (2 < 3) I would guess the former is more common, but I really have no basis for that guess beyond some experience with languages that use this syntax. I can see no particular advantages to either interpretation and can certainly imagine that some languages might choose the latter instead. Moreover, the distinction actually matters in this case, because the first expression is true (at least in Python) while the second is false. I will take ambiguity that is mostly unimportant over ambiguity that is critical to the meaning of the expression any day of the week. Cheers, Ian