News for hackers. Stuff that matters.
Re:What are the crawling horrors of PHP? by RyanMcGreal on Tuesday July 13, 2010 @08:01AM (#1511059)
There's plenty to hate about PHP, but most of my gripes have been repeated ad nauseam all over the internet. Yet one issue that really drives me bonkers doesn't seem to have received the opprobrium it deserves: Functions can take default named arguments, but insist on referencing named arguments by order, not name. This is just utterly asinine.
Re:What are the crawling horrors of PHP? by eli on Tuesday July 13, 2010 @08:39AM (#1511128)
Yeah, that really does stink. Once you get more than 2 or 3 parameters, it's tempting to just pass a $config hash instead.
Re:What are the crawling horrors of PHP? by nuclear_eclipse on Tuesday July 13, 2010 @08:23AM (#1511092)
That's because PHP is heavily influenced by C and Perl, both of which exhibit the same behavior.
Re:What are the crawling horrors of PHP? by RyanMcGreal on Tuesday July 13, 2010 @08:35AM (#1511120)
What's the point of named arguments if you can't do something like the following (e.g. Python)?

    >>> def some_func(a=1, b=2, c=3):
        return (a + b) * c

    >>> val1 = some_func()
    >>> val1
    9
    >>> val2 = some_func(b=3)
    >>> val2
    12
    >>> val3 = some_func(c=5)
    >>> val3
    15
    >>>
Re:What are the crawling horrors of PHP? by nuclear_eclipse on Tuesday July 13, 2010 @08:39AM (#1511127)
I completely agree with you, and I much prefer Python's method of handling it. I was at explaining why PHP acts the way it does.
Re:What are the crawling horrors of PHP? by RyanMcGreal on Tuesday July 13, 2010 @09:33AM (#1511257)
Yes, of course. I wasn't holding you responsible. :)
Re:What are the crawling horrors of PHP? by phaylon on Tuesday July 13, 2010 @02:11PM (#1512232)
Raw core Perl doesn't have named arguments. You can pass in a list of key/value pairs and the function can simply pull those in a hash, but you don't need to have them in the right order for that.

I don't know all libraries on CPAN that implement some kind of function signature or argument validation, but I can't remember seeing one that requires ordered named arguments.