How to Get Fired Using Switch Statements & Statement Expressions

TIL there are programmers who get paid to write code who find the example you posted to be so difficult to read that they get angry at the programmer who write it. And apparently, that's the majority of programmers.

For those that need help reading it: The original programmer hacked the switch/case statement into acting like a series of else ifs. The following sequence of Vim commands would transform it into an ordinary series of if/else if statements:

1,$!grep -v switch
1,$!grep -v '};'
s/case/if(/
1,$s/case/else if(/
1,$s/:/) {/
1,$s/break;/}

Result:

    if( (createAccountForm = forms.filter(createAccountForm), !!createAccountForm.length)) {
        createAccountFormFn(createAccountForm);
        processQueryString(createAccountForm);
        }
    else if( (addNewProperty = forms.filter(addNewProperty), !!addNewProperty.length)) {
        addNewPropertyFn(addNewProperty);
        processQueryString(addNewProperty);
        }
    else if( (!!templates.length && templates.is(contactUsFormTemplate))) {
        contactUsFn(forms);
        }
    else if( (!!templates.length && templates.is(loginFormTemplate))) {
        loginFn(forms);
        }

    else if( (!!templates.length && templates.is(forgotPassTemplate))) {
        forgotPassFn(forms);
        }

    else if( (!!templates.length && templates.is(GetSecurityQuestionTemplate))) {
        resetPasswordFn(forms);
        }

Now all you have to complain about is the use of multi-statement expressions.

/r/programming Thread Parent Link - blog.robertelder.org