Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't understand why pretty much no language does that these days. I think the argument is that your IDE should do this, and it does in some cases, but still...


You can get a much more powerful alternative for "free" if you support de-structuring assignments (in arguments).

JavaScript Example:

    function test({a,b,c}) {
        console.log(c,b,a)
    };
    
    test({
        a: 1,
        b: 2,
        c: 3
    });
If you have this there's really no need for named arguments anymore. If you add features to your de-structuring, your "named arguments" will have them too (things missing for JS specifically: optional objects, TS support to specify types for the destructured objects inline instead of repeating the entire thing).


It is not more powerful. You cannot do this for example:

    function hello($name='Joe',$title='dear')
    {
        echo "Hello $title $name";
    }
    hello('Sue');
Try here: https://3v4l.org/6MZHh

With your object properties approach, you always have to use the variable "names".


Mixing implicit positional and named parameters is a misfeature. The named parameters should have a distinct syntax like other systems do, e.g. :$ twigil.


Python, Kotlin and C# all support named arguments, and they're pretty popular languages. And also... there's Visual Basic.


I guess you can add dart and maybe ruby and elixir if you accept that they treated as a map/keyword list on the receiving end of the function.

Edit: Ruby apparently made them first class citizens back in 2014. Ive been oblivious to this for years... wow.


Crystal supports named arguments.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: