Lots of Assertion in facebook/src/com/facebook/internal/WorkQueue.java
Dear author,
Thank you for developing this nice SDK. I am trying to be more involved in using the code so I start to read it. In the file facebook/src/com/facebook/internal/WorkQueue.java
I saw lots of places with 'assert', which from my best knowledge, is not really a good practice.
It breaks the code path, and may have different behaviors when assert is turned off.
So I am wondering why you use it and why not changing it into a couple of if / throw. Thanks.
Si
Hi Si,
According to the Java language guides for asserts (http://docs.oracle.com/javase/7/docs/technotes/guides/language/assert.html), there are two situations where you should not use assertions:
- Do not use assertions for argument checking in public methods.
- Do not use assertions to do any work that your application requires for correct operation.
The WorkQueue class fits neither of them since it's not a public class, and all the assertions are checking for preconditions and do not have any side effects. Also, in practice, assertions are never turned on in production environments, so they would not trigger except when explicitly turned on during testing or debugging.
If they were public methods, then we would have used the if/throw pattern.
Thanks for your questions,
Ming
Thanks for this detailed comment.
Si