Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80905 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89097 invoked from network); 20 Jan 2015 21:38:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 21:38:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wg0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:64931] helo=mail-wg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/F7-49046-0CACEB45 for ; Tue, 20 Jan 2015 16:38:08 -0500 Received: by mail-wg0-f41.google.com with SMTP id a1so15219782wgh.0 for ; Tue, 20 Jan 2015 13:38:05 -0800 (PST) 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=/FKV5AjylM8CO/OrpnCQqmzZGOei3VOaXr0JAFqP67c=; b=T0w2senXKabUH0d4Y+ehXLS3a9Mvezh5plB1VJqmhnOSF3LBxrul821mpZW6uQfQLw MAkJb222jgEvsJ8a0yZgynh7nmO7EPrtjRVDX5qV22ugLaLHr5VUH7j2B2rrRgw8IjaG 7TBeZ+vXdyiq6v+KutSWiVfwE3NLB5Cmt1VXt75woTi0SyGjFQM7tiSMacAvzl7KWEr6 02zjjp+hE4ksFihF27LQxJlZ192saR1KxChVN/ieTVig9SS+FyBHv5sS2uroYXvPW2z3 uKbZqStdyHaG0LrhmV5Ka5dwcMd1ZZawrHT7hAruot5N5/DSqyVIRFdXmYw4ewOL4Ny7 4q5A== X-Received: by 10.194.108.98 with SMTP id hj2mr76492326wjb.102.1421789885516; Tue, 20 Jan 2015 13:38:05 -0800 (PST) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id o16sm22877889wjw.7.2015.01.20.13.38.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jan 2015 13:38:04 -0800 (PST) Message-ID: <54BECAB8.7020907@gmail.com> Date: Tue, 20 Jan 2015 21:38:00 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: <52243BA6.5040905@sugarcrm.com> <54B6C047.3070301@mabe.berlin> <48223964-2F90-4386-BD8F-934791E45EB4@welsh.co.nz> <9F083B4E-B603-4A1D-9F1D-C758D835B450@ajf.me> <54BEB604.9000705@mabe.berlin> In-Reply-To: <54BEB604.9000705@mabe.berlin> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Skipping parameters take 2 From: rowan.collins@gmail.com (Rowan Collins) On 20/01/2015 20:09, Marc Bennewitz wrote: > > Am 19.01.2015 um 19:48 schrieb Adam Harvey: >> On 17 January 2015 at 18:04, Andrea Faulds wrote: >>> For consistency with list(), we could also just put nothing: >>> >>> >>> foo($bar, , $baz); >>> >>> Which is like: >>> >>> list($bar, , $baz) = $arr; >>> >>> Thoughts? >> That was Stas's original, original proposal way back when. I argued >> then for having "default" as a placeholder, and still would today — in >> the case where a function with, say, ten optional parameters[0] is >> being called and eight of them should be the default, I think it's a >> bit rough for somebody inheriting that code to have to count commas. >> Having a token increases readability, IMO, and costs us nothing except >> a few keystrokes, which isn't going to break the camel's back in a >> language that requires "function" each time you declare a function. >> >> Adam >> >> [0] Yes, that's probably poor API design. You and I both know someone >> will do it, though. :) > > Pros & Cons > > _Simply skipping the argument out:_ > pro: > - same syntax as skipping entries used by `list` > con: > - hard to read and to differ from mistakes > - not an option for inheritance > > _Using the keyword `default`:_ > pro: > - better to read and to differ from mistakes > - usable on inheritance > con: > - different syntax as `list` > - not possible as alternative syntax for `list` as it has no > "default" naming > > _Using a special character:_ > pro: > - better to read and to differ from mistakes > - usable on inheritance > - possibly an alternative syntax for `list` (for consistency) > con: > - different syntax as `list` > - Not a good character found for it, yet > > _Named Parameters:_ > pro: > - readability (If caller is not required to call as assoc array) > - not an option for inheritance > con: > - paramter skipping is a side product with possible edge cases > - Adds variable names to be part of the API > - implementation complexity > > In my opinion plain skipping parameters is a nice addition to PHP even > if named arguments will be introduced. > > A special character would indeed the best option but as long as there > is no good character it's not an option. Nice summary. My only difference of opinion would be that a special character, even if a good candidate were found, should be listed as "pros: better readability than simply skipping; cons: worse readability than a keyword". Punctuation is never going to be as intuitive as a well-chosen keyword for someone new to the feature. It certainly has advantages in applicability to multiple situations, though. The mention of for..in elsewhere made me wonder about a syntax for discarding the values of an array when looping over its keys; if _ were available as a default/skip token, you could write: foreach ( $foo as $key => _ ) { ... } That doesn't make sense with the "default" keyword, although a different keyword might fit multiple use cases, e.g. "skip": func_with_many_args(42, skip, skip, false); list($foo, skip, $bar) = $some_array; foreach ( $foo as $key => skip ) { ... } That actually reads quite well to me, but obviously requires reserving a new keyword, and breaking compatibility if any code has a constant named "skip". Regards, -- Rowan Collins [IMSoP]