This should never happen
github.com
This should never happen
1–10 of 214 posts
Re: This should never happen
#2Apparently things-that-shouldn't-happen happen 10x more in C code than the next nearest language.
Re: This should never happen
#3assert(false);
Re: This should never happen
#4if happens:
print "shit, that wasn't supposed to happen"
Re: This should never happen
#5My favorite part is the Java project that has an exception class called ThisShouldNeverHappenException [1]. Only in Java would someone create an exception class for a condition that should never happen :)
[1] https://github.com/TheProjecter/propidle/blob/f0d5320e2a3d46...
Re: This should never happen
#6Apparently things-that-shouldn't-happen happen 10x more in C code than the next nearest language.
I didn't even notice that. Good observation. I wonder if that's simply because C is a lot older and may just have a lot more dead code or this type of code or something else entirely.
Re: This should never happen
#7Re: This should never happen
#8In my experience, "this should never happen" cases often are a sign of very brittle design that branches into many separate but nearly-identical paths, and could be simplified to remove them. The other thing it points to is bad error handling paths (assuming that an error could "never happen".)
Also funny to see Java being the most verbose as usual, with its ThisShouldNeverHappenException.java
Re: This should never happen
#9I remember using the comment "Craw! Polly shouldn't be!" instead, as a homage to a specific Simpsons episode. :)
Re: This should never happen
#10In my experience, "this should never happen" cases often are a sign of very brittle design that branches into many separate but nearly-identical paths, and could be simplified to remove them. The other thing it points to is bad error handling paths (assuming that an error could "never happen".) Also funny to see Java being the most verbose as usual, with its ThisShouldNeverHappenException.java
Mostly there is no need for "ThisShouldNeverHappenException" since java has a IllegalStateException