4 ms·
It sounds like you are unfamiliar with this style, not that it "isn't what anyone ordinarily means". Bash, Ruby, and Perl all support this style of argument pa
by bloblaw 5y ago
It sounds like you are unfamiliar with this style, not that it "isn't what anyone ordinarily means".
Bash, Ruby, and Perl all support this style of argument passing.
Perl does not have named formal parameters, but instead supports passing arguments as lists / arrays. You can pass any number of arguments of any supported type this way.
If you've never programmed in a language that supports passing arguments in this manner, it will seem foreign.
However, argument passing in this manner has many benefits (eg easy to extend a function def, can easily add optional / req params with basic checking within subroutine) and after 15 min of doing it this way you don't really think about it again.
- civilized 5y agoIt sounds like a subset of Python where "def fun(*args)" is your only option for a function signature. And you have to do all the work of pulling apart *args to get the data you want, including manually throwing errors if you didn't get what you expected. Python lets your function signature have required positional arguments, variable positional arguments (*args) AND variable keyword args (**kwargs). And everyone uses these features because it makes programming much more pleasant and manageable. **kwargs is especially important for complex packages like sklearn or pandas, which have many functions with lots of options that often change with version. It would be utterly unimaginable to build these magnificent packages while chained to the underpowered, antiquated Perl style of argument passing.
- bloblaw 5y ago> And you have to do all the work of pulling apart *args to get the data you want, including manually throwing errors if you didn't get what you expected. Respectfully, isn't this just the same amount of work to define named function arguments? In Perl you do the work of unpacking the array and then validating data. In Python you have the work of defining the function arguments and then validating the received data. > Python lets your function signature have required positional arguments, variable positional arguments (*args) AND variable keyword args (*kwargs). And everyone uses these features because it makes programming much more pleasant and manageable. Perl supports this as well. Same functionality as *kwargs is found by passing a hash to a subroutine. And of course *args is analogous to how Perl subroutines were designed to work.