lua-users home
lua-l archive

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


Something I think other people undervalue is how easy code is to skim.

if v == 'value1' then
  do_something()
elseif v == 'value2' then
  do_something_else()
  goto whatever
elseif v == 'value3 then
  do_another_thing()
else
::whatever::
  do_whatever()
end

While this is readable, I feel like this is more comfortable:

switch condition do
  'value1' then
    do_something()
    break
  'value3' then
    do_another_thing()
    break
  'value2' then
    do_something_else()
  else
    do_whatever()
end

I'm not sure if this is the exact syntax I would want.  It's important
that the value being compared is top-level, and what it is being
compared against is on the same level of indentation -- also
fall-through is possible.  I find long elseif chains a bit skewing,
especially when using something like goto in the mix.  If I want to
understand code quickly, I expect "skim value" in how I can express
those comparisons.  Shrug it off as convenience for lazy programmers ~