You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, looking at some real world code examples of this it seems that about 50% of the time returning whatever value comes out of the if is not intended and adding returnafter the block is a better "fix". e.g.
functionfoo()
if condition
x
else
y
endreturnend
and around 50% or the time it is better to insert the returns inside the branches, e.g.
functionfoo()
if condition
return x
elsereturn y
endend
Some potential changes to the current setup:
If there are no return in any branch recurse and add returns in the branches instead of putting the return in front of the whole block. The question would then be if Runic should also add an explicit else branch when no such branch exist, e.g.
functionfoo()
if condition
x
endend
would become
functionfoo()
if condition
return x
elsereturnendend
If there are return in any branch, make sure there is a return in all branches.
The same discussion applies to try, but for try it can actually improve readability a bit too since it isn't obvious what the possible return values are in e.g.
If there is a finally branch with return this will override any other return so it is misleading to add return in any other branch (perhaps Runic should even remove existing ones?)
If there is an else it can always have return except it is misleading to add if 1. or if the try block has a return.
The catch block can always have it except misleading if 1.
The try block can have it if there is no else and if not 1.
Currently Runic will format something e.g.
into
However, looking at some real world code examples of this it seems that about 50% of the time returning whatever value comes out of the
if
is not intended and addingreturn
after the block is a better "fix". e.g.and around 50% or the time it is better to insert the returns inside the branches, e.g.
Some potential changes to the current setup:
return
in any branch recurse and add returns in the branches instead of putting thereturn
in front of the whole block. The question would then be if Runic should also add an explicitelse
branch when no such branch exist, e.g.return
in any branch, make sure there is a return in all branches.The same discussion applies to
try
, but fortry
it can actually improve readability a bit too since it isn't obvious what the possible return values are in e.g.so making it explicit is a good idea, e.g.
The text was updated successfully, but these errors were encountered: