Discussion Thread: DIP 1042--ProtoObject--Community Review Round 1

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 14 02:22:13 UTC 2022


On Fri, Jan 14, 2022 at 01:48:06AM +0000, Dom DiSc via Digitalmars-d wrote:
[...]
> > This makes me question the wisdom of putting opCmp in the common
> > base of all classes.  If only a small subset of classes will be
> > comparable with each other
> 
> This is a misunderstanding.
> First of all, you don't compare classes, but objects (instances) of
> the same class.
> And the majority of objects may well be comparable.
[...]

Majority? Hardly.  How should opCmp for std.stdio.File be defined?  What
does it even mean for one File to be "less than" another?  What about a
Socket?  What about a Widget or Window? What about a ServerConnection?
What about an ObjectFactory?  What kind of order can be meaningfully
imposed on objects of such classes?

In the universe of things one might want to define classes for, only a
narrow subset are meaningfully (partially) orderable.  And among them,
an even narrower subset is linearly-orderable (mostly just user-defined
numerical types and number-like objects).  Even std.complex.Complex does
not have any meaningful order (except for the very narrow case where the
imaginary part is zero).

A base class should generally encapsulate functionality common to ALL
subclasses.  If most classes are not meaningfully orderable (File,
Socket, Widget, Connection, Factory, Complex), then why are we
shoehorning opCmp into the base class of ALL classes?


T

-- 
Unix is my IDE. -- Justin Whear


More information about the Digitalmars-d mailing list