Named arguments

  1. 4 months ago

    Marc

    Jun 20 User since 2018
    Edited 4 months ago by Marc

    When you have a method with optional parameters:

    func Test(a = 1, b = 2) {} 

    and you only want to provide argument "b", then you have to do this:

    Test( , "value for b")

    This looks a bit messy imho.

    In other languages I've always used named arguments, when available there, like this:

    Test(b: "only value b")

    Or:

    Test(b: "value b", a: "value a")

    NB: With named arguments, sequence doesn't matter.

    I personally find using named arguments, albeit more verbose (for some ...), gives better code readability and, as a bonus, is less prone to errors (if you f.e. use the wrong sequence).

  2. marco

    Jun 20 Administrator User since 2016

    Hi @Marc yes I agree and named arguments are already 3/4 implemented so you can expect that feature in the near future.

or Sign Up to reply!