Login  Register

Re: How does Boolean ifTrue work?

Posted by Thierry Goubier on Oct 31, 2016; 2:55pm
URL: https://forum.world.st/How-does-Boolean-ifTrue-work-tp4920873p4920895.html

Le 31/10/2016 à 15:32, CodeDmitry a écrit :
> I realized it a bit before you posted but thanks for confirming.
>
> Boolean seems to indeed just be a "Dynamic Interface"; since Smalltalk does
> not have "Java Interfaces"(nor want them for the same reason JavaScript
> doesn't), the developers wanted to still have True and False be subclasses
> of Booleans.

Boolean is a nice header for classification. Everybody is familiar with
Boolean algebra, including hardware guys :)

> In all honesty Boolean seems to be there purely for the "common sense" of
> it, rather than need. Smalltalk is duck typed and has no need for
> interfaces. If it's a Boolean, you know it has those methods so Boolean is
> not actually useful for anything; True and False may as well just be
> subclasses of Object.

Not exactly. Boolean carry 15 methods that are not overridden in either
False nor True (and 11 methods which are), so Boolean is also used as a
way to share code between the classes True and False and avoid code
duplication. A nice case for having a common superclass below Object.

Thierry