digitalmars.D - opCmp - any consensus
- Matthew (2/2) Apr 20 2005 Haven't been able to follow the debate the last few days. Has a
- Ben Hinkle (12/14) Apr 20 2005 You mean the stuff xs0 and I posted about A[] implicitly casting to B[] ...
- Matthew (11/25) Apr 20 2005 Thanks Ben.
- Walter (4/6) Apr 21 2005 I was thinking about changing Object.opCmp to return false if the argume...
- Matthew (7/15) Apr 21 2005 My opinion - which seems to be shared by at least one other - is
- Matthew (6/23) Apr 21 2005 Also, would that cover only the case where the null is the rhs
- Georg Wrede (59/86) Apr 21 2005 I'm with Matthew here. Creating classes of objects, the only person to
- TechnoZeus (4/90) Apr 22 2005 And what of those cases where it is known but still not implemented? Be...
-
Stewart Gordon
(7/8)
Apr 22 2005
- TechnoZeus (7/15) Apr 23 2005 Sorry. I thought the meaning would have been clear inthe context of wha...
- Derek Parnell (11/12) Apr 24 2005 I too have a real problem with your replies. I have to work hard to
- TechnoZeus (19/27) Apr 24 2005 *snip*
- StarCrossed (3/5) Apr 22 2005 total BS
- TechnoZeus (3/10) Apr 23 2005 That doesn't even deserve an answer, but.. yes.
- Derek Parnell (6/20) Apr 24 2005 Well it just wasn't all that obvious. Thanks for clearing it up.
- TechnoZeus (3/9) Apr 24 2005 You're welcome.
- Matthew (6/28) Apr 24 2005 Now _that's_ comedy.
- Stewart Gordon (7/15) Apr 22 2005 So every object would rank equally with null? I'm not sure what sense
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (24/32) Apr 22 2005 Me neither. For opEquals, sure. But for opCmp ? Hmm...
Haven't been able to follow the debate the last few days. Has a consensus emerged?
Apr 20 2005
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...Haven't been able to follow the debate the last few days. Has a consensus emerged?You mean the stuff xs0 and I posted about A[] implicitly casting to B[] for A:B? It seems like xs0 and I agree it is a type-safety hole but we have different ideas about what to do about it. I would like to make the user explicitly cast from A[] to B[] (much like an explicit cast from A* to B* is required in D). Xs0 posted some suggestions involving syntax with ! or in/out to improve the safety. Georg posted that the current behavior is fine as it is. In my interpretation of the rest of the thread I agree with your post requesting input from Walter before going much farther. Why redesign opCmp if Walter isn't open to changing it?
Apr 20 2005
"Ben Hinkle" <ben.hinkle gmail.com> wrote in message news:d46nhi$1gut$1 digitaldaemon.com..."Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...Thanks Ben. I'd noticed a lot of posts, but each one I dipped into involved the pathological issue about array casting - I earned myself a gold star by resisting getting involved for once <g> (I agree with you, btw) - and I couldn't see any further discussion on the proposal. I'm guessing there wasn't any. Walter, can we tempt you out of your shell for a thought on this one? Absent that, I'll continue to wait.Haven't been able to follow the debate the last few days. Has a consensus emerged?You mean the stuff xs0 and I posted about A[] implicitly casting to B[] for A:B? It seems like xs0 and I agree it is a type-safety hole but we have different ideas about what to do about it. I would like to make the user explicitly cast from A[] to B[] (much like an explicit cast from A* to B* is required in D). Xs0 posted some suggestions involving syntax with ! or in/out to improve the safety. Georg posted that the current behavior is fine as it is. In my interpretation of the rest of the thread I agree with your post requesting input from Walter before going much farther. Why redesign opCmp if Walter isn't open to changing it?
Apr 20 2005
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...Haven't been able to follow the debate the last few days. Has a consensus emerged?I was thinking about changing Object.opCmp to return false if the argument is null. I think that would satisfy most peoples' objections to it.
Apr 21 2005
"Walter" <newshound digitalmars.com> wrote in message news:d49d7g$12hb$1 digitaldaemon.com..."Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...My opinion - which seems to be shared by at least one other - is that that's a minor issue. The real issue is that it doesn't belong in Object, and I've presented a (what I think) good proposal for fixing the problem. It does require changes to the language/compiler, though.Haven't been able to follow the debate the last few days. Has a consensus emerged?I was thinking about changing Object.opCmp to return false if the argument is null. I think that would satisfy most peoples' objections to it.
Apr 21 2005
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d49dei$12ji$1 digitaldaemon.com..."Walter" <newshound digitalmars.com> wrote in message news:d49d7g$12hb$1 digitaldaemon.com...Also, would that cover only the case where the null is the rhs comperand? If so, IMO, the cure's worse than the disease. If not, then a guarded hurrah! (Though that does not obviate the need to get it out of Object in the first place.)"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...My opinion - which seems to be shared by at least one other - is that that's a minor issue. The real issue is that it doesn't belong in Object, and I've presented a (what I think) good proposal for fixing the problem. It does require changes to the language/compiler, though.Haven't been able to follow the debate the last few days. Has a consensus emerged?I was thinking about changing Object.opCmp to return false if the argument is null. I think that would satisfy most peoples' objections to it.
Apr 21 2005
Matthew wrote:"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d49dei$12ji$1 digitaldaemon.com...I'm with Matthew here. Creating classes of objects, the only person to know how, or whether at all, they might be comparable, is the programmer. And only the programmer. Therefore, if he has not implemented (forgotten, or chosen not to) opCmp (or whatever equivalent we might have in 6 months), it is not for the compiler to _assume_ any kind of comparability. A stupid example, I might have a class: class PropertyPatch { int numTrees; int area; } How would any compiler consider these instances sortable? And with what right? Heh, this conveniently brings us to Table Manners. (Pun intended!) In SQL, you might have records of PropertyPatch. But, it is customary (good table manners) to also have some way of uniquely addressing the individual instances. With databases, you are encouraged to have an extra field, (say PatchID) that identifies the item. Because this field has to be unique, and (when there's no other candidate for differentiation) it is usually an integer, then we -- all of a sudden -- have sortablility. Meanigless as such, or not. (Not to mention that whatever we have as instances, they have to be individually addressable also outside the computer. Like the real physical patches on my ranch: even I gotta know which is which.) This leads us conveniently to the fact that whenever we do have several instances of a class, we simply do have to have something unique with which we can distinguish the individual items from each other. As a result, we can _demand_ that instances be sortable. And, in spite of that, I think we can also _demand_ that anybody who creates a class, either has to define how to sort the instances, or face an assert error! ---- This means, that if the programmer hasn't, then he'll become aware of it early enough. Now, sortability and equality are two separate issues. But there is one thing in common between them: a PropertyPatch can only be equal and only be sortable, via the explicit definition by the programmer himself. (I'm not talking about equivalence here, especially as defind as being the same instance.) I might want a 2 acre 33 tree patch to be equal to a 1 acre 66 tree patch. ((Hmm, on second thought, is it guaranteed that we can have "bit pattern equality" as a default? And then just expand on this with programmer defined equalities? I guess we can, since I'm unable to imagine a situation where two instances having the same bit pattern would be considered unequal!)) Otoh, the above (parenthesized) paragraph becomes moot if the PatchID is defined! Then no two instances would compare equal by bit pattern. Which leads us back to obligatory user-defined equality. Sigh. ---- For "internal purposes", the compiler may use any means it chooses -- in situations where the instances have to be handled or ordered -- as long as this handling or ordering is invisible to the programmer. (I.e. go ahead and use toHash(currentMemoryLocation), if you want. But only where the programmer never gets to know about it. One example would be, in which order the instances are sent over a stream.) ---- Well, I haven't presented so many solutions in this post. :-( But, at least, I feel I've found some Right Questions to ask. :-)"Walter" <newshound digitalmars.com> wrote in message news:d49d7g$12hb$1 digitaldaemon.com...Also, would that cover only the case where the null is the rhs comperand? If so, IMO, the cure's worse than the disease. If not, then a guarded hurrah! (Though that does not obviate the need to get it out of Object in the first place.)"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...My opinion - which seems to be shared by at least one other - is that that's a minor issue. The real issue is that it doesn't belong in Object, and I've presented a (what I think) good proposal for fixing the problem. It does require changes to the language/compiler, though.Haven't been able to follow the debate the last few days. Has a consensus emerged?I was thinking about changing Object.opCmp to return false if the argument is null. I think that would satisfy most peoples' objections to it.
Apr 21 2005
And what of those cases where it is known but still not implemented? Better to have a default. If someone wants to make something not comparable, then they can override the default accordingly, I would think... just as Walter is talking about doing in the case of the argument being null. This makes much more sense than to remove useful functionality from the language. TZ "Georg Wrede" <georg.wrede nospam.org> wrote in message news:426857C1.4030007 nospam.org...Matthew wrote:"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d49dei$12ji$1 digitaldaemon.com...I'm with Matthew here. Creating classes of objects, the only person to know how, or whether at all, they might be comparable, is the programmer. And only the programmer. Therefore, if he has not implemented (forgotten, or chosen not to) opCmp (or whatever equivalent we might have in 6 months), it is not for the compiler to _assume_ any kind of comparability. A stupid example, I might have a class: class PropertyPatch { int numTrees; int area; } How would any compiler consider these instances sortable? And with what right? Heh, this conveniently brings us to Table Manners. (Pun intended!) In SQL, you might have records of PropertyPatch. But, it is customary (good table manners) to also have some way of uniquely addressing the individual instances. With databases, you are encouraged to have an extra field, (say PatchID) that identifies the item. Because this field has to be unique, and (when there's no other candidate for differentiation) it is usually an integer, then we -- all of a sudden -- have sortablility. Meanigless as such, or not. (Not to mention that whatever we have as instances, they have to be individually addressable also outside the computer. Like the real physical patches on my ranch: even I gotta know which is which.) This leads us conveniently to the fact that whenever we do have several instances of a class, we simply do have to have something unique with which we can distinguish the individual items from each other. As a result, we can _demand_ that instances be sortable. And, in spite of that, I think we can also _demand_ that anybody who creates a class, either has to define how to sort the instances, or face an assert error! ---- This means, that if the programmer hasn't, then he'll become aware of it early enough. Now, sortability and equality are two separate issues. But there is one thing in common between them: a PropertyPatch can only be equal and only be sortable, via the explicit definition by the programmer himself. (I'm not talking about equivalence here, especially as defind as being the same instance.) I might want a 2 acre 33 tree patch to be equal to a 1 acre 66 tree patch. ((Hmm, on second thought, is it guaranteed that we can have "bit pattern equality" as a default? And then just expand on this with programmer defined equalities? I guess we can, since I'm unable to imagine a situation where two instances having the same bit pattern would be considered unequal!)) Otoh, the above (parenthesized) paragraph becomes moot if the PatchID is defined! Then no two instances would compare equal by bit pattern. Which leads us back to obligatory user-defined equality. Sigh. ---- For "internal purposes", the compiler may use any means it chooses -- in situations where the instances have to be handled or ordered -- as long as this handling or ordering is invisible to the programmer. (I.e. go ahead and use toHash(currentMemoryLocation), if you want. But only where the programmer never gets to know about it. One example would be, in which order the instances are sent over a stream.) ---- Well, I haven't presented so many solutions in this post. :-( But, at least, I feel I've found some Right Questions to ask. :-)"Walter" <newshound digitalmars.com> wrote in message news:d49d7g$12hb$1 digitaldaemon.com...Also, would that cover only the case where the null is the rhs comperand? If so, IMO, the cure's worse than the disease. If not, then a guarded hurrah! (Though that does not obviate the need to get it out of Object in the first place.)"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...My opinion - which seems to be shared by at least one other - is that that's a minor issue. The real issue is that it doesn't belong in Object, and I've presented a (what I think) good proposal for fixing the problem. It does require changes to the language/compiler, though.Haven't been able to follow the debate the last few days. Has a consensus emerged?I was thinking about changing Object.opCmp to return false if the argument is null. I think that would satisfy most peoples' objections to it.
Apr 22 2005
TechnoZeus wrote:And what of those cases where it is known but still not implemented?<snip top of upside-down reply> What is "it" here? And known to whom? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Apr 22 2005
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:d4ah96$24ha$2 digitaldaemon.com...TechnoZeus wrote:Sorry. I thought the meaning would have been clear inthe context of what it was a reply to. Obviously, I was mistaken, so here's a translation... <translation> And what of those cases where the fact that the object is comparable is known (by the programmer of that object) but still not implemented? </translation> TZ And what of those cases where it is known but still not implemented?And what of those cases where it is known but still not implemented?<snip top of upside-down reply> What is "it" here? And known to whom? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Apr 23 2005
On Sat, 23 Apr 2005 21:39:07 -0500, TechnoZeus wrote: [snip]Sorry. I thought the meaning would have been clear inthe context of what it was a reply to. Obviously, I was mistaken, so here's a translation...I too have a real problem with your replies. I have to work hard to discover what it is you are actually replying to. The problem seems to stem from your top-posting style. It just makes it too much work to bother reading your posts. You leave in the posts all the other stuff you are *not* replying to. It is quite confusing. -- Derek Parnell Melbourne, Australia 24/04/2005 8:57:37 PM
Apr 24 2005
"Derek Parnell" <derek psych.ward> wrote in message news:l9bbk7o31w4s$.13wkgjjxknpmt.dlg 40tude.net...On Sat, 23 Apr 2005 21:39:07 -0500, TechnoZeus wrote:*snip*I too have a real problem with your replies. I have to work hard to discover what it is you are actually replying to. The problem seems to stem from your top-posting style.*snip*-- Derek Parnell Melbourne, Australia 24/04/2005 8:57:37 PMThanks for the input. I'll work on it. I see many reply styles here. Top posting, bottom posting, insert posting, etcetera. So far, I have only heard complaints about me top posting, which is the deault for Outlook Express and my prefered style.... and one complaint about not having line breaks in my paragraphs. You may have already notice that I have been trying to remember to insert line breaks manually into my paragraphs, for the sake of people reading my posts through the web interface, or through any interface that doesn't have automatic word wrap. Again, thanks for pointing out your difficulty in dealing with the top down style, and extended context quoting. The feedback is appreciated. TZ
Apr 24 2005
In article <d4ad7d$21ev$1 digitaldaemon.com>, TechnoZeus says...And what of those cases where it is known but still not implemented? Better to have a default. If someone wants to make something not comparable, then they can override the default accordingly, I would think... just as Walter is talking about doing in the case of the argument being null. This makes much more sense than to remove useful functionality from the language.total BS Do u program?
Apr 22 2005
"StarCrossed" <StarCrossed_member pathlink.com> wrote in message news:d4ajh6$26kn$1 digitaldaemon.com...In article <d4ad7d$21ev$1 digitaldaemon.com>, TechnoZeus says...That doesn't even deserve an answer, but.. yes. TZAnd what of those cases where it is known but still not implemented? Better to have a default. If someone wants to make something not comparable, then they can override the default accordingly, I would think... just as Walter is talking about doing in the case of the argument being null. This makes much more sense than to remove useful functionality from the language.total BS Do u program?
Apr 23 2005
On Sat, 23 Apr 2005 21:40:17 -0500, TechnoZeus wrote:"StarCrossed" <StarCrossed_member pathlink.com> wrote in message news:d4ajh6$26kn$1 digitaldaemon.com...Well it just wasn't all that obvious. Thanks for clearing it up. -- Derek Parnell Melbourne, Australia 24/04/2005 9:00:39 PMIn article <d4ad7d$21ev$1 digitaldaemon.com>, TechnoZeus says...That doesn't even deserve an answer, but.. yes.And what of those cases where it is known but still not implemented? Better to have a default. If someone wants to make something not comparable, then they can override the default accordingly, I would think... just as Walter is talking about doing in the case of the argument being null. This makes much more sense than to remove useful functionality from the language.total BS Do u program?
Apr 24 2005
"Derek Parnell" <derek psych.ward> wrote in message news:mrypw5e0gsvi.zf6thq5km4k2.dlg 40tude.net...On Sat, 23 Apr 2005 21:40:17 -0500, TechnoZeus wrote: Well it just wasn't all that obvious. Thanks for clearing it up. -- Derek Parnell Melbourne, Australia 24/04/2005 9:00:39 PMYou're welcome. TZ
Apr 24 2005
"Derek Parnell" <derek psych.ward> wrote in message news:mrypw5e0gsvi.zf6thq5km4k2.dlg 40tude.net...On Sat, 23 Apr 2005 21:40:17 -0500, TechnoZeus wrote:Now _that's_ comedy. LOL Derek, you're a gem. And what a tonic for the morning after the night before? :-)"StarCrossed" <StarCrossed_member pathlink.com> wrote in message news:d4ajh6$26kn$1 digitaldaemon.com...Well it just wasn't all that obvious. Thanks for clearing it up.In article <d4ad7d$21ev$1 digitaldaemon.com>, TechnoZeus says...That doesn't even deserve an answer, but.. yes.And what of those cases where it is known but still not implemented? Better to have a default. If someone wants to make something not comparable, then they can override the default accordingly, I would think... just as Walter is talking about doing in the case of the argument being null. This makes much more sense than to remove useful functionality from the language.total BS Do u program?
Apr 24 2005
Walter wrote:"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:d46ii5$1cvv$1 digitaldaemon.com...So every object would rank equally with null? I'm not sure what sense that would make.... Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.Haven't been able to follow the debate the last few days. Has a consensus emerged?I was thinking about changing Object.opCmp to return false if the argument is null. I think that would satisfy most peoples' objections to it.
Apr 22 2005
Stewart Gordon wrote:Walter wrote:Me neither. For opEquals, sure. But for opCmp ? Hmm... The approach I took in a simple "String" class I made was: int opEquals(Object o) { if (this is o) return true; String string = cast(String) o; if (string is null) return false; return this.str == string.str; } int opCmp(Object o) { if (this is o) return 0; String string = cast(String) o; if (string is null) assert(0); return std.string.cmp(this.str, string.str); } Based on how the same thing was being done in Java. ("cast" also takes care of the other's "instanceof") --andersI was thinking about changing Object.opCmp to return false if the argument is null. I think that would satisfy most peoples' objections to it.So every object would rank equally with null? I'm not sure what sense that would make....
Apr 22 2005