The Inbox: Collections-cmm.858.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-cmm.858.mcz

commits-2
Chris Muller uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-cmm.858.mcz

==================== Summary ====================

Name: Collections-cmm.858
Author: cmm
Time: 4 November 2019, 7:25:14.227142 pm
UUID: 071a78c1-3ac2-4cad-b0e0-e7c2935504e1
Ancestors: Collections-pre.857

Let the printString of an OrderedDictionary reveal its key sequence.

=============== Diff against Collections-pre.857 ===============

Item was added:
+ ----- Method: Dictionary>>keysInOrder (in category 'printing') -----
+ keysInOrder
+ ^ self keysSortedSafely!

Item was changed:
  ----- Method: Dictionary>>printElementsOn: (in category 'printing') -----
  printElementsOn: aStream
  aStream nextPut: $(.
  self size > 100
  ifTrue: [aStream nextPutAll: 'size '.
  self size printOn: aStream]
+ ifFalse: [self keysInOrder
- ifFalse: [self keysSortedSafely
  do: [:key | aStream print: key;
  nextPutAll: '->';
  print: (self at: key);
  space]].
  aStream nextPut: $)!

Item was added:
+ ----- Method: OrderedDictionary>>keysInOrder (in category 'printing') -----
+ keysInOrder
+ ^ self keys!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-cmm.858.mcz

marcel.taeumel
Hi Chris.

Nice catch!

+1 for adding #keysInOrder and using it in #printElementsOn:.

-1 for choosing 'printing' as category of #keysInOrder (and #keysSortedSafely). Maybe 'accessing' instead?
-1 for not having a comment in #keysInOrder ... could you explain the idea of "order" in contrast to "as is" with just a few words? :-) So that one can figure out when to use #keysSortedSafely and when to pick #keysInOrder

Hmmm... does "keys in order" sound almost like "are keys in order" and thus like a boolean result? I have no idea. :-D Did you also consider "keysOrdered" or "orderedKeys"? Just thinking about Color class >> #orderedCrayonColors.

Anyway, good idea. :-) I suppose that even if this method is used in any serialization format, the order would not harm the integrity of the contents.

Best,
Marcel

Am 05.11.2019 02:25:27 schrieb [hidden email] <[hidden email]>:

Chris Muller uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-cmm.858.mcz

==================== Summary ====================

Name: Collections-cmm.858
Author: cmm
Time: 4 November 2019, 7:25:14.227142 pm
UUID: 071a78c1-3ac2-4cad-b0e0-e7c2935504e1
Ancestors: Collections-pre.857

Let the printString of an OrderedDictionary reveal its key sequence.

=============== Diff against Collections-pre.857 ===============

Item was added:
+ ----- Method: Dictionary>>keysInOrder (in category 'printing') -----
+ keysInOrder
+ ^ self keysSortedSafely!

Item was changed:
----- Method: Dictionary>>printElementsOn: (in category 'printing') -----
printElementsOn: aStream
aStream nextPut: $(.
self size > 100
ifTrue: [aStream nextPutAll: 'size '.
self size printOn: aStream]
+ ifFalse: [self keysInOrder
- ifFalse: [self keysSortedSafely
do: [:key | aStream print: key;
nextPutAll: '->';
print: (self at: key);
space]].
aStream nextPut: $)!

Item was added:
+ ----- Method: OrderedDictionary>>keysInOrder (in category 'printing') -----
+ keysInOrder
+ ^ self keys!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-cmm.858.mcz

Chris Muller-3
Thanks for the code review.   Updated version in Collections-cmm.859.mcz.

-1 for choosing 'printing' as category of #keysInOrder (and #keysSortedSafely). Maybe 'accessing' instead?

Sure.  I actually did think about that, but one thing I've begun doing lately is, when I introduce an accessor _only_ because of printing, I've been starting it out in 'printing' too, for ease of collecting "related methods" together.

But, I think you're right that these could be useful accessors beyond printing (serialization?).  I moved them.
 
-1 for not having a comment in #keysInOrder ... could you explain the idea of "order" in contrast to "as is" with just a few words? :-) So that one can figure out when to use #keysSortedSafely and when to pick #keysInOrder

Hmmm... does "keys in order" sound almost like "are keys in order" and thus like a boolean result? I have no idea. :-D Did you also consider "keysOrdered" or "orderedKeys"? Just thinking about Color class >> #orderedCrayonColors.

Okay.

Thanks,
  Chris


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-cmm.858.mcz

marcel.taeumel
> ...  but one thing I've begun doing lately is, when I introduce an accessor _only_ because of printing, I've been starting it out in 'printing' too, for ease of collecting "related methods" together.

That's a good first step. However, as soon as in Trunk (or shipped for that matter), I suppose that -- for the users -- the class itself will become the first, obvious relationship for its methods. And putting it in "accessing" might also transport the information that it is actually usable in public and not like "private use for printing only".

Here is a small anecdote:

A: "Oh, you used #x instead of #position. That explains the strange behavior."
B: "Why is that?"
A: "It is in the Etoys category. Etoys uses a different coordinate system."
B: "Aha, I did not see that. Just stumbled upon #x and thought that it fits well for the morph's coordinates."

The end. :-)

Best,
Marcel

Am 06.11.2019 01:13:48 schrieb Chris Muller <[hidden email]>:

Thanks for the code review.   Updated version in Collections-cmm.859.mcz.

-1 for choosing 'printing' as category of #keysInOrder (and #keysSortedSafely). Maybe 'accessing' instead?

Sure.  I actually did think about that, but one thing I've begun doing lately is, when I introduce an accessor _only_ because of printing, I've been starting it out in 'printing' too, for ease of collecting "related methods" together.

But, I think you're right that these could be useful accessors beyond printing (serialization?).  I moved them.
 
-1 for not having a comment in #keysInOrder ... could you explain the idea of "order" in contrast to "as is" with just a few words? :-) So that one can figure out when to use #keysSortedSafely and when to pick #keysInOrder

Hmmm... does "keys in order" sound almost like "are keys in order" and thus like a boolean result? I have no idea. :-D Did you also consider "keysOrdered" or "orderedKeys"? Just thinking about Color class >> #orderedCrayonColors.

Okay.

Thanks,
  Chris