13.07.2015 Views

Smalltalk Best Practice Patterns Volume 1: Coding - Free

Smalltalk Best Practice Patterns Volume 1: Coding - Free

Smalltalk Best Practice Patterns Volume 1: Coding - Free

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SortedCollectionYou have a Collection that needs to be ordered according to some attributes of the elements.How do you sort a collection?When I was in college, sorting was a big deal. I studied Knuth. I learned a dozen clever ways tosort. I listened to all the stories about how much computing time went into sorting algorithms, andwhat an amazing impact even small improvements could have.Imagine my distress when after eleven years of <strong>Smalltalk</strong> programming I have yet to write a sortingalgorithm. All those brain cells wasted!Not wasted, of course. To be an accomplished programmer you have to know what’s going onunder the hood. It’s just that <strong>Smalltalk</strong>’s collection classes turn awareness of how sorting isimplemented into a rare and spectacular event.Just as you have collections whose order is determined by when elements were added(OrderedCollection) and unordered but efficient (Set), sorting is just another attribute of a specialkind of collection, SortedCollection.Use a SortedCollection. Set its sort block if you want to sort by some criteria other than “

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!