Jump to content

Why use only one return statement per function?


Recommended Posts

Hi community :).

 

A very general question.

 

What is your personal preference concerning the use of only one return statement per function.

 

In the past I've been used to this coding style but now I really appreciate the brevity that multiple return statement in a function (or object method) grant me when writing code and as a result I used it a lot when writing my modules.

 

Now I'm particularly worried about going against the coding standards suggested by PS.

 

How about you guys?

 

 

P.S: if the post isn't placed in the right position in the forum or if the topic isn't right for the forum itself please forgive me and notify me so that I can remove it :)

Edited by gr4devel (see edit history)
Link to comment
Share on other sites

mmm...wait I think I didn't explain myself.

 

I don't mean to return multiple values but to use multiple return statement in different positions in a given function or method.

 

e.g:

 

function A ($a) {
if($a)
return 'hi';
return 'bye';
}

 

Sorry for the lack of my precision.

Edited by gr4devel (see edit history)
Link to comment
Share on other sites

for me - everything is fine in this code. Im using these statements.

I don't know why you think that you're going against the coding standards suggested by PS :)

 

in my opinion

if your code is compatible with php - you definitely don't have to worry

Link to comment
Share on other sites

Nice to know my friend :).

 

I was worried about the "We recommend one return per method/function." that I've found reading the coding standards (http://doc.prestashop.com/display/PS15/Coding+Standards#CodingStandards-Returnvalues).

 

However let me thank you as always for the participation to this topi :D

Edited by gr4devel (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...