Live data from Hacker News

This should never happen

github.com

31–40 of 214 posts

Re: This should never happen

#31

GitHub's search is pretty interesting: every time I refresh the search page it shows a different number of results: 18,401,830; 17,751,631; 15,995,799. Which is anyways quite a lot of results, but then this search finds ThisShouldNeverHappenException , the string "this should never happen" and stuff like // *This* gets run before every test. if (b > d) { fail("XX *should never happen*"); } With quotations it's only a…

HyperLogLog[1] will do that. You can find it in Redis, Lucene; and I suspect it is also hidden behind BigQuery's count(distinct X)s.

[1] https://en.wikipedia.org/wiki/HyperLogLog

Re: This should never happen

#33

GitHub's search is pretty interesting: every time I refresh the search page it shows a different number of results: 18,401,830; 17,751,631; 15,995,799. Which is anyways quite a lot of results, but then this search finds ThisShouldNeverHappenException , the string "this should never happen" and stuff like // *This* gets run before every test. if (b > d) { fail("XX *should never happen*"); } With quotations it's only a…

Trying a quoted "should never happen" yields a bit over 3,000,000 results. Trying a quoted "never happen" yields over 5,000,000 results.

Re: This should never happen

#34
One of the most common causes of failures are cases that the programmer never considered. Once of my favorite test coverage tools shows you missed branches and I find that invaluable.

My initial reaction was "oh no" but as I thought about it, this explicitly indicates that the programmer actually thought about a case.

And is it any different than what most of us do in our unit tests? If we're expecting an exception that isn't thrown or the wrong exception is thrown, we force a test failure.

One of the goals our team is working towards is more robust and complete metric and log collection. We specifically want to capture exceptions that make it to the application server for analysis, but this assumes that the developer has a) considered all cases and b) caught intermediate exceptions and continued processing (or abort).

Re: This should never happen

#37
post #16

My 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...

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.

In C#, I tend to use the built-in InvalidOperationException class -

https://msdn.microsoft.com/en-us/library/system.invalidopera...

Re: This should never happen

#38
I usually annotate should-never-happen asserts by the most plausible explanation how it _could_ happen, for the sake of some poor guy unlucky enough for having to debug my code.

E.g. "Should not happen — probably a bug in Apache Commons Math?"

Or "Shouldn't really happen, barring compiler bugs or cosmic rays"

As they told us, there is no such thing as probability of zero.

Re: This should never happen

#39

Earlier quoted context omitted.

I remind myself frequently not to swear in code as I am quite juvenile on a normal day. If I'm struggling I'll just make up a word, so that if it ever happens that someone else sees it I can say it is an acronym but that I have conveniently forgotten for what.

You could always put a "this should never happen" right before the swear words so they know it wasn't your fault.

But there's a risk I'll become stuck in an infinite loop of writing shit! this should never happen shit! this should never happen shit! ...

and so on. Still it would be a change from writing bad code.

Post reply on HN