Question about example from Slider documentation

Hi all

I have a question about this example:

(
w = Window.new.front;
b = ControlSpec(-50, 50, \linear, 0.01); // min, max, mapping, step
c = StaticText(w, Rect(20, 20, 150, 20)).align_(\center).background_(Color.rand);
a = Slider(w, Rect(20, 50, 150, 20))
    .focusColor_(Color.red(alpha:0.2))
    .background_(Color.rand)
    .value_(0.5)
    .action_({
        c.string_(b.map(a.value).asString)
        // round the float so it will fit in the NumberBox
        });
a.action.value;
)

Why is it advisable to write “.asString” in the line about c.string and one couldn’t just omit that?

Thanks

A StaticText’s string property is, formally, a string (which should make intuitive sense).

I’m not certain whether StaticText string_ will automatically convert the input to a string or not.

If it doesn’t convert, then asString is mandatory for non-string input values.

If it does convert, then asString would be optional, but that doesn’t mean it’s a good idea to leave it out. I think it makes sense for the help to demonstrate the idea that the string property should be a string. (Wouldn’t it be more confusing to demonstrate a string property by setting it to a non-string?)

There are many places in SC where you can take a shortcut about object types and the class library will try to do something logical with it. But it’s justifiable for the help system to document best practices even if those best practices are more strict than SC permits.

EDIT: Now I see that the preceding example does omit .asString – which I’d argue is a mistake. We should be consistent and illustrate best practices everywhere.

hjh