In many of my models, at some moment I have included a procedure assert to check that the state of the system is according to expectations.
Could this become a primitive of NetLogo, similar to assert in most other languages?
Some languages permit two variants, one with an error message and one without.
My preference for NetLogo would be the default without error message.
The other one – if present at all – would need parentheses then.
I know @SteveRailsback has done a lot of thinking about ways to confirm the validity of NetLogo models. I would love to hear his thoughts on this. We could add something like this to the language, but if you already have achieved this with a procedure in NetLogo code, it would be a great candidate for the upcoming module system!
Yes, we have a journal manuscript in review on ways to test NetLogo
code. In preparing it, I came to the conclusions that:
(a) Yes NetLogo lacks code reliability tools that most general languages
have, such as “assert” statements, stepwise debuggers, and unit testers; but
(b) It is easy to write the equivalent in NetLogo code, just as you did
with your assert procedure. Another example is that instead of a
debugger breakpoint in the code, you can just use “inspect self” and
“user-message” to pause execution and show you what’s going on.
Because NetLogo code is often more complex than it might look (it’s very
easy to write a short statement that uses turtle, patch, and global
variables plus variables of some other turtle that might be selected
randomly) it is hard to design generic testing tools that are easy to
use. Just writing defensive programming and test code yourself might not
be more work than using such tools if they existed.
To me, the main need is to get users to understand the need for code
testing–that just because NetLogo code is easy to write doesn’t mean
it’s correct. That’s the main need that our journal article addresses
and I’m glad to see other people working on it.