Re: [RFC] Skipping parameters take 2
| From: | Marc Bennewitz | Date: | Tue, 20 Jan 2015 20:09:40 +0000 |
| Subject: | Re: [RFC] Skipping parameters take 2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80894@lists.php.net to get a copy of this message | ||
Am 19.01.2015 um 19:48 schrieb Adam Harvey:
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 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_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 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.
@Stas: Any news on using default on inheritance ?
Marc