News for hackers. Stuff that matters.
Re:Get to No as fast as possible by emehrkay on Thursday June 17, 2010 @01:45PM (#1439715)
I much prefer one return per mehtod/func. Of course there are cases where that isn't possible, but I feel that if it were structured the right way, the code would be easier to read.

    func(){
        val = true
        resp = 'whatever'

        if(condition){
            resp = 'new'
        }

        return resp
    }
Re:Get to No as fast as possible by nihilocrat on Thursday June 17, 2010 @02:29PM (#1439899)
What do you do if in between if(condition) and return, there are a bunch of actions that modify state outside the function that, if condition is true, you'd never ever want to do?
Re:Get to No as fast as possible by emehrkay on Thursday June 17, 2010 @04:55PM (#1440310)
else ?
Re:Get to No as fast as possible by fleitz on Thursday June 17, 2010 @04:59PM (#1440325)
It's generally pretty easy to do if you write your code in a functional/tail recursive style. Instead of modifying your variables and returning, create new variables and pass them back into your function, in that way whatever you create will have to go back through all the sanity checks. Yes you can get infinite loops this way, but it alerts you to having coded your function incorrectly instead of returning the wrong data.

func(condition,resp){ val = true if(!condition){ return func(!condition,'new'); }) return resp } func(false,'whatever');