<?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"
	>
<channel>
	<title>Comments on: Implementation Patterns emerging</title>
	<atom:link href="http://upstream-berlin.com/2007/12/03/implementation-patterns-emerging/feed/" rel="self" type="application/rss+xml" />
	<link>http://upstream-berlin.com/2007/12/03/implementation-patterns-emerging/</link>
	<description></description>
	<pubDate>Wed, 20 Aug 2008 07:18:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: eno</title>
		<link>http://upstream-berlin.com/2007/12/03/implementation-patterns-emerging/#comment-6597</link>
		<dc:creator>eno</dc:creator>
		<pubDate>Fri, 28 Dec 2007 11:58:56 +0000</pubDate>
		<guid isPermaLink="false">http://upstream-berlin.com/blog/2007/12/03/implementation-patterns-emerging/#comment-6597</guid>
		<description>I like that, this last one is quite expressive...</description>
		<content:encoded><![CDATA[<p>I like that, this last one is quite expressive&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander Lang</title>
		<link>http://upstream-berlin.com/2007/12/03/implementation-patterns-emerging/#comment-6568</link>
		<dc:creator>Alexander Lang</dc:creator>
		<pubDate>Thu, 27 Dec 2007 17:07:13 +0000</pubDate>
		<guid isPermaLink="false">http://upstream-berlin.com/blog/2007/12/03/implementation-patterns-emerging/#comment-6568</guid>
		<description>Nice idea, although I think this gets close to overengineering, but that's just my personal taste. The problem with this is that in the meantime we have changed the keys in the hash to regular expressions and now using method names would not work anymore. What we could do now is to use blocks again instead of methods:

&lt;code&gt;
class Renderers
  renderer /video\.google\.(de&#124;com)/ do &#124;url&#124;
    "video.google.com/${url}"
  end
end
&lt;/code&gt;

This should probably build up another Hash again but then we surely end up with overengineered code. But expressive. Maybe. :)

(any suggestions for comment preview/code plugins for wordpress?)</description>
		<content:encoded><![CDATA[<p>Nice idea, although I think this gets close to overengineering, but that&#8217;s just my personal taste. The problem with this is that in the meantime we have changed the keys in the hash to regular expressions and now using method names would not work anymore. What we could do now is to use blocks again instead of methods:</p>
<p><code><br />
class Renderers<br />
  renderer /video\.google\.(de|com)/ do |url|<br />
    "video.google.com/${url}"<br />
  end<br />
end<br />
</code></p>
<p>This should probably build up another Hash again but then we surely end up with overengineered code. But expressive. Maybe. <img src='http://upstream-berlin.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>(any suggestions for comment preview/code plugins for wordpress?)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eno</title>
		<link>http://upstream-berlin.com/2007/12/03/implementation-patterns-emerging/#comment-6561</link>
		<dc:creator>eno</dc:creator>
		<pubDate>Thu, 27 Dec 2007 12:28:27 +0000</pubDate>
		<guid isPermaLink="false">http://upstream-berlin.com/blog/2007/12/03/implementation-patterns-emerging/#comment-6561</guid>
		<description>Having at least one way to insert actual code here and/or some kind of preview: *that* would be great. I would even trade in smileys ;-)</description>
		<content:encoded><![CDATA[<p>Having at least one way to insert actual code here and/or some kind of preview: *that* would be great. I would even trade in smileys <img src='http://upstream-berlin.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eno</title>
		<link>http://upstream-berlin.com/2007/12/03/implementation-patterns-emerging/#comment-6560</link>
		<dc:creator>eno</dc:creator>
		<pubDate>Thu, 27 Dec 2007 12:26:57 +0000</pubDate>
		<guid isPermaLink="false">http://upstream-berlin.com/blog/2007/12/03/implementation-patterns-emerging/#comment-6560</guid>
		<description>Ruby offers you a more elegant way of doing this. Remember: an object is more or less a hash matching ids to Proces. So your code could be 

&lt;code&gt;
class Video  
  class Renderers
    def self.youtube(url)
      "player.youtube.com/#{url}"
    end

    def self.vimeo(url)
      "vimdeo.com/player/#{url}/1"
    end
  end

  def html   
    renderers = self.class.Renderers 
    provider = renderers.public_methods.
      find { &#124;met&#124; @url.include?(met)}

    renderers.send provider, @url
  end
end
&lt;/code&gt;

2 lines less, no ugly lambdas, no Proc object (which makes that thing faster), Ruby class magic still possible etc.

You could even embed the actual renderers into a module which you would then mix into the Video class: no need to pass url any longer ;-)

BTW: It appears your code iterates over *all* renderers, not only over the first one.

See you @ CCC?</description>
		<content:encoded><![CDATA[<p>Ruby offers you a more elegant way of doing this. Remember: an object is more or less a hash matching ids to Proces. So your code could be </p>
<p><code><br />
class Video<br />
  class Renderers<br />
    def self.youtube(url)<br />
      "player.youtube.com/#{url}"<br />
    end</p>
<p>    def self.vimeo(url)<br />
      "vimdeo.com/player/#{url}/1"<br />
    end<br />
  end</p>
<p>  def html<br />
    renderers = self.class.Renderers<br />
    provider = renderers.public_methods.<br />
      find { |met| @url.include?(met)}</p>
<p>    renderers.send provider, @url<br />
  end<br />
end<br />
</code></p>
<p>2 lines less, no ugly lambdas, no Proc object (which makes that thing faster), Ruby class magic still possible etc.</p>
<p>You could even embed the actual renderers into a module which you would then mix into the Video class: no need to pass url any longer <img src='http://upstream-berlin.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>BTW: It appears your code iterates over *all* renderers, not only over the first one.</p>
<p>See you @ CCC?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
