Infosys strikes again



  • One of the iOS applications I support at work contains a nice little method whose sole responsibility is to create and display an alert.  It's short and clean and serves a single purpose, taking no parameters and returning void:

     

        - (void)showFooAlertView
        {
            // Setup and display code
            ...
            ...
        }

     

    Today one of the offshore devs submits a pull request and changes the method to this:

        - (BOOL)showFooAlertView:(BOOL)shouldShowAlertView
        {
            BOOL shouldShow = NO;

            if (shouldShowAlertView)
            {
                // Setup and display code
                ...
                ...

                shouldShow = YES;
            }

            return shouldShow;
        }

     

    That's right.  Now you can call a method with a single clear purpose and at the same time tell it not to perform its single clear purpose, and as a bonus it will even tell you what you told it to do.  I was naturally curious as to the value added by this modification.  When I asked I was informed that this was done to "increase readability" and "make the method understandable to everyone".



  • @Smitty said:

    I was informed that this was done to "increase readability" and "make the method understandable to everyone"

    Mission accomplished, then, because I understand it and I've just had to read it three or four times to make that true.

    I didn't have to read the old version anywhere near as many times to achieve the same end, so it must have had lower readability.



  • To be honest, it does do a conversion to BOOL as well. If you manage to somehow pass it something like @"YES", NULL or -3.14, it will still return just YES or NO. That's so wonderful.



  • Not only that, but if you pass it something that evaluates to false, it won't do anything but that conversion. This gives the coder the flexibility to re-use this code for a much wider range of tasks than that envisioned by the impoverished design it replaces. It's win-win!



  • Wait a minute — what sort of alert are we talking about, that has no parameters of any kind?



  • @Daniel Beardsmore said:

    Wait a minute — what sort of alert are we talking about, that has no parameters of any kind?
    A FooAlert, obviously. I buttume that all the information needed to show the alert is implied by the type of alert; therefore, no parameters are needed.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.