Clarity vs. code reuse/generality

kj no.email at please.post
Sat Jul 4 12:30:10 EDT 2009


In <mailman.2611.1246721197.8015.python-list at python.org> "Pablo Torres N." <tn.pablo at gmail.com> writes:

>On Sat, Jul 4, 2009 at 10:05, kj<no.email at please.post> wrote:
>>>http://docs.python.org/reference/simple_stmts.html#grammar-token-assert_s=
>tmt
>>>"The current code generator emits no code for an assert statement when op=
>timization is requested at compile time."
>>
>> Sorry, this doesn't say anything like "don't use assertions to test
>> argument values". =C2=A0I'm aware of the fact that assertions are silence=
>d
>> under certain circumstances. =C2=A0But where does the principle 1. in
>> your first reply come from? =C2=A0I've never seen it before, and would
>> like to understand the reasoning behind it.
>>
>> kj
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>

>But...if no code is generated for assertions on some occasions, then the
>parameters would go unchecked, potentially breaking your code in said
>occasions.

This implies that code that uses *any* assert statement (other than
perhaps the trivial and meaningless ones like "assert True") is
liable to break, because whatever it is that these assert statements
are checking "on some occasions, ... would go unchecked, potentially
breaking your code."

I'm beginning to think that the original "precept" was simply "cargo
cult," i.e. one of those rules that are parroted without being
fully understood.

As I wrote in my original post, the function I posted was an internal
("helper") function, not to be used outside of the file.  This fact
was further (ahem) underscored by the leading underscore in the
function's name.  Under these circumstances, the assert statements
seem to me perfectly in keeping with the intended use for them. 

kj




More information about the Python-list mailing list