Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80999 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76850 invoked from network); 22 Jan 2015 22:48:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Jan 2015 22:48:17 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.27 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.27 out3-smtp.messagingengine.com Received: from [66.111.4.27] ([66.111.4.27:46991] helo=out3-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0E/23-61273-D2E71C45 for ; Thu, 22 Jan 2015 17:48:14 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B1BFC21162 for ; Thu, 22 Jan 2015 17:48:11 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Thu, 22 Jan 2015 17:48:11 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:message-id:date:from :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=lWQ1X5wUvck1/5FjzNJB5P +HX9I=; b=JstaGlM3uqozL00Q5sgnmQ5YfqL0azuH2Eluf9RlQbJN4M/6cAaNZc baQEtheG0dOX28FqaFeDeTdZAkfUECRK/twd4u5v2mtVmQO60t5OS94wuHwaO16E NrqlwpadSHnnhHP49f0iy9tkPxlqu/EngNQAp5aQw/zS1YO6BZ5jI= X-Sasl-enc: ln5t042eibeonu0g+oFS2aP8vkMLViDLkSfN+RpdkTTF 1421966891 Received: from [192.168.42.117] (unknown [98.226.241.18]) by mail.messagingengine.com (Postfix) with ESMTPA id 72E75680192 for ; Thu, 22 Jan 2015 17:48:11 -0500 (EST) Message-ID: <54C17E2B.80708@garfieldtech.com> Date: Thu, 22 Jan 2015 16:48:11 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: <53F8A1FF-C809-4DDF-9C6F-6916C3E4F044@ajf.me> <3251D635-D97C-4738-B537-935A6CC21E19@ajf.me> In-Reply-To: <3251D635-D97C-4738-B537-935A6CC21E19@ajf.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Combined Comparison (Spaceship) Operator From: larry@garfieldtech.com (Larry Garfield) On 01/19/2015 08:29 AM, Andrea Faulds wrote: > Hey Nikita, > >> On 19 Jan 2015, at 14:07, Nikita Popov wrote: >> >> I like the idea behind this (exposing internal compare_function), but I don't want to have an extra operator for a minor use case. Please just introduce a function instead. > I originally wanted a function, but an operator has some advantages. There’s no backwards-compatibility issues from function name conflicts (nor do we have to break with tradition and use a namespace despite everything else not having one). The syntax is similar to other comparisons: we don’t have lt(), gt(), lt_or_eq(), gt_or_eq(), eq() and not_eq(), we have <, >, <=, >=, == and !=. Why, then, should we have cmp() or compare()? We get to fix one of C’s mistakes here, in that C (unlike FORTRAN of all things) failed to provide a three-way comparison operation despite it being useful and often available natively. <=> has a certain brevity and is familiar to Ruby and Perl users. > > Plus, it looks cool and has a cool name (not really an argument, I know). > > Still, there is a case for a function, but I’m trying for an operator for now. I quite like how this feature makes multi-item comparisons much simpler. > > -- > Andrea Faulds > http://ajf.me/ This looks potentially quite useful, especially for multi-stage comparisons as you note. Mainly it would mean I don't have to remember which direction is positive or negative, as I can never get that right without looking it up. :-) The examples say nothing about mixing types, though. Eg, what would these return: return 0 <=> "0" return "" <=> 0 return 1 <=> [1, 2, 3] Ignoring object property names and going by the order of the property definition seems like asking for trouble, too. There may be easy logical answers to the above given PHP's existing type juggling, but they should be called out explicitly in both the RFC and in any subsequent documentation. --Larry Garfield