Live data from Hacker News

This should never happen

github.com

61–70 of 214 posts

Re: This should never happen

#61

Using github to search like this reminds me of how a CS professor of mine would show the "best commit messages of the year" (homework was submitted via git) by looking for various patterns like all caps, all symbols, etc. http://www.slideshare.net/bsotomay/uchicago-cmsc-23300-the-b...

It would have been funnier with context. Most of the references they're making are related to the assigned problems, I assume.

Re: This should never happen

#62
post #10

In 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

To be fair, someone writing a ThisShouldNeverHappenException may not be the kind of developer that knows about an IllegalStateException.

Re: This should never happen

#65

Using github to search like this reminds me of how a CS professor of mine would show the "best commit messages of the year" (homework was submitted via git) by looking for various patterns like all caps, all symbols, etc. http://www.slideshare.net/bsotomay/uchicago-cmsc-23300-the-b...

Hahaha, I went through the masters of comp sci program there. Those commits mentioning Borja cracked me up, and I swear "i love the smell of segfaults in the morning" was written on the wall in the big lecture room in the physical sciences building. Gives me flashbacks - that program was brutal (though really good).

Re: This should never happen

#66

Using github to search like this reminds me of how a CS professor of mine would show the "best commit messages of the year" (homework was submitted via git) by looking for various patterns like all caps, all symbols, etc. http://www.slideshare.net/bsotomay/uchicago-cmsc-23300-the-b...

http://www.commitlogsfromlastnight.com/

Re: This should never happen

#68

In 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

I found myself doing something similar to this in Java more than any other language.

Usually because some insane abstraction was built over a concept and some of the implementations could throw something like IOException and some could not but of course the API throws IOException as a checked exception.

Re: This should never happen

#69
post #10

Earlier quoted context omitted.

Mostly there is no need for "ThisShouldNeverHappenException" since java has a IllegalStateException

To be fair, someone writing a ThisShouldNeverHappenException may not be the kind of developer that knows about an IllegalStateException.

Actually they at least need to know about a RuntimeException then.

So that would've worked, too:

    throw new RuntimeException("This should never happen!");
There would've been a difference between a Exception and a RuntimeException.

Also sometimes this kind of RuntimeException happens when you convert one type into another and want to explictly call all cases something like that:

    interface A
    class AA implements A
    class AB implements A
    
    if (x instanceof AA) {}
    else if (x instanceof AB) {} 
    else { throw new IllegalStateException; } 
It's sometimes better to explicitly call all states instead of using the last else for the AB branch, since sometimes this will be extended later or the compiler would've throw an error since you have a return inside the if or else if. Btw. Kotlin and Scala won't have this problem due to pattern matching.

Re: This should never happen

#70
post #16

Earlier quoted context omitted.

Not just Java. I've seen similar classes in C++ and C# to indicate things which should never occur/are clearly bad programmer mistakes/... Think InternalErrorException/DevFailedError etc. Sometimes it's just a sane thing to do, and using such names means you don't need to write the dreaded 'should never happen' comment manually anymore.

Isn't that what assertions are for?

in Python, running with `-O`, from .pyo files, or equivalent settings in your webserver will all disable assertions. surprise!
Post reply on HN