Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84988 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87594 invoked from network); 16 Mar 2015 06:21:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2015 06:21:15 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.51 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.51 mail-pa0-f51.google.com Received: from [209.85.220.51] ([209.85.220.51:34396] helo=mail-pa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/F4-06614-B5676055 for ; Mon, 16 Mar 2015 01:21:15 -0500 Received: by pacwe9 with SMTP id we9so55372177pac.1 for ; Sun, 15 Mar 2015 23:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=x2kolgRRVCHEZg40hH1uL29kMVM/57Rj7OvBihHC6GQ=; b=xocLeCan66jrqdCHnIt4UAKXMF/oTCt/PPC/YB5ZRi+u362N4UtTVT/TXdpKY6N5hk QqCGAZz0sCTqj+YDPzQzFSTAjhm3+5ZazsI+kbEQvhBxrN/Eq5X1hvC7BuZt+Ob+KYn6 v8vp8WeqRyzuctdWdKRmd7ROvZ4cur0wnLPrHYEdXTXZUe14DEIczq3JCePyhmmngFU5 vnpTNPJcBlXHwJ/RQpImzTpNP12AJacJejiqwRB1AAT9fJwtR6xcvkBRSWfM4Zd7NA1p JVt186YEIWuGR4UiOKTMAPxWB+Zw0ucYk7vEyzyGYsmL5UYkfIV54ZZ1Gj022ITiYzok KcWw== X-Received: by 10.70.0.207 with SMTP id 15mr42061426pdg.56.1426486872381; Sun, 15 Mar 2015 23:21:12 -0700 (PDT) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id ae7sm15308284pac.19.2015.03.15.23.21.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2015 23:21:11 -0700 (PDT) Message-ID: <55067656.9080209@gmail.com> Date: Sun, 15 Mar 2015 23:21:10 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Eli , internals@lists.php.net References: <5504EF9D.1000707@gmail.com> <55064508.6050206@eliw.com> In-Reply-To: <55064508.6050206@eliw.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][PRE-VOTE] In Operator From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > But I'd like to know from your POV: Does this harm anything? Depends on what you see as "harm". Complicating the language is kind of harm. Introducing stuff that promotes patterns that are not always best, and that do a bit too much, and look too much like something in different languages that does something close, but not exactly that - is kind of harm. Both kinds are very small, more inconvenience than a serious problem, and can be easily compensated for by benefits of the feature, but given we already have all the benefits, I don't see much point. > I can now with this syntax, write code that directly matches the > cognitive process: > > if ($zebra in $zoo) {} Two things here: 1. If you're looking whether your zoo has a zebra, and you're doing it by inspecting every inch of your zoo and checking if it doesn't contain a zebra by any chance, you're running your zoo wrong. I hope this metaphor is clear :) 2. We don't talk to computers in natural language. For many reasons. So part of the cognitive process of any programmer is translating his thoughts into patterns that particular software (we rarely talk to hardware directly anymore) understands. From that POV, it doesn't matter too much how exactly bytes that you use to represent it are arranged, as long as they are not unnecessarily unwieldy. That, of course, is a matter of opinion, and my opinion is in_array is fine in that regard. > And the newer people to the language often get tripped up on exactly > these kinds of things. Lowering that cognitive barrier to translating > one's thought, to code. I feel is going to be a benefit here. Frankly, I don't see how that would help. Because with this operator, you'd have to tell them: 1. It's the same as in_array function, it goes through array and checks if the element is there. 2. But not exactly - in_array can do non-strict lookup, this one can't. 3. Oh, but instead it also works on strings. 4. Where it is like strstr except it doesn't tell you *where* the substring is. 5. And if you want to use it like Python's "in" you shouldn't because Python's works on keys while ours works on values. 6. And unlike many other languages you can't use it in a loop either. 7. And if you want to write an *efficient* lookup you shouldn't use this operator at all. I don't think it is a cognitive simplification. -- Stas Malyshev smalyshev@gmail.com