March 25, 2004 Re: Doing someObjectArray.sort | ||||
---|---|---|---|---|
| ||||
Posted in reply to SL | SL wrote: > C. Sauls wrote: > >> If you're trying to do what I think you're trying to do, change the prototype of that method to: >> public int opCmp(SolarSystem ss) >> >> -C. Sauls >> -Invironz > > > I just tried something like that (with a separate class) and it didn't work: > > (These code snippets are for a class named StarTypeInfo) > This does not sort properly: > --------------------------------- > int opCmp(StarTypeInfo sti) { > if (amount<sti.amount) { > return -1; > } else if (amount>sti.amount) { > return 1; > } else { > return 0; > } > } > --------------------------------- > > > This sorts fine: > --------------------------------- > int opCmp(Object o) { > StarTypeInfo sti=cast(StarTypeInfo) o; > if (sti!=null) { > if (amount<sti.amount) { > return -1; > } else if (amount>sti.amount) { > return 1; > } > } > return 0; > } > --------------------------------- > That's strange, Note that you can simplify that to: int opCmp(Object o) { test sti=cast(test) o; return amount - sti.amount; } but this should work (I tried it myself with no luck) int opCmp(StarTypeInfo sti) { return amount-sti.amount; } -- -Anderson: http://badmama.com.au/~anderson/ |
March 26, 2004 Re: Doing someObjectArray.sort | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | J Anderson wrote: > That's strange, > > Note that you can simplify that to: > int opCmp(Object o) > { > test sti=cast(test) o; > return amount - sti.amount; > } I should add that I didn't test for null because if you use it with another object it'll cause an error, which is what you want (then you could go back and detect that object). However the above code is seriously bad code and the following should've worked (and is what I ment in my original message). > but this should work (I tried it myself with no luck) > int opCmp(StarTypeInfo sti) > { > return amount-sti.amount; > } -- -Anderson: http://badmama.com.au/~anderson/ |
March 26, 2004 Re: Converting X to D (was Doing someObjectArray.sort) | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | J Anderson wrote: > SL wrote: > >> J Anderson wrote: >> >> "Converting C# to D" and "Converting Java to D" pages would probably help in that regard, much like the "Converting C to D" and "Converting C++ to D" pages do. I'm learning that those (The existing "Converting" pages) usually have good hints that aren't covered in the rest of the spec. >> >> -SL > > > Good idea! The trouble is getting the man power to do such things (most coders like to code not write). Parhaps you (or someone else) could jot down ideas for these converting pages as you (they) go along and then produce something at the end. Quite often its the people who are learning that are the best at explaining such things to newbies. There's already a spot on the wiki to put these, http://www.wikiservice.at/d/wiki.cgi?NotesForProgrammersUsedTo. I've put a little guide for BASIC users there since that's where I have the most experience. If someone wants to add to an existing page or add a new one that'd be great. -- Justin http://jcc_7.tripod.com/d/ |
March 26, 2004 Re: Converting X to D (was Doing someObjectArray.sort) | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | J C Calvarese wrote:
> J Anderson wrote:
>
>> SL wrote:
>>
>>> J Anderson wrote:
>>>
>>> "Converting C# to D" and "Converting Java to D" pages would probably help in that regard, much like the "Converting C to D" and "Converting C++ to D" pages do. I'm learning that those (The existing "Converting" pages) usually have good hints that aren't covered in the rest of the spec.
>>>
>>> -SL
>>
>>
>>
>> Good idea! The trouble is getting the man power to do such things (most coders like to code not write). Parhaps you (or someone else) could jot down ideas for these converting pages as you (they) go along and then produce something at the end. Quite often its the people who are learning that are the best at explaining such things to newbies.
>
>
> There's already a spot on the wiki to put these,
> http://www.wikiservice.at/d/wiki.cgi?NotesForProgrammersUsedTo.
>
> I've put a little guide for BASIC users there since that's where I have the most experience. If someone wants to add to an existing page or add a new one that'd be great.
>
Ooooo, nice. *several minutes later* I've added (the beginnings of) a page for C# (I copied the java page, changed what was appropriate, and added some more stuff).
And I added a note about instanceof and casting to the Java page, and noted that D allows inline assembly too.
(It'd be nice if these pages were easier to find - Say, if some links on the left-bar in the spec pointed to wiki pages).
-SL
|
March 26, 2004 Re: Converting X to D (was Doing someObjectArray.sort) | ||||
---|---|---|---|---|
| ||||
Posted in reply to SL | SL wrote: ... > J C Calvarese wrote: >> There's already a spot on the wiki to put these, >> http://www.wikiservice.at/d/wiki.cgi?NotesForProgrammersUsedTo. >> >> I've put a little guide for BASIC users there since that's where I have the most experience. If someone wants to add to an existing page or add a new one that'd be great. >> > > Ooooo, nice. *several minutes later* I've added (the beginnings of) a page for C# (I copied the java page, changed what was appropriate, and added some more stuff). Great! > > And I added a note about instanceof and casting to the Java page, and noted that D allows inline assembly too. Thanks. > > (It'd be nice if these pages were easier to find - Say, if some links on the left-bar in the spec pointed to wiki pages). (That sounds like a good idea to me.) > > -SL -- Justin http://jcc_7.tripod.com/d/ |
March 27, 2004 Re: Converting X to D (was Doing someObjectArray.sort) | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | J C Calvarese wrote: >> (It'd be nice if these pages were easier to find - Say, if some links on the left-bar in the spec pointed to wiki pages). > > (That sounds like a good idea to me.) Personally I find the wiki pages messy as well (particularly the first page). I wouldn't want to fix it myself because: 1) I many offend someone 2) Not enough time to spend on this 3) I'm sure someone could do a better job at it then me I think at the very least the links should be at the bottom of the front page because links go to non-specific pages and normally users want to go somewhere specific. >> >> -SL > -- -Anderson: http://badmama.com.au/~anderson/ |
March 27, 2004 Re: Converting X to D (was Doing someObjectArray.sort) | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | J Anderson wrote: > J C Calvarese wrote: > >>> (It'd be nice if these pages were easier to find - Say, if some links on the left-bar in the spec pointed to wiki pages). >> >> >> (That sounds like a good idea to me.) > > > Personally I find the wiki pages messy as well (particularly the first page). I wouldn't want to fix it myself because: > 1) I many offend someone > 2) Not enough time to spend on this > 3) I'm sure someone could do a better job at it then me I'm not sure what kind of changes you're recommending so I just made some random changes to the front page and hopefully you would agree with me that it's an improvement. I like my changes and I'm not afraid of offending anyone. :) > I think at the very least the links should be at the bottom of the front page because links go to non-specific pages and normally users want to go somewhere specific. Are you referring to the D Website or the wiki here? >>> -SL -- Justin http://jcc_7.tripod.com/d/ |
March 27, 2004 Re: Converting X to D (was Doing someObjectArray.sort) | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | J C Calvarese wrote: > > I'm not sure what kind of changes you're recommending so I just made some random changes to the front page and hopefully you would agree with me that it's an improvement. I like my changes and I'm not afraid of offending anyone. :) Yes it is better. However personally I still would like less content on the page. Parhaps (if possible) using some of the white space up by going horizontal with the links. >> I think at the very least the links should be at the bottom of the front page because links go to non-specific pages and normally users want to go somewhere specific. > > Are you referring to the D Website or the wiki here? The wiki. D links looks like my mother's shopping list (no offence meant Walter), the wiki is a little better. Imagine when we have two hundred D pages. -- -Anderson: http://badmama.com.au/~anderson/ |
Copyright © 1999-2021 by the D Language Foundation