#1023 fwt::TextWidget Doc bug - weird default value for multiLine

tactics Sun 14 Mar 2010

Here's a weird one.

In this doc, the default value for the multiLine slot (a boolean) is this is RichText.

http://fantom.org/doc/fwt/TextWidget.html#multiLine

const Bool  multiLine := this is RichText

tactics Sun 14 Mar 2010

Apparently, there isn't a whole lot of syntax checking going on in certain classes :)

In src\fwt\TextWidget.fan:

**
** False for text fields and true for multiline text areas.
** Default is false for `Text` widgets and true for `RichText`
** widgets.  This field cannot be changed once the widget
** is constructed.
**
const Bool multiLine := this is RichText

KevinKelley Sun 14 Mar 2010

const Bool multiLine := this is RichText

That's actually good code, imo anyway... is corresponds to as, doing what you'd expect: returns true if this is an instanceof RichText.

See docLang::Expressions#typeChecking

That's one of my favorite little fantomisms. :-)

tactics Sun 14 Mar 2010

Oh wow... it is, isn't it? I even considered that possibility in my head, but then passed it off.

jodastephen Thu 18 Mar 2010

If you'd seen

const Bool  multiLine := this isa RichText

would that have been clearer?

"is a" becoming isa might be a helpful change?

tactics Thu 18 Mar 2010

would that have been clearer?

I don't think so. It's just very awkward to see an English sentence in the code. Not to mention it makes reference to a subclass, which isn't clean OO.

I think the more idiomatic way of expressing this would be to give it a default of false and make it virtual, allowing RichText to override it.

Login or Signup to reply.