I love assert

Ethan Furman ethan at stoneleaf.us
Fri Nov 14 19:18:27 CET 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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:
> 
> http://import-that.dreamwidth.org/676.html
> 
> 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.  ;)

- --
~Ethan~
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBAgAGBQJUZkdzAAoJENZ7D1rrH75Nl9YQALx9UIAxYzlzH04EoMlILErb
0wz5xNhTM2JmF3csJPi3pQSpEr1XpHhWjFZYsFoPB24I8bN7tGALb91+ME7ElHgw
WP6Z+AVPuHCRxTG/oteK72+f5S+SN6zV1ECwrUuWxqIt5CHzYFtQjRKvEinNDtaT
xKtEfYZdrZFeqo7ssV2gHprDd1QFIAygLMbIlwke6nT/TdMGmw/wG9LQtpfSnrQc
4BeFoeYM3OL+hxHUNfYJI9cGL7skykU3EHnuFqNbhA6QhGawvBqUhVDGoFFDkJ/e
AX6AGk5Fu9cvjEFTzRQJzW4S5s6nD4dYM7Z93GfD9G9KBmfzQNM1pBA3yqxf0S8Q
CWTWBs8pPkYe/G1Y/WOn7lzYQdMneIGUNnHR8fnABKPPf5IeTXabkWgtVnq1g5Ty
DVcg/47G8gBMOTz5DD08iigu4f2bsNGowFoAkCDsbNmzjmxODGSUoj1ph/4xg6HP
HbuEQZXwNZXmlP9ZcLoxjCKdBdRJo3JZ4hAf6kVj4VT4y438GL2dI0/KIUSDWgYE
B0mCsQ7WYm80AvfpYR7fJoZsd/5jXe7RCLHanNLIZff3LupdFZri5E246KloUBj+
3Jw3HgwME6wyDshiHtsS5tuDcANvow+PICA+wn2KmU9Mn2JNwsG3D98ZFJfXp0JR
eG/Pg7cgQhrjhFqe6cgO
=EoEX
-----END PGP SIGNATURE-----



More information about the Python-list mailing list