It really depends on the complexity of the method, you should always strive for readability, these examples are great for me.
function MyFunc: Boolean;
begin
Result := False;
if (Something or SomethingElse) and Whatever then
Result := True;
end;
function MyFunc: Boolean;
begin
Result := (Something or SomethingElse) and Whatever;
end;
function MyFunc: Boolean;
begin
Exit((Something or SomethingElse) and Whatever);
end;
function MyFunc: Boolean;
begin
if (Something or SomethingElse) and Whatever then
Result := True
else
Result := False;
end;
Personally, I would like to avoid other statuses and write as few lines of code as possible, so I would go with example 2, but example 1 is fine too, options 3 and 4 are not very readable by IMO.
I think that if you give these 4 examples to beginners, the first one will be easiest to understand.
source
share