Get boolean if boolean return boolean



  • Been lurking here for years. Found loads of WTFs, but usually just email them around work. Found one just now, and, thought I'd share with a wider audience:

    private function getEditability(selectedRoleEditable:Boolean):Boolean
    {
        if (selectedRoleEditable)
            return true;
    }

    There is more after the if, it can return a different value from the one you pass in, but still, I read that far and immediately thought "WTF?"



  •  What's the WTF then? It's editable if either the selected role is already know to be editable or some other conditions apply.



  • To me, the wtf is that if you already know the role is editable, there's not a lot of need to call a function to check if it's editable.

    I also forgot to mention that it was pure cruft, not called from anywhere, and so I deleted the function.

     



  • @nochange said:

    To me, the wtf is that if you already know the role is editable, there's not a lot of need to call a function to check if it's editable.

    I also forgot to mention that it was pure cruft, not called from anywhere, and so I deleted the function.

     

     

    You're lucky if this is the worst you're dealing with... I'm not saying it's not a WTF, but it could have been much, much worse. Where are uninitialized variables? Where's the eval()? Where are the tons of cryptic code without comments? Where's the condition that makes the function return something completely different than what you'd expect? Where are the tons of lines of code that could be replaced with only a couple? Where is the redundancy? Where's the passion?

    It's a good start, tho. Keep digging and I'm sure you'll be able to find more juicy stuff :-)



  • @nochange said:

    There is more after the if, it can return a different value from the one you pass in, but still, I read that far and immediately thought "WTF?"

    To me, the wtf is that if you already know the role is editable, there's not a lot of need to call a function to check if it's editable.

     

    There is if it can return a different value from the one you pass in, like you said in your first post. I'd much rather write code that just called this function, rather than "  if (selectedRoleEditable || (getEditability(selectedRoleEditable)))". 

    If thats not the case, then the real WTF is your post ;-)


  • :belt_onion:

    @Mole said:

    If thats not the case, then the real WTF is your post ;-)
    Hmmm... though crowd today. I'll think I'll post my WTF next week if the mood lightens :-)



  • If it can return a different value, then it's not immediately a WTF. I imagine it might grant "edit" rights even if the boolean flag says otherwise (e.g. if you're a superuser). With complex logic behind access control this might actually be the right way to do it. It's a bit weird that it takes a Boolean and not the actual Role, but other than that I wouldn't pick on it.


Log in to reply