News for hackers. Stuff that matters.
Re:Tidy First? by dspillett on Thursday January 11, 2024 @05:47AM (#38950473)
> It still amazes me how they can believe that putting all the guards in tens of nested ifs can be saner than a few extra returns at the top.

If I have a function that needs a group of guards like that but local style guides demand a single exit point, I start a boolean like “AllHunkyDory” that gets set false where a return would be. Then you can keep the less nested structure and just wrap the main body in “if(AllHunkyDory){}”.

It is probably a touch less efficient, that variable is going to take up a register at least throughout the checks, but a fiunction with piles of guard clauses is hopefully not in a tight loop anyway so that is unlikely to matter.

Re:Tidy First? by aulin on Thursday January 11, 2024 @07:00AM (#38951089)
Sure, there are ways, less readable and more error prone. But that's not what you see where this rule is enforced. You see nested ifs.