lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


在 2016/3/26 15:43, Ulrich Schmidt 写道:

A simple way do make the function parameters more descriptive would be to allow a "?" in identifiers. for instance:

  function concatPath(drive?, folder?, filename);


I don't like the idea of making the leading parameters optional.

when I see a function signature such as

    function foo (optional_param1, optional_param2, required_param)

I can't figure out how am I supposed to call this functional without the optional parameters.

    foo(nil, nil, 'baz')
or  foo('baz')

or  foo(nil, 'bar', 'baz')
or  foo('bar', 'baz')

or is this valid?
    foo('bar', nil, 'baz')


the most intuitive way for me is make the trailing parameters optional.
or simply don't use positional parameters: use named parameters instead.

--
the nerdy Peng / 书呆彭 / Sent from Thunderbird