<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Nov 17, 2013 at 1:05 PM, Maciej Fijalkowski <span dir="ltr"><<a href="mailto:fijall@gmail.com" target="_blank">fijall@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
My problem with -O and -OO is that their arguments are very circular.<br>
Indeed, I understand the need why you would want in certain and<br>
limited cases to remove both docstrings and asserts. So some options<br>
for doing so are ok. But a lot of arguments I see are along the lines<br>
of "don't use asserts because -O removes them". If the option was<br>
named --remove-asserts, noone would care, but people care since -O is<br>
documented as "do optimizations" and people *assume* this is what it<br>
does (makes code faster) and as unintended consequence removes<br>
asserts.<br clear="all"></blockquote><div><br></div><div>It's circular indeed (and not just the shape of the letter :-).<br><br></div><div>I expect that if there was a separate --remove-asserts option, people would write essential asserts and just claim "don't turn off asserts when using this code". But that's just wrong because such an option (whether named -O or --remove-asserts) is a global choice not under control of the author of the program.<br>

<br></div><div>The correct rule should be "don't use assert (the statement) to check for valid user input" and the stated reason should be that the assert statement was *designed* to be disabled globally, not to be a shorthand for "if not X: raise (mumble) Y". A corollary should also be that unittests should not use the assert statement; some frameworks sadly encourage the anti-pattern of using it in tests. (There are valid reasons to want to run unittests with -O or -OO: for example, to validate that the code does not depend on side effects of assert statements. If there was a --remove-asserts option, running unittests with that option would be similarly useful.)<br>

<br></div><div>That said I think our man page and --help output could be more forthcoming about this implication of "optimize". (The language reference is quite clear about it.)<br></div></div><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div></div>