It's considered a bad pratice use return to end a function?

后端 未结 5 1158
忘了有多久
忘了有多久 2021-01-19 10:46

I\'m a PHP and ActionScript developer, and in some of my functions I use return to end it. Example:

private function lolsome(a:String):void
{
           


        
5条回答
  •  抹茶落季
    2021-01-19 11:23

    For further interesting reading look up "multiple vs single return" on Google. Much heat there. The alternative is generally to hold your return in state, and only return it once, at the end. Personally I'd rather dump out asap rather than risk some state being modified further down the line; smaller more focussed methods help stop that happening.

    I'd say your practice here is fine.

提交回复
热议问题