You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be useful to be able to define a parameter signature which would coerce undef to the default value for the parameter. As an example, with a signature of
That does move the logic out of the caller, but it moves the setting of defaults for this parameter out of the signature and into the body of the subroutine.
If multiple parameters have defaults, specifying them in a single place makes for more understandable and maintainable code; I find that the signature is the natural place for them, as the boilerplate code required to initialize them outside of the signature detracts from the purpose of the subroutine. Having them in the signature provides both aesthetic and functional benefits.
There will always be oddball parameters requiring some sort of custom initialization which won't fit into the signature, but I think that passing undef is sufficiently common that it warrants specialized support in the signature.
It would be useful to be able to define a parameter signature which would coerce
undef
to the default value for the parameter. As an example, with a signature ofI currently have to check that the
cell_span
parameter is defined before passing it, otherwise I'll get a type error, which leads to things like this:If the bike-sheddable
undef_is_default
flag was set for thecell_span
parameter, then this would turn into:PerlX::Maybe
is an option, but I believe that the ability to conditionally coerceundef
to the default in the signature results in clearer code.The text was updated successfully, but these errors were encountered: