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

The code block in question might be something that doesn't really deserve a whole function on its own, and could also involve local control-flow statements (return/continue/break/etc.) that can't really be outsourced to a function nicely. For example, you're parsing a line from a flat file and you want to assign a value to a certain variable based on the first word on the line. So you have a few dozen/a hundred lines of

if ( key == "hitpoints" ) {player.hitpoints = value; return;}

if ( key == "mana" ) {player.mana = value; return;}

Those "return"s make it rather awkward to use a function. At best, said function would have to return a bool and you'd end up with something like

if ( maybe_assign( key, "hitpoints", &player.mana ) ) return;

which hardly gains you anything and in fact reduces readability a fair amount.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: