3 ms·
Thanks for this writeup. By "what is your proposed solution?" I meant to ask "how would you change the language semantics to remove this 'idiotic' footgun", no
by davidatbu 5y ago
Thanks for this writeup.
By "what is your proposed solution?" I meant to ask "how would you change the language semantics to remove this 'idiotic' footgun", not "how would you work around this footgun?" I apologize for the ambiguity.
I initially thought this specific footgun was an unavoidable consequence in languages that primarily pass around references (like Python and Javascript). But it turns out that Javascript's default arguments do "make a special case exception for when the expression that constitutes a function default is evaluated!"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters#evaluated_at_call_time https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...