fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

`else` keyword in loops is confusing to beginners

Open michaellilltokiwa opened this issue 1 year ago • 5 comments

Maybe we should use another keyword like finally, or end?

At least it confused Simon, Khalil and me in the beginning.

michaellilltokiwa avatar Sep 04 '24 09:09 michaellilltokiwa

I think finally or end could also be confusing, because that sounds as if it is always executed afterwards, but is actually only executed when until condition is not met. I don't have a better idea though.

simonvonhackewitz avatar Sep 04 '24 13:09 simonvonhackewitz

@simonvonhackewitz hmm, yes.

michaellilltokiwa avatar Sep 04 '24 14:09 michaellilltokiwa

I think our use of else is similar to that in Python, so millions can deal with this, even if Python does not have the counterpart of code following until. The only alternative I could think of is otherwise, but that has the same meaning as else.

fridis avatar Sep 09 '24 09:09 fridis

fallback, or else might also be alternatives. I currently think all of them would be better than having two meanings for keyword else.

michaellilltokiwa avatar Sep 10 '24 08:09 michaellilltokiwa

e.g.

    for
      res list u8 := nil, res ++ byte  # contains the decoded data at the end
      nxt := 0, nxt + 2
    while nxt < data.length
    do
      bits_0_3 := dec_char_at nxt
      bits_4_7 := dec_char_at nxt+1

      byte := if bits_0_3.ok && bits_4_7.ok
                [(bits_0_3.val << 4) | bits_4_7.val]
              else [u8 0]              # decoding result not used in error case

    until bits_0_3.is_error || bits_4_7.is_error
      if bits_0_3.is_error then bits_0_3.err
      else                  bits_4_7.err
    else
      outcome res.as_array

would be

    for
      res list u8 := nil, res ++ byte  # contains the decoded data at the end
      nxt := 0, nxt + 2
    while nxt < data.length
    do
      bits_0_3 := dec_char_at nxt
      bits_4_7 := dec_char_at nxt+1

      byte := if bits_0_3.ok && bits_4_7.ok
                [(bits_0_3.val << 4) | bits_4_7.val]
              else [u8 0]              # decoding result not used in error case

    until bits_0_3.is_error || bits_4_7.is_error
      if bits_0_3.is_error then bits_0_3.err
      else                  bits_4_7.err
    otherwise
      outcome res.as_array

Seems more clear to me with otherwise

michaellilltokiwa avatar Sep 10 '24 08:09 michaellilltokiwa