<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Coding: Copy/Paste then refactor</title>
	<atom:link href="http://www.markhneedham.com/blog/2009/10/31/coding-copypaste-then-refactor/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2009/10/31/coding-copypaste-then-refactor/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Tue, 16 Mar 2010 05:27:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Carlo</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-copypaste-then-refactor/comment-page-1/#comment-26123</link>
		<dc:creator>Carlo</dc:creator>
		<pubDate>Tue, 03 Nov 2009 08:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1777#comment-26123</guid>
		<description>Typically I find when working with collections that everything has been done already and I like to use the mechanisms there where possible. They may not be the most efficient but often easy to understand. I know you&#039;re learning Scala and one of the best ways is trying to do things manually so you learn the idioms etc.

Anyway after looking at the code you ended up with it reminded me of a sorted collection and a parameterised sort closure.
So in Smalltalk (sorry I haven&#039;t learned Scala yet, but Groovy would look similar) it would be something like:

&#124;min max&#124;
min := aCollectionHoldingInts asSortedCollection first.

max := aCollectionHoldingInts asSortedCollection last.
Or we could do (although slower), 
max := aCollectionHoldingInts asSortedCollection reversed last.

Alternatively if you&#039;re not storing int&#039;s in the collection but rather an object then you sould pass the sort block around:
max := aCollection asSortedCollection: [:a :b &#124; a someIntField &gt; b someIntField].

Cheers
Carlo</description>
		<content:encoded><![CDATA[<p>Typically I find when working with collections that everything has been done already and I like to use the mechanisms there where possible. They may not be the most efficient but often easy to understand. I know you're learning Scala and one of the best ways is trying to do things manually so you learn the idioms etc.</p>
<p>Anyway after looking at the code you ended up with it reminded me of a sorted collection and a parameterised sort closure.<br />
So in Smalltalk (sorry I haven't learned Scala yet, but Groovy would look similar) it would be something like:</p>
<p>|min max|<br />
min := aCollectionHoldingInts asSortedCollection first.</p>
<p>max := aCollectionHoldingInts asSortedCollection last.<br />
Or we could do (although slower),<br />
max := aCollectionHoldingInts asSortedCollection reversed last.</p>
<p>Alternatively if you're not storing int's in the collection but rather an object then you sould pass the sort block around:<br />
max := aCollection asSortedCollection: [:a :b | a someIntField &gt; b someIntField].</p>
<p>Cheers<br />
Carlo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Book Club: Working Effectively With Legacy Code &#8211; Chapter 8 (Michael Feathers) at Mark Needham</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-copypaste-then-refactor/comment-page-1/#comment-26066</link>
		<dc:creator>Book Club: Working Effectively With Legacy Code &#8211; Chapter 8 (Michael Feathers) at Mark Needham</dc:creator>
		<pubDate>Mon, 02 Nov 2009 14:17:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1777#comment-26066</guid>
		<description>[...] the section on TDD Feathers mentions the copy/paste/refactor pattern which I wrote about a few days ago. Cam pointed out that this technique allows us to get to the [...]</description>
		<content:encoded><![CDATA[<p>[...] the section on TDD Feathers mentions the copy/paste/refactor pattern which I wrote about a few days ago. Cam pointed out that this technique allows us to get to the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Ribakoff</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-copypaste-then-refactor/comment-page-1/#comment-26062</link>
		<dc:creator>Josh Ribakoff</dc:creator>
		<pubDate>Mon, 02 Nov 2009 13:27:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1777#comment-26062</guid>
		<description>Oh yeah, and I started to notice recently sometimes the 3rd function that is born ends up becoming a public method and a core part of the system&#039;s API. Maybe not in this case but take for example a method extraction in the middle of a loop, now you have a method to call when you have an object instead of a collection</description>
		<content:encoded><![CDATA[<p>Oh yeah, and I started to notice recently sometimes the 3rd function that is born ends up becoming a public method and a core part of the system's API. Maybe not in this case but take for example a method extraction in the middle of a loop, now you have a method to call when you have an object instead of a collection</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Ribakoff</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-copypaste-then-refactor/comment-page-1/#comment-26061</link>
		<dc:creator>Josh Ribakoff</dc:creator>
		<pubDate>Mon, 02 Nov 2009 13:24:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1777#comment-26061</guid>
		<description>Kent Beck uses this method as his introduction to TDD, he had me sold right away.</description>
		<content:encoded><![CDATA[<p>Kent Beck uses this method as his introduction to TDD, he had me sold right away.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
