thegooglecodearchive / sfepy

Automatically exported from code.google.com/p/sfepy
0 stars 0 forks source link

use of assert #58

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
As discussed in [1], using the 'assert' statement as a run-time check in a
production code is problematic, as asserts are removed by -OO option of python.

In SfePy, I propose to do the following:
1. asserts that are used for debugging can stay (it's their purpose)
2. asserts validating user input, sanity checks, bound checks should be
active even in the optimized code (-OO), and thus should be replaced by a
function (let's say assert_).

What do you think?

[1] http://www.mail-archive.com/numpy-discussion@scipy.org/msg12914.html

Original issue reported on code.google.com by robert.c...@gmail.com on 1 Oct 2008 at 10:47

GoogleCodeExporter commented 9 years ago
Well, I think that discussion is mainly about tests, no?

Original comment by ondrej.c...@gmail.com on 1 Oct 2008 at 11:25

GoogleCodeExporter commented 9 years ago
Yes, the discussion is about tests. But even the tests should work with -OO. 
And we
use asserts also outside tests to check values, e.g. in meshio.py. Those checks
should not be removed by any option.

Original comment by robert.c...@gmail.com on 1 Oct 2008 at 11:39

GoogleCodeExporter commented 9 years ago
> But even the tests should work with -OO.

I don't think so. nosetests and py.test use assert to do the tests. So it is a
defacto standard.

Original comment by ondrej.c...@gmail.com on 1 Oct 2008 at 11:54

GoogleCodeExporter commented 9 years ago
Actually, in files in tests/ directory is only a minority of asserts, so they 
can
stay until it causes problems.

Original comment by robert.c...@gmail.com on 1 Oct 2008 at 12:23

GoogleCodeExporter commented 9 years ago
I was in a mood of doing mindless repetitive tasks, so I introduced assert_().

Original comment by robert.c...@gmail.com on 2 Oct 2008 at 11:56

GoogleCodeExporter commented 9 years ago
Migrated to http://github.com/sfepy/sfepy/issues/62

Original comment by robert.c...@gmail.com on 30 Jan 2012 at 10:25