On Fri, May 20, 2011 at 12:27 PM, Masklinn <span dir="ltr"><<a href="mailto:masklinn@masklinn.net">masklinn@masklinn.net</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
</div>Absolutely, but the mutation of the default parameters seems to be the main<br>
problem (historically): it's a memory leak, and it's a global data corruption,<br>
where modifying a provided parameter is a local data corruption (unless the<br>
object passed in is global of course).<br><br></blockquote><div><br></div>Agreed, but that wasn't how I interpreted Jack's question. I think there are two issues (with the first one the one that I think Jack was targeting):</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">(1) I want to make sure a parameter is immutable so I don't accidentally change it (and none of the functions I call can do that). Akin to declaring a parameter const in C-like languages. For example, <font class="Apple-style-span" face="'courier new', monospace">is_ip_blocked(ip_address, blocked_ip_list)</font>. (That's not just <font class="Apple-style-span" face="'courier new', monospace">ip_address in blocked_ip_list</font> if the list contains CIDR addresses.) We could add code to make the values immutable or use annotations:</div>
<div class="gmail_quote"><br></div><div class="gmail_quote"><font class="Apple-style-span" face="'courier new', monospace"> @const</font></div><div class="gmail_quote"><font class="Apple-style-span" face="'courier new', monospace"> def func(x : const, y : const = []):</font></div>
<div class="gmail_quote"><font class="Apple-style-span" face="'courier new', monospace"> pass</font></div><div class="gmail_quote"><br></div><div class="gmail_quote">Personally, I like declaring the contract that a parameter is not being modified explicitly and I would like a shallow freeze() function.</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">(2) The gotcha that the default value is the same value every time rather than a new value. Lot's of ways to deal with this but none of them work without educating people how the feature works. For example:</div>
<div class="gmail_quote"><br></div><div class="gmail_quote"><font class="Apple-style-span" face="'courier new', monospace"> @copy</font></div><div class="gmail_quote"><font class="Apple-style-span" face="'courier new', monospace"> def func(x : copy, y : copy = []):</font></div>
<div class="gmail_quote"><font class="Apple-style-span" face="'courier new', monospace"> pass</font></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br clear="all">--- Bruce<div><div>Latest blog post: <a href="http://www.vroospeak.com/" target="_blank">http://www.vroospeak.com</a> Your social security number is a very poor password</div>
</div><div>Learn how to hack web apps: <a href="http://j.mp/gruyere-security">http://j.mp/gruyere-security</a></div><br><div> </div></div>