invent-framework / invent

Express yourself with code.
https://invent-framework.github.io/
Apache License 2.0
109 stars 12 forks source link

Comments/suggestions on design #2

Closed aroberge closed 4 years ago

aroberge commented 4 years ago

Note: after seeing issue #1, I did not attempt to run the code since I too use a Windows environment. This is just based on reading the code. I submit this as an issue instead of a private email so that perhaps others can chime in with better suggestions.

I really like this idea. With beginners in mind, I would suggest a few minor changes to the code examples. Note that these are just quibbles, and that I overwhelmingly positive towards this project and what has been done so far.

  1. Replace the name (first argument of functions) data_store by something like all_cards.
  2. Replace the name (second argument of functions) form or form_value by something like previous_card or previous_card_value -- assuming I understand the logic correctly.

I understand the programmers logic to use all_caps for enums (as in Inputs.SELECT, etc.) ... but I am wondering if using lowercase would not be more beginner friendly - since beginners will not see the underlying code but only use the choices provided.

I really like the idea of creating Python objects instead of using json notation. With this in mind, and thinking back of my own experience (I used to find that keeping track of brackets, parens, etc., and level indentation of "complicated" objects was a bit error prone), instead of having examples that include a list of unnamed objects, like:

cards = [
    Card(
        "GetValue",
        form=Inputs.TEXTBOX,
        text="Enter a number to convert...",
        buttons=[
            {"label": "Convert to Celsius", "target": to_c},
            {"label": "Convert to Farenheit", "target": to_f},
        ],
    ),
    Card(
        "Error",
        text="[b]ERROR[/b]\n\nPlease enter a number.",
        text_color="white",
        background=palette("red"),
        auto_advance=3,
        auto_target="GetValue",
    ),
    Card(
        "Result",
        text="{result:.2f}",
        text_size=98,
        buttons=[{"label": "Ok", "target": "GetValue"}],
    ),
]

I would write something like

get_value = Card(
    "GetValue",
    form=Inputs.TEXTBOX,
    text="Enter a number to convert...",
    buttons=[
        {"label": "Convert to Celsius", "target": to_c},
        {"label": "Convert to Farenheit", "target": to_f},
    ]
)

error = Card(
    "Error",
    text="[b]ERROR[/b]\n\nPlease enter a number.",
    text_color="white",
    background=palette("red"),
    auto_advance=3,
    auto_target="GetValue",
)

result = Card(
    "Result",
    text="{result:.2f}",
    text_size=98,
    buttons=[{"label": "Ok", "target": "GetValue"}],
)

cards = [get_value, error, result]

When using this with beginners, I would possibly encourage them to use paper index cards to design their programs, with each index card corresponding to a Card object. When discussing the code with users, instead of talking about "the third card in the list of cards", one would refer to "the result card".

JoshuaLowe1002 commented 4 years ago

+1 to this. I much prefer the code design in this example as it's much easier to keep track of what's what for beginners :)

ntoll commented 4 years ago

Hey hey... I've incorporated these suggestions into the examples in the docs for the project..! https://pypercard.rtfd.io/

All feedback most welcome and please feel free to ping over PR's too. I greatly value such contributions. :-)

Thank you!