[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Adding a Return() function
- From: Javier Guerra Giraldez <javier@...>
- Date: Wed, 17 Dec 2014 03:03:41 -0500
On Wed, Dec 17, 2014 at 2:25 AM, Hao Wu <firstname.lastname@example.org> wrote:
> I think OP's point is return can be a function so it can be baked into the
> expression v.s. a single statement, for simplicity.
yes, i was just pointing a third option that is shorter, more readable
(IMHO) and currently valid.
when any function has some 'fail fast' condition(s), i like to add one
or more such 'guard lines' as close to the top as possible. also, if
the "then" clause ends with a return, i don't put an "else" for the
rest of the function, avoiding useless indentation and too many 'ends'
at the end.
if y==0 then return nil, "division by zero" end
return x / y
if y==0 then
return nil, "division by zero"
the OP proposal would be:
if y!=0 or Return(nil, "division by zero") then
which i think is much less readable than either of the others, and not
shorter than the first one.