These are chat archives for ractivejs/ractive

28th
Oct 2018
Cerem Cem ASLAN
@ceremcem
Oct 28 2018 21:16
what do you think about using try/catch as goto:
try
  if something 
    do-something
    throw {do: "this"}
  else if ...
    if ...
      throw {do: "this"}
    else
      if ...
        if ...
          if ...
            throw {do: "this"}
catch e
  if e.do?
    # this is normal
    do-the-job()
  else 
    # something unexpected, rethrow the exception
    throw e
how does it affect code readability in your opinion?
Chris Reeves
@evs-chris
Oct 28 2018 22:22
is there any reason not to just accumulate the do jobs in an array?
just exceptions are a bit weird
Cerem Cem ASLAN
@ceremcem
Oct 28 2018 22:28
actually do-the-job() is a piece of code (say, a few lines), not just a simple function call
Cerem Cem ASLAN
@ceremcem
Oct 28 2018 22:33

is there any reason

technically, no. it's just because of historical reasons: the piece of code block is starting its life as a if/else block. then if gets deeper with nested if/elses. then, at some point, we need the first if/else's else block again.

if it must be refactored, it's absolutely doable
Chris Reeves
@evs-chris
Oct 28 2018 23:08
I usually try to pull stuff like that into functions do that the overall flow can be expressed a little more concisely
and each function is easier to reason through
Cerem Cem ASLAN
@ceremcem
Oct 28 2018 23:11
fair enough