<div dir="auto"><div>I've used Python for 20 years, and programming in general for about 40 now. I think almost EVERY large code base I've seen used asserts in their intended way. I frequently use them myself in a way differentiated (subtly) from 'if cond: raise SomeException'.</div><div dir="auto"><br></div><div dir="auto">I honestly don't know how Ivan has avoided seeing these. Giving up this useful construct would feel about the same as depreciating 'finally'. Yes, Python would be Turing complete without it, and you could work around it being missing... But why?!<br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">On Nov 27, 2017 11:12 PM, "Ivan Pozdeev via Python-ideas" <<a href="mailto:python-ideas@python.org">python-ideas@python.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">On 28.11.2017 8:59, Steven D'Aprano wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Nov 28, 2017 at 07:35:45AM +0300, Ivan Pozdeev via Python-ideas wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Actually, the way I'm using them,<br>
<br>
assert condition, "error message", type<br>
<br>
would probably be the most expressive way.<br>
</blockquote>
I disagree that is expressive -- I call it *misleading*. I see something<br>
which looks like an assertion (that is, a checked comment, a contract, a<br>
check on an internal piece of logic etc) but it is actually being used<br>
as a test.<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I can do anything in any Turing-complete language without any changes to<br>
the language. That's no reason to never change anything, is it.<br>
</blockquote>
"We can change this" is not a reason to change this. There needs to be a<br>
*good* reason to change, and you have given no good reasons for this<br>
change.<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The rationale basically is:<br>
* As it was intended, the statement has no practical use -- basically a<br>
rudiment, due to disappear eventually<br>
</blockquote>
Nonsense. I make extensive use of assert as a way of checking<br>
assertions, and I will fight tooth and nail against any proposal to<br>
either remove it or to misuse it for public input tests instead of<br>
assertions.<br>
</blockquote></div>
I invite you to show me a single use case for those "assertions" because after ~20 years of experience in coding (that included fairly large projects), I've yet to see one.<br>
<br>
Any, every check that you make at debug time either<br>
* belongs in production as well (all the more because it's harder to diagnose there), or<br>
* belongs in a test -- something coded independently from the program (if your code as a whole cannot be trusted, how any specific part of it can?), or<br>
* isn't needed at all because a fault will inevitably surface somewhere down the line (as some exception or an incorrect result that a test will catch).<br>
<br>
Finally, I've got much experience using existing code outside its original use cases, where the original author's assumptions may no longer hold but the specific logic can be gauded to produce the desired result. Coding these assumptions in would undermine that goal.<br>
<br>
So, I see "debug assertions" as either intentionally compromizing correctness for performance (a direct opposite of Python's design principles), or as an inferiour, faulty, half-measure rudiment from times when CI wasn't a thing (thus not something that should be taught and promoted as a best practice any longer).<div class="quoted-text"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
* It can instead be reused as syntax sugar to cover a very common use case<br>
</blockquote>
There is no need for such syntactic sugar. It would be harmful<br>
to use assert for something which is not an assertion.<br>
<br>
<br>
<br>
</blockquote>
<br>
-- <br></div>
Regards,<br>
Ivan<div class="elided-text"><br>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</div></blockquote></div><br></div></div></div>