Did he think that poor use of pratis comes back to end the function?

I am a developer of PHP and ActionScript, 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 code } 

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

Thanks!

+4
source share
5 answers

I would only consider this as bad practice if you have returned functions in complex complex functions, because itโ€™s even harder for someone to understand the algorithm when viewing it. However, bad practice is to have large, long functions (they usually should be divided into several smaller functions).

In general, I would consider checking the parameters and the state at the beginning of the function and just go back to good practice, not even quite normal.

But be careful not to clog a function with several different return values โ€‹โ€‹in the main logic.

+4
source

Nope. It's my pleasure. This is often an important element of the control flow, in fact:

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

This can happen if you repeat a sequence that is looking for something that satisfies a certain condition. If you find something, you will return it and prevent further processing. If you never find it, you will return the default value.

+5
source

I would not consider this a bad practice. It is widely used.

+1
source

For further interesting reading, check out โ€œmultiple vs single returnโ€ on Google. There is a lot of heat. An alternative is usually to keep your return in a condition and only return it once, at the end. Personally, I would prefer to abandon attacks instead of risking that some state changes further along the line; smaller, more focused methods help stop this.

I would say that your practice here is wonderful.

+1
source

I use it when I'm too lazy to declare a flag and test it. But the fact is that if you use break, return, and such instructions in the middle of your code, you sometimes have to reorganize it when adding functionality.

Therefore, I consider this a bad practice, but it is very often used. Well this is just my opinion: p

0
source

All Articles