| |
| Posted by H. S. Teoh in reply to Dom DiSc | PermalinkReply |
|
H. S. Teoh
Posted in reply to Dom DiSc
| On Fri, Jan 14, 2022 at 03:04:28AM +0000, Dom DiSc via Digitalmars-d wrote:
> On Friday, 14 January 2022 at 02:22:13 UTC, H. S. Teoh wrote:
[...]
> > Majority? Hardly. How should opCmp for std.stdio.File be defined?
>
> Oh, come on. Every browser need to order files. Of course there are endless different orders (by size, by name, by date, ...) but there IS an order - and one need to be applied if you want to show the user a list. How else can you create a list other than creating an order?!?
A File does not have an inherent order; an *directory entry* may have one of several possible orders imposed upon it. You create a list by defining an external ordering (by name, by date, by size, etc.). The file itself is not inherently orderable, and therefore the ordering does not belong in the class.
> > What does it even mean for one File to be "less than" another?
>
> It means it should be shown before the other one in a list.
Yes, it means "less than" **according to some externally-defined order**. The ordering is external to the file, and not inherent to it. This is why there are multiple possible orders. Which of them should File.opCmp use?
> And this also makes clear why this order is only partial, because maybe you have some filter. All files filtered out are non-comparable to ones within the list, because they are not shown, neither before nor after. And of course they are not equal.
Your mention of "filter" makes it clear that the order does not belong in the File class; it belongs in another object that represents an entry in a list of files. A filter is something you use to impose an order on a collection of unordered objects; it's not something inherent to the object itself. Therefore, std.stdio.File should not have an .opCmp defined for it.
> > What about a Socket?
> Any kind of ID?
Again, that's imposing an external order to something that inherently doesn't have one. You can sort a list of sockets by last access time, connection speed, lexicographic IP address, etc., but these are external orders imposed upon the Socket, not an inherent order.
> > What about a Widget or Window?
> z-Order? - at least for windows that really matters.
Also an external order.
> > What about a ServerConnection?
> Priority?
Ditto.
> > What about an ObjectFactory?
> Nah, maybe for something too generic order doesn't matter so much, but at least for the majority of your examples there were meaningful orders, don't you think?
No, they are not inherently orderable, the orderings you mentions are external orders imposed on them. An external order should be defined by an external predicate that compares two objects (this is why std.algorithm.sort takes a predicate, btw), not in the .opCmp which defines an *inherent* order. You can order complex numbers by magnitude, for example, but that does not mean they are inherently orderable.
T
--
If creativity is stifled by rigid discipline, then it is not true creativity.
|