• (disco)

    The Frist ... The Last ...

    https://www.youtube.com/watch?v=Fcd3XuQwDQQ

  • (disco)

    I sort of understand:

    public DataModel getEditionModel() {
       if ( true )
           throw new IllegalArgumentException( "You shouldn't be here" );
       return editionModel;
    }
    

    It's a stub for functionality that never got implemented...probably in context editionModel is not well formed/implemented yet either.

  • (disco)

    Of course, countDocuments() does just that. It counts the documents. One by one, just like if you were counting documents.

    'Course, I don't actually see any point in doing that to find out how many documents there are.

    Unless it's a bit like the conditional branch instructions on the 6809. It had the usual combinations of assorted CPU flags set or clear (Zero set/clear, Carry set/clear, Sign set/clear, Overflow set/clear, etc.), but it also had two more branch instructions: BRA (no sniggers in the back of the class) and BRN, respectively BRanch Always and BRanch Never. Looking at the opcode byte values showed that branch-if-set and branch-if-clear for some condition differed by one bit (the same bit for all pairs), as did BRA and BRN. In effect, the 6809 had no unconditional branch instruction at all. All the pairs were "branch if some condition is true" and "branch if that condition is false". For the eighth pair of branch instructions (BRA and BRN), the condition was just "true".

    Maybe this is just one of a series of conditional document counters, and in this one the condition is "true", and whoever wrote it was too afraid of the fucknuttery of a PHB to do it right. Or maybe it was built by the PHB itself.

  • (disco)
    function countDocuments() {
        var count = 0;
    
        for ( var i = 0; i < user.documents.length; i++) {
            count++;
        }
    
        return count;
    }
    

    WTFTFY

    function countDocuments() {
        var count = 0;
    	try {
    		for ( var i = 0; i < Int32.MaxValue; i++) {
    			var q = user.documents[i];
    			count++;
    		}
    	} catch (Exception) {}
        return count;
    }
    
  • (disco) in reply to accalia
    accalia:
    count = 0
    We're still wondering why it is always assumed an array must have at least zero elements. Is it that uncommon for it to be a null reference? :wink: And what about the imaginary elements? document -1 is a good read I hear...
  • (disco) in reply to Tsaukpaetra
    Tsaukpaetra:
    Is it that uncommon for it to be a null reference?

    i have no idea. but my WTF version will happily report 0 documents when the user is null (or documents is)

    in fact it will report whatever number it's happened to count up to ANY TIME an exception is thrown in the loop.

    :laughing:

    like i said i WTFified that for us.

  • (disco)

    Might not be a bad idea for the Classic WTF articles to link to the old comments instead. :laughing:

  • (disco)

    Timo's version (the getEditionModel() one) is completely valid if it's an override of a virtual method, on a subclass where the operation in question doesn't make sense.

    Otherwise, it's definitely a WTF.

  • (disco) in reply to Tsaukpaetra

    I like that. 0 is an assumption. Maybe the correct number is a fraction, or ... why not make the assumption NaN or a Schrödinger Kat. It's imaginary is nothing, is everyting, is fantastic until we actually count them, one by one!

  • (disco) in reply to tdwtf

    That's precisely the problem. How do you count something one-by-one if you don't know if it uses a particular zero-indexed scheme? Certain languages allow you to arbitrarily use integers and keys under the same syntax. For example: user.documents["First"] could very well be the same as: user.documents[0] And we're not even going to start talking about pointer math! :stuck_out_tongue_winking_eye: ;P

  • (disco) in reply to Tsaukpaetra
    Tsaukpaetra:
    Certain languages allow you to arbitrarily use integers and keys under the same syntax

    this is indeed true, however the attribute index on documents does hint at a traditional array layout, does it not? :-)

  • (disco) in reply to Tsaukpaetra

    In C#, does that not just link to the .Item() method, where the .Item(string) overload goes by field name, and the .Item(int) overload goes by index?

  • (disco) in reply to chubertdev

    Sounds about right. I know PHP does it, but I'm not as sure about Javascript and whatnot. 'Tis why I made no specific reference.

  • (disco) in reply to Mason_Wheeler
    Mason_Wheeler:
    Timo's version (the getEditionModel() one) is completely valid if it's an override of a virtual method, on a subclass where the operation in question doesn't make sense.

    Otherwise, it's definitely a WTF.

    Okay then, what's the `if (true)` and `return editionModel` doing there? You could just throw the exception and be done with it.
  • (disco) in reply to JBert

    Yeah, the if (true) is a bit silly. The return, if I had to guess, is probably there to silence a compiler that doesn't know enough about flow analysis to realize that this is not a "missing return value" problem.

    ...maybe.

  • (disco) in reply to Mason_Wheeler

    I think the if (true) is there for the same reason. Maybe it was something like this:

    public DataModel getEditionModel() {
        // TODO
    }
    

    and then when that didn't compile

    public DataModel getEditionModel() {
        return editionModel;
    }
    

    but wait - we aren't ready to expose that functionality yet

    public DataModel getEditionModel() {
        throw new IllegalArgumentException( "You shouldn't be here" );
        return editionModel;
    }
    

    oops, that doesn't compile either!

    public DataModel getEditionModel() {
        if (true)
            throw new IllegalArgumentException( "You shouldn't be here" );
        return editionModel;
    }
    

    perfect

  • (disco)

    For extra fun, trim a space or two from the timestamp length and see what happens. Particularly if you have source control that ignores whitespace changes.

  • (disco) in reply to Scarlet_Manuka
    Scarlet_Manuka:
    For extra fun, trim a space or two from the timestamp length and see what happens. Particularly if you have source control that ignores whitespace changes.
    TRWTF would be source control that ignores whitespace changes inside string literals.
  • (disco)
    [image]

    Really? Also no SidebarWTF.

  • Allan Mills (unregistered)

    I think in many cases this kind of coding can be summarized by the old adage "When all you have is a hammer, every problem looks like a nail".

Leave a comment on “Classic WTF - Sweet Mysteries of Life”

Log In or post as a guest

Replying to comment #:

« Return to Article