I love assert

Ethan Furman ethan at stoneleaf.us
Fri Nov 14 21:41:09 CET 2014


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

On 11/14/2014 11:12 AM, Marko Rauhamaa wrote:
> Ethan Furman wrote:
> 
>> My point being: a safety net that is so easily disabled does not count (IMHO) as a backup.
> 
> Correct. You never lean on assertions. They are primarily formal comments.

On this point we can agree.  :)


>> 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/.
> 
> I don't remember ever having optimized them out in any programming language. Has that really improved the 
> performance of your code?

In the handful of languages I have worked with so far, it's the other way 'round:  you un-optimize debug mode in.
CPython itself is a good example: when configuring, you must add --with-pydebug in order to get all the extra checks
added (which is great when adding new features), but that option isn't used when making production CPythons; yet
Python the language is just the opposite: debug mode is on /by default/, and to turn it off you have to specify -O:

$ ./python -c "print(__debug__)"
True

$ ./python -O -c "print(__debug__)"
False

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

iQIcBAEBAgAGBQJUZmjlAAoJENZ7D1rrH75N3wMP/j9AowuuEvW9khTFX512QUHn
VGwEqkIu4FDFRA8T+qzwqhL7st5GGsnXaPvaWCLmPGbtt1qrVxJ1M6LLkuSWI8Fj
/hGe5rcEPP88/tMA5zy/pmg6jDgl96hojCnDmmS6meIQijVRpxMUGQ/4+N1oKI5d
JYKOlhFStk0N5O6gyZ3Yc6UDY+I9kLVPZsIgH0bXx5IkvwQUi1aNboADehDgSbM5
XDCuZvfNsauKyJZL52NkKu6qLSY/CHDx4kaWdP/i75gZPeVJirjEUkcLYSK6iE19
DpkyeR5wetH1yppH27yyfZPCKHnaYD8O/rykRrQLaIYefKb7XhxGWXa4C17w+AQP
3+hjONiPBsXe2FZZNTskKufI88oXbFwTyI3GseeWTIbS+V9TIwGTjZA+V9jc6EvL
T6T9PRGwOzfPolcLZ43x3ea8uCzLhxe0BILEfdmv6XPoPl9sJ5wHhbxg0oblo8GL
GNkfOFw0ncxplyobU0RXhvsKCUg6EpAukWgIcX5IhHfnesoS1BpSMtZubAbY4GVI
AHzL34KpYhOIDo3Ws26dCtHz5ocJSnDlHv2lxv+iEEZV+4lShFEreqfCLK0hcJTP
QMFoI401Dy3bLd3wJX9mYQA+nMGhNtRK+4uYwGSbAinOGDKVuqrmNM7wCaF9lr/I
aC+wno9PzNxkDNy2nUpY
=gJhZ
-----END PGP SIGNATURE-----



More information about the Python-list mailing list