• ray10k (unregistered)

    Wow, that has to be the oldest "classic WTF" I've seen yet! Also, with this WTF being at least 11 years old now, I'm starting to feel old a little myself.

  • (nodebb)

    Yeah, quantum. I'm just so glad nobody thought maybe these are functions with a very restricted "domain" (set of inputs).

    They are really hexdigit2bin and hexdigit2int. And of course they return something weird on out-of-domain input. That's a bit WTF, but only a bit. (I'd assert or throw, but ...)

    They are more "er, ok, but..." rather than real WTFs.

  • OpiF (unregistered) in reply to Steve_The_Cynic

    Returning '2222' from hexdigit2bin is a wtf no matter how you look at it. I don't usually expect my binary strings to have random noise inserted for whatever reason.

  • (nodebb) in reply to OpiF

    "I'd assert or throw, but ..."

    And what exactly should it return if I pass "W" or "65"?

  • Keith (unregistered) in reply to Steve_The_Cynic

    FILE_NOT_FOUND obviously

  • beef (unregistered)

    Binary is base-2, so "2222" seems very appropriate. No WTF here at all...

  • siciac (unregistered) in reply to Steve_The_Cynic

    That's a bit WTF, but only a bit.

    Your inclination to throw an exception was entirely correct.

    This is burying the error. (The case of nulls is what Tony Hoare called his one billion dollar mistake.)

    You had an error condition and instead of raising it right away so it could be dealt with, you stored it somewhere in a data structure. That stack trace is gone, so solving the problem just got much, much harder.

    That data will get passed from component to component. It could be written into a file or stored in your database, possibly overwriting valid data with corrupted data.

    At some point, you'll have to debug it. That's when you'll spend hours and hours cursing "WTF did this come from?"

  • 🤷 (unregistered)

    "I've never seen code like this"

  • Decius (unregistered) in reply to OpiF

    If you don't expect your binary strings to have random noise, don't give this function hex strings with random noise.

    Making wrong output obviously wrong is important.

  • anonymous (unregistered) in reply to OpiF

    I don't expect my binaries to be passed around as strings. That is TRWTF.

  • Deuxis (unregistered) in reply to Decius

    This is called proper defensive programming. You expect that somewhere along the way due to a bug or input error a hex string with a wrong value may be passed. So in case that happens you throw/exit with error, so that the issue can be immediately noticed right where it occurred. Silently passing (intentionally) horribly wrong results further down the line is how you get the weirdest bugs.

  • (nodebb)

    I suspect the programmer didn't want to see the warnings in VisualStudio.NET that not every code path returns a value.

    (In C#, this would even be an error that would prevent compiling.)

    Returning something nonsensical instead of throwing an exception ist still a WTF.

    (I personally prefer to define a class UnexpectedAlternativeException)

Leave a comment on “Classic WTF: Quantum Computering”

Log In or post as a guest

Replying to comment #:

« Return to Article