4 ms·
No, the flexibility on offer is that you get regular arguments, optional arguments, variable numbers of arguments and keyword/named arguments all as a result of
by arunix 5y ago
No, the flexibility on offer is that you get regular arguments, optional arguments, variable numbers of arguments and keyword/named arguments all as a result of this mechanism.
I hardly ever use shift like this, preferring instead the more readable argument copying:
sub PaintHouse {
my ($house, $color) = @_;
...
- motogpjimbo 5y agoI work in a legacy codebase (in PHP, not Perl) where the previous developer often wrote functions to be excessively flexible with regards to their parameters - many of the parameters are optional, some of them behave differently depending on whether they're passed as strings, integers or booleans, arrays can be passed as either flat or associative arrays, etc. I'm sure he thought he was making his functions easier to reuse in different contexts but in practice the actual result is that it's impossible to modify any of those functions without considering _every possible_ combination of parameters that could be passed in. Often what should be a simple fix becomes something much more time consuming. There is a place for flexibility in software design, but the parameter list of a function is not one of those places in my opinion.
- BrandoElFollito 5y agoI was inclined to do so on python and was reluctant to use a typed language. I tried Go and Typescript and realized that the extra code is really, really worth the security, refactorability and safety. I now frown on my beloved Python for being so permissive