Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
{
   if(a == "abs"){return void;}

   // function's code      
}

I could just place the function's code into its else, but I prefer this way because in my opinion, this is more legible. I just want to know if this is considered a bad practice or something like that.

Thanks!

like image 571
Marcelo Assis Avatar asked Dec 21 '22 14:12

Marcelo Assis


1 Answers

Nope. Not at all. It's often an important piece of control flow, in fact:

for x in someiterable:
    if somecondition:
        return somevalue
return None

This might come up if you were iterating over a sequence looking for something that satisfies a particular condition. If you find that something, you return it and prevent any further processing. If you never find it, you return a default value.

like image 167
Rafe Kettler Avatar answered Mar 23 '23 00:03

Rafe Kettler