|
|
|
|
|
by archargelod
572 days ago
|
|
I don't understand, what's wrong with assert and doAssert? They are both enabled in release AND debug modes.
You would have to explicitly compile code with -d:danger flag to disable any assertions. > And they didn't even name the safe version clearly! In this context safe version is clearly named as "release" mode, and unsafe one is even more clear - "danger" mode. "danger" obviously implies it should be used with caution. |
|
1. There's no semantic different between `assert` and `doAssert`. Does `assert` not "do" the assert? Of course it does. The names are meant to communicate what the functions do, and these fail. It should be called `assert` and `always_assert` or something....
2. Except that it shouldn't because the "obvious" one to use (`assert`) should be the safest. People don't always read the manual (including you) and they sometimes make mistakes (yes, including you), so the default actions should be safe. Danger should be opt-in, not opt-out-if-you-happen-to-know-you-have-to.
That's why it's `assert`/`debug_assert` not `release_assert`/`assert`.
There are a couple of famous examples where they got it completely wrong: Python's YAML library has `load` and `load_safe`. MySQL has `escape` and `real_escape`. There's probably more.