Skip to content

Instantly share code, notes, and snippets.

@rgrig
Created January 20, 2018 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgrig/e6cce9932cf02f460d35c2fc6403f7e5 to your computer and use it in GitHub Desktop.
Save rgrig/e6cce9932cf02f460d35c2fc6403f7e5 to your computer and use it in GitHub Desktop.

Questions: https://github.com/regehr/assert_quiz/blob/master/assert_quiz.md

  1. bad, should handle error sensibly
  2. bad, debug builds don't even alloc
  3. bad, should handle error sensibly
  4. ?, assert ok, but code around clearly bad: the hash_function has no idea what lenght is, and no modulo done after
  5. bad, should handle error sensibly
  6. kinda ok. You probably want a way to turn off expensive assertions, though. This way you can run prog with all asserts on small tests, and with cheap asserts on big tests (an with no asserts in release -- if you so fancy).
  7. bad, release build skips otherCode if 42
  8. bad, should handle error sensibly
  9. ok, but lack of {} is somewhat error prone. (Yes, I do it all the time.)
  10. bad, that's not even an assertion. assert(true)? come on
  11. blah, see tweets
  12. bad, should be a static assert
  13. bad, check your geometry
  14. bad, side effect
  15. ok, especially in hyperbolic geometries. euclid would probably request a stronger assert
  16. bad, side effect

that said, "handling errors sensibly" turns out to be very annoying, especially without exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment