12
xorith
7y

int someFunc()
{
int result = -1;
// imagine all the fucking ifs in the world...
{
{
{
{
{
{
{
{
{
}
}
}
}
}
}
}
}
}
return result;
}

Comments
  • 5
    if (numIfs > 3) { return jobApplication; }
  • 5
    That's called advanced AI lol
  • 1
    I know this is a dumb question, but, how should it be formatted? I mean, I would rather that than a bunch of booleans that eventually go off screen
  • 1
    @SpencerBeige Well technically this would have indentation.

    To answer your question though, any code that starts to look like this is probably a candidate for refactoring. There's probably far too many concerns being addressed and they should probably be broken out into their own logic.

    Next, whenever I see code like this I often see where a number of conditionals could be checked at the same time and provide an early out for the code.

    Lastly, and the real punch-line of my rant, is the "return result;" and the fact that it's an integer. The idea of an integer result that has meaning isn't new and has a place, but it's on the programmer to keep things readable. I've seen 100+ line functions that operate like this where result is set to a value because a condition was met half way through the block. When debugging and I want to know why 'someFunc' returned 20 and not 0, I now have to dig through a ton of code.

    That was the point of the rant. :)
Add Comment