lua-users home
lua-l archive

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


ORIF should be a great idea to make code easier to maintain without switch/case construct, IMOO.
 



Le Vendredi 14 août 2015 21h02, Soni L. <fakedme@gmail.com> a écrit :




On 14/08/15 03:31 PM, Coda Highland wrote:
> On Fri, Aug 14, 2015 at 11:29 AM,  <tobias@justdreams.de> wrote:
>> Quoting "Soni L." <fakedme@gmail.com>:
>>
>>> With orif:
>>>
>>> ```lua
>>> local flag = false
>>> if i == 1 then
>>>      flag = true
>>> orif i == 2 then -- explicit fallthrough
>>>      print(flag)
>>> else -- default
>>>      print "Unknown!"
>>> end
>>> ```
>>
>> Lua has elseif which is I think exactly the same:
>> local flag = false
>> if i == 1 then
>>      flag = true
>> elseif i == 2 then -- explicit fallthrough
>>      print(flag)
>> else -- default
>>      print "Unknown!"
>> end
>>
>> Regards,
>>    Tobias
> No, elseif is totally different semantics, and elseif is exactly WHY I
> think orif is a bad idea: elseif only fires if an earlier condition
> wasn't true. orif looks syntactically like it ought to behave like
> elseif, but it doesn't.
>
> /s/ Adam
>
orif is the or operator combined with elseif.

It's similar to this (if Lua allowed this):

local flag = false
if i == 1 then
  flag = true
  goto next
elseif i == 2 then
  ::next::

  print(flag)
else
  print"Unknown!"
end


--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.