Re: [RFC] Skipping parameters take 2
| From: | Rowan Collins | Date: | Tue, 20 Jan 2015 21:38:00 +0000 |
| Subject: | Re: [RFC] Skipping parameters take 2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80905@lists.php.net to get a copy of this message | ||
On 20/01/2015 20:09, Marc Bennewitz wrote:
Am 19.01.2015 um 19:48 schrieb Adam Harvey: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]On 17 January 2015 at 18:04, Andrea Faulds <ajf@ajf.me> wrote:Pros & Cons _Simply skipping the argument out:_ pro:For consistency with list(), we could also just put nothing: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. :)foo($bar, , $baz);Which is like:list($bar, , $baz) = $arr;Thoughts?- same syntax as skipping entries used bycon:list- hard to read and to differ from mistakes - not an option for inheritance_Using the keyworddefault:_ pro:- better to read and to differ from mistakes - usable on inheritancecon:- different syntax as_Using a special character:_ pro:list- not possible as alternative syntax forlistas it has no "default" naming- better to read and to differ from mistakes - usable on inheritance - possibly an alternative syntax forcon:list(for consistency)- different syntax as_Named Parameters:_ pro:list- Not a good character found for it, yet- readability (If caller is not required to call as assoc array) - not an option for inheritancecon:- paramter skipping is a side product with possible edge cases - Adds variable names to be part of the API - implementation complexityIn 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.