lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 16-Aug-17 11:49, Dirk Laurie wrote:
if condition then call_my_routine() else return end

Do you indent it as:

if condition then
    call_my_routine()
else
    return
end

Usually the latter one.
Rarely the one-liner above, but only for situations involving neither function calls nor 'return' statements, i.e. when it is basically a form of ternary operator.

As an aside: I try to avoid using 'return' in the middle of a function, unless it is really needed for efficiency or for readability. I like to be able to easily follow the execution flow when reading the code.
When I have to use 'return' I mark it with a special comment, such as:

 if condition then
     return --> exit
 end

and a blank line just below, to make it stand out.
I got this habit after reading "Structured programming with Pascal" [Wirth]. It helped a lot with the assembly code I used to write at the time... and proved useful for all languages I learned later.

--
  Enrico