Returning tuples of different lengths — OK?

MateoGOP edited

("burn", 12.5), ("set", "mode", "SAFE"), ("abort",). Is mixing shapes good design?

4

Comments 4

Join the discussion

Already have an account? Log in

  1. SamPricereplies: 2

    It's a common lightweight pattern: the first element says what kind of command it is, the rest are its arguments. The caller checks the first element and unpacks accordingly. For bigger systems you'd use classes or dataclasses, but for a console parser tuples are fine.

    6
    1. MateoGOPreplies: 1

      First element as the "type" — makes sense.

      0
      1. PiotrZ

        That trailing comma got me. Printed "abort" instead of "('abort',)".

        5
    2. AmeliaRuns

      Don't forget the comma in ("abort",) — without it, it's just a string in brackets.

      2