Live data from Hacker News

This should never happen

github.com

51–60 of 214 posts

Re: This should never happen

#51

Earlier quoted context omitted.

Never ever EVER put bad language in any unexpected error cases or logs - even as you're developing it... it WILL somehow magically make its way to production, and it WILL appear!

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.

I had a hearthy chuckle when learning about Android's Log class: the highest level of importance for a message is WTF. Documented as What a Terrible Failure.

Re: This should never happen

#55

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

This is amazing.

amazing waste of time that is, of everybody, the commit authors and the people spending time looking them up and making slides out of them. And lets not forget the waste of space on HN regarding this referral post.

Re: This should never happen

#57
Sometimes you have to satisfy the compiler because it has less information about a situation than you do. Ideally this would be captured in the type system, but limitations (language, project, politics, time, etc) may prevent this. As another comment mentions, it's a kind of invariant check.

For example, based on external information you might know[1] that a condition inside of a loop will always be hit exactly one time. Your compiler or tools might not be able to determine that same thing. It may try to force you to do something like assign a value or whatever you did in that condition, that it can't guarantee has happened. In such a scenario, it might[2] make sense to have something like "this should never happen" after the loop, with a brief comment explaining why you've done this.

[1] I think this is the crux of the issue. We programmers often think we "know" something, but it might be an incorrect assumption. IMO part of being a good programmer is examining your assumptions at every step. The chasm is vast, between "the framework strongly guarantees X" and "the function that gets called before this one has done X already". The former is OK if you want to get work done, while the latter is much more brittle and possibly dangerous, depending on the level of coupling you're willing to accept.

[2] Nine times out of ten, a reorganization of the logic makes more sense. However, I do think there are scenarios where this pattern is the best choice given the options.

Re: This should never happen

#59

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://whatthecommit.com/
Post reply on HN