Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Something like it works for if...else...if...else too. To my horror, this was more readable and maintainable than any alternative I could imagine.

    switch(override){
    default:
        printf("unexpected...\n");
        // fallthrough
    case 0:
        if(z_bits&4 || N_flag){
    case 100:
            handle_100();
        }else if(x_bits & 0x80){
    case 200:
            handle_200();
        }else{
    case 500:
            handle_500();
        }
    }
It's cut down a bit for Hacker News. The original had about a dozen lines of code where each handle_XXX function now sits.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: