Replies: 1 comment 1 reply
-
|
After looking at the different options, I think the chevron syntax both looks the nicest and is just explicit enough. I remember that you don't want the end-user to know how |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Percieved Issue
I often find myself making a Derived state that only depends on one source state and think the full
DerivedState(<source>, <fn or lambda>)is a bit clunky and gets in the way of writing readable, declarative code.Possible Solution
I've been playing around with a few possible syntaxes and would appreciate some input.
>>assource >> <transfrom>.deriveor.into, assource.derive(<transfrom>)source(<transfrom>)I think there should only be one option. let's explore what they might look like for formatting an int into a string, a pretty general use case.
Chevron and Call
I've been leaning towards the chevron syntax as I think it shows the derived state as a transformation from one state into another. For example:
shows that the label takes
how_muchtransformed into a string, I think this is clear and concise.However, python has some restrictions when it comes to chevrons with lambdas and requires parens or some delimiters.
in this case I think the call syntax may be more clear for lambdas...
but is less clear for simple transformations.
And I think this option is too close to forward method call syntax and may be more confusing for users, they shouldn't have to understand the framework to use it.
I don’t think there should be two options.
Small Aside
One cool thing about using the chevron is they could be chained together...
Explicit or no change
It may be that verbose is the best option, maybe.
While both of these are clear I think they have two drawbacks. The first is you have to stop and think about what they are doing. Secondly, this requires a new-comer to understand what deriving state is.
Though into is a bit better...
and can both be read cleanly, "text equals
how_muchturned into a string" and "text equalshow_muchinto this function"Trial Implementation
to try any of these out add this to the body of tg_gui_core.stateful.State
Beta Was this translation helpful? Give feedback.
All reactions