I love assert
ethan at stoneleaf.us
Fri Nov 14 19:18:27 CET 2014
-----BEGIN PGP SIGNED MESSAGE-----
On 11/14/2014 03:33 AM, Steven D'Aprano wrote:
> I agree with Marko in this case. Marko's example of defensive programming is very similar to the one I gave in my
> essay here:
> You're correct of course that under the circumstances you describe the code will fail. But that is no different
> from the scenario:
> "a new status is added, the code is not modified to handle it, no tests are written to check the code is correct
> (or if the tests are written, the test suite is not run), and then the code is released at which point it fails"
I am reminded of a Star Treck episode (Deep Space 9?) in which a Klingon is mocking the Federation tech for having
three backups, instead of only two, to which the Federation tech replies, "When the second one fails, I wouldn't want
to be without my tertiary backup!"
My point being: a safety net that is so easily disabled does not count (IMHO) as a backup.
> If your process is so poor that you release code without running it with asserts enabled, then assert will not save
> you from bugs.
This is one my very few complaints about Python: running it normally is the same as running with DEBUG turned on, so
the unusual case is remembering to run with asserts turned /off/.
> Assertions are just a tool, not a panacea.
Right -- and using it is like using a rock when what you need is a ball-peen hammer. ;)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
-----END PGP SIGNATURE-----
More information about the Python-list