lua-users home
lua-l archive

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



On April 7, 2023 2:38:14 AM EDT, bil til <biltil52@gmail.com> wrote:
>This shows the power of an interpreter language like Lua, which is
>free to evaluate variable types and variable interpretations during
>runtime.
>
>... such things make life harder for any "intellisense" editors like
>VS Studio - I agree... . Those allow flexible parameters only at the
>end of the parameter list, as it would also be common in compiled
>languages like C++... .

Are you sure?

So far as I'm aware, there is no particular advantage or disadvantage to overloading optional positional parameters in the middle (as opposed to the end) of the parameter-list, based on the number and/or type of the arguments, regardless of whether the language is statically or dynamically typed, compiled or interpreted.

One could easily create the equivalent of table.insert() in C++ with the optional insertion index as the middle parameter, between the required parameters.

The convention of placing optional parameters at the *end* of a positional parameter list is a stylistic one, as optional parameters in the middle of the list tend to be confusing and bug-prone.  Frankly, when there are more than a few parameters (especially optional ones), these days I prefer named parameters to positional.

-- David