<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>MemeRocket &#187; Ruby</title>
	<atom:link href="http://memerocket.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://memerocket.com</link>
	<description>Bill Burcham's Launch Platform</description>
	<lastBuildDate>Sun, 19 Feb 2012 03:56:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='memerocket.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/048c0b3b1b3b5279e320104a4b5d0bb0?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>MemeRocket &#187; Ruby</title>
		<link>http://memerocket.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://memerocket.com/osd.xml" title="MemeRocket" />
	<atom:link rel='hub' href='http://memerocket.com/?pushpress=hub'/>
		<item>
		<title>Go Quacks Right</title>
		<link>http://memerocket.com/2009/11/16/go-quacks-right/</link>
		<comments>http://memerocket.com/2009/11/16/go-quacks-right/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 00:20:35 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[duck typing]]></category>
		<category><![CDATA[go]]></category>

		<guid isPermaLink="false">http://memerocket.com/?p=282</guid>
		<description><![CDATA[In Ruby Module#include at Odds with Duck Typing I lamented the fact that Ruby wouldn&#8217;t treat an object as an Enumerable unless that object included the Enumerable interface explicitly. Well Google&#8217;s new Go language has no such limitation. If it quacks, &#8230; <a href="http://memerocket.com/2009/11/16/go-quacks-right/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=282&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://memerocket.com/2006/09/28/ruby-moduleinclude-at-odds-with-duck-typing/">Ruby Module#include at Odds with Duck Typing</a> I lamented the fact that Ruby wouldn&#8217;t treat an object as an Enumerable unless that object included the Enumerable interface explicitly.</p>
<p>Well Google&#8217;s new Go language has no such limitation. <a href="http://golang.org/doc/go_lang_faq.html#types">If it quacks, it really is a duck in Go</a>:</p>
<blockquote><p>Rather than requiring the programmer to declare ahead of time that two types are related, in Go a type automatically satisfies any interface that specifies a subset of its methods. Besides reducing the bookkeeping, this approach has real advantages. Types can satisfy many interfaces at once, without the complexities of traditional multiple inheritance. Interfaces can be very lightweight—having one or even zero methods in an interface can express useful concepts. Interfaces can be added after the fact if a new idea comes along or for testing—without annotating the original types. Because there are no explicit relationships between types and interfaces, there is no type hierarchy to manage or discuss.</p></blockquote>
<p>Well…there it is.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=282&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2009/11/16/go-quacks-right/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>OOCSS + SASS = Fewer Classes On Your Elements</title>
		<link>http://memerocket.com/2009/03/28/oocss-sass-fewer-classes-on-your-elements/</link>
		<comments>http://memerocket.com/2009/03/28/oocss-sass-fewer-classes-on-your-elements/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 23:44:06 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://memerocket.com/?p=164</guid>
		<description><![CDATA[update 3/29/2009 8:23 AM: Turns out Chris Eppstein is way ahead of me. Check out Compass. It&#8217;s a project that delivers your favorite CSS frameworks as SASS mix-ins. Oh and also it integrated with your favorite Ruby web development framework. Stubbornella &#8230; <a href="http://memerocket.com/2009/03/28/oocss-sass-fewer-classes-on-your-elements/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=164&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>update</strong> 3/29/2009 8:23 AM: Turns out <a href="http://acts-as-architect.blogspot.com/">Chris Eppstein</a> is way ahead of me. Check out <a href="http://compass-style.org/">Compass</a>. It&#8217;s a project that delivers your favorite <a href="http://wiki.github.com/chriseppstein/compass/supported-frameworks">CSS frameworks</a> as SASS mix-ins. Oh and also it integrated with your favorite Ruby web development framework.</p>
<p>Stubbornella you have captivated me. I am now watching <a href="http://www.stubbornella.org/content/">Nicole Sullivan</a>&#8216;s <a href="http://www.stubbornella.org/content/2009/03/23/object-oriented-css-video-on-ydn/">Object Oriented CSS talk</a> for the second time. The <a href="http://wiki.github.com/stubbornella/oocss">OOCSS framework</a> is a terse but ambitious thing in the tradition of <a href="http://developer.yahoo.com/yui/grids/">YUI Grids CSS</a> and <a href="http://www.blueprintcss.org/">Blueprint</a> but with opinions that reach beyond grids, resets and typography.</p>
<p>While I have certainly not mastered the OOCSS concepts I do have some early observations I&#8217;d like to share nevertheless. This of course is dangerous territory since I risk having to eat my words later. So be it. Feel free to feed ’em to me as appropriate…</p>
<p>It strikes me from looking at the <a href="http://wiki.github.com/stubbornella/oocss/uml">UML diagram</a> for OOCSS that something is missing, or more accurately, some things are being conflated which shouldn&#8217;t be. If we&#8217;re thinking about objects and classes here the first question should be: what are we modeling? Well the <a href="http://en.wikipedia.org/wiki/HTML#Semantic_HTML">semantic HTML</a> folks might say we need to model things like paragraphs and headings, or at another level contacts and phone numbers, or at another level sidebars and navigation. These are all semantics.</p>
<p>When we think about modeling these things in HTML in such as way that CSS can be profitably applied, we use HTML element types to directly model semantics where we can (p element for paragraph, h1 element for top-level heading) and we use class attributes to express the rest (&#8216;top-nav&#8217;, &#8216;address&#8217;, &#8216;phone&#8217;). If you have a look at the OOCSS UML diagram you will see in the &#8220;page layout&#8221; section a set of classes that fall into the former category ( &#8216;doc&#8217;, &#8216;hd&#8217; for header, &#8216;bd&#8217; for body, &#8216;ft&#8217; for footer).</p>
<p>So far so good. But now how do we actually extend a class? The approach suggested in OOCSS is to change the (HTML) markup. One example from the talk is to specialize the media block class &#8216;media&#8217; so that the fixed-size media is on the right instead of on the left. The suggestion is to define a new class &#8216;media_ext&#8217; along with a new set of CSS rules. Then the idea is to change our HTML so that the element of interest carries two classes: &#8216;media&#8217; and &#8216;media_ext&#8217;. And then we define some CSS for the new media_ext module, something like this:</p>
<pre>.media_ext .fixedMedia { float:right }</pre>
<p>This is the fundamental approach in OOCSS, so fundamental that it is on the short list of <em>10 Best Practices</em> from slide 19 of <a href="http://www.slideshare.net/stubbornella/object-oriented-css">the talk</a>:</p>
<p style="padding-left:30px;">9. Extend objects by applying multiple classes to an element</p>
<p>The library defines a small set of base classes and a few core extensions to those. Users are invited to extend these further and we change our HTML to carry the full set of classes expressing semantics, layout and skinning too, all as separate classes.</p>
<p>The value in this approach is it certainly brings order to chaos. The downside is twofold: first we must pollute our HTML with layout and skinning choices and second, we must rely solely on coding conventions to ensure that each HTML element carries a self-consistent and complete set of classes.</p>
<p style="padding-left:30px;">aside: To me this feels much more akin to structured programming or maybe at best &#8220;abstract data types&#8221; than it does OO. I don&#8217;t really see language-level inheritance here, nor do I see polymorphism. But that&#8217;s just a terminological nit.</p>
<p>The first problem we need to solve is to get rid of the superfluous classes (on our elements). How could we make a media block (&#8220;fixed-width media object on the left with an open editable zone on the right&#8221;) into a right-handed media block without changing our HTML? Well the classic way in CSS is to use context to distinguish this situation. So let&#8217;s imagine that every odd media block ought to be right-handed. A classic approach is to have an &#8216;odd&#8217; class on the element (or to use nth-child pseudo class). Perhaps something like this:</p>
<pre>.media.odd .fixedMedia { float:right }</pre>
<p>Where target is the fixed-width object we&#8217;d like to be on the right-hand side instead of the left. You get the idea. The problem with this approach is that we&#8217;ve just coded up some potentially reusable stuff (the {float:right} part) and we&#8217;ve got no way to reuse it in other circumstances. Also we are now guilty of committing pitfall #1 from the talk:</p>
<p style="padding-left:30px;">1. Location dependent styles</p>
<p>So you can see that we are definitely violating a key tennet of OOCSS. If you&#8217;re already an OOCSS dogmatist you may want to stop reading now. Still with me? OK, what if we want a right-hand media block for even rows next time? We&#8217;d have to edit that last CSS rule to look something like this:</p>
<pre>.media.even .fixedMedia { float:right }</pre>
<p>Yuck. What&#8217;s going on here? The problem is that CSS has no named/reusable/callable construct. No macro. No function. No Class. OOCSS does the best it can with plain old CSS by requiring us to define a new HTML class name. That lets us define a reusable set of CSS rules for it, but at the cost of polluting our HTML at each use.</p>
<p>I think a good way out of this is to break out of plain old CSS into a higher realm. Both <a href="http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html">SASS</a> and <a href="http://shauninman.com/archive/2007/06/27/css_server_side_pre_processor">CSS-SSC</a> have a macro concept. SASS has its mixins and CSS-SSC has its base and based-on. What these actually add to CSS is named abstractions and reuse. So I could define a SASS mixin like this:</p>
<pre>=right-hand-media
  .fixedMedia
    float: right</pre>
<p>Now that is a reusable module. In my application I can apply that module to an element:</p>
<pre>.media.odd
  +right-hand-media</pre>
<p>Yay. Now I have the best of both worlds. If we have another app that wants even media items to be right-handed then we just define this:</p>
<pre>.media.even
  +right-hand-media</pre>
<p>The value of this is that I didn&#8217;t have to change my HTML markup in order to change the layout. There are examples of using the same approach to define a <a href="http://wonderfullyflawed.com/2008/05/21/clearfix-as-mixin/">clearfix module</a>. To those who say this approach is going to generate a lot of CSS I say, &#8220;well maybe, but I think our first priority needs to be making our source code manageable and this approach may just help us do that.&#8221;</p>
<p>As I already pointed out, this proposal (using SASS mix-ins or CSS-SSC macros to implement reusable modules, and then using contextual CSS Rules to apply those modules) violates a core principle of OOCSS. On the upside it solves one of the wish list items from the <a href="http://www.slideshare.net/stubbornella/object-oriented-css">talk</a> (on slide 60):</p>
<p style="padding-left:30px;">1. Extending objects—possible to make &#8220;sale module&#8221; inherit from &#8220;module&#8221;</p>
<p style="padding-left:30px;">
<pre>.module{}
.saleModule{extends: module}</pre>
<p>Now that approach is a bit different from the one I described for right-hand-media. But it is clear that mix-ins or macros could easily be used to reuse .module in .saleModule right? SASS mix-ins, for instance can be used (as in my first example) as straight-up mix-ins, or to implement inheritance. The choice is yours.</p>
<p>To close, I highly recommend watching the <a href="http://us.dl1.yimg.com/download.yahoo.com/dl/ydn/nicolesullivan.m4v">Stubbornella&#8217;s presentation</a>. <strong>Twice</strong>. There is just a ton of gold in there. Meanwhile, I&#8217;ll go experiment with SASS mix-ins and let you know how it works in practice and how it can be combined with some of the other principles highlighted in the talk.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=164&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2009/03/28/oocss-sass-fewer-classes-on-your-elements/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
<enclosure url="http://us.dl1.yimg.com/download.yahoo.com/dl/ydn/nicolesullivan.m4v" length="583962269" type="video/x-m4v" />
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>Are Ruby Session ID&#8217;s Secure?</title>
		<link>http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/</link>
		<comments>http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 01:47:15 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://meme-rocket.com/2008/10/14/are-ruby-session-ids-secure/</guid>
		<description><![CDATA[The question of the security of cookie-based session storage in Rails has pretty much been settled it seems to me. Out of the box, Rails uses cookie-based session storage. When you generate a new Rails app you get a nice &#8230; <a href="http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=110&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The question of the security of cookie-based session storage in Rails has pretty much been settled it seems to me. <a href="http://ryandaigle.com/articles/2007/2/21/what-s-new-in-edge-rails-cookie-based-sessions">Out of the box</a>, Rails uses cookie-based session storage. When you generate a new Rails app you get a nice new 128 character long (numbers and lowercase letters) secret set in config.action_controller.session[:secret] in your Rails::Initializer. That secret is used to sign and validate cookies for your application. Now the cookie data isn&#8217;t secret mind you, but it is tamper-proof. Good.</p>
<p>Now what if you don&#8217;t use cookie-based session storage at all? Well, just because you aren&#8217;t using cookie-based session storage doesn&#8217;t mean you aren&#8217;t using cookies. If your application has sessions at all, be they memcached ones or ActiveRecord ones, it is probably using cookies. It&#8217;s using cookies to <a href="http://www.quarkruby.com/2007/10/21/sessions-and-cookies-in-ruby-on-rails#sinrails">store the session id</a> so that when a request arrives, that id can be mapped to the corresponding session storage.</p>
<p>&#8220;So what&#8221; you say. &#8220;Well&#8221; I say… isn&#8217;t it cool that Rails generates that big random secret for you when you use cookie-based session storage? When we are not using cookie-based session storage, and that secret is not generated, don&#8217;t you wonder what secret is being used to secure your session id&#8217;s? You see, a <a href="http://www.technicalinfo.net/papers/WebBasedSessionManagement.html">session id must be hard to guess</a> lest bad people <a href="http://www.cgisecurity.com/lib/SessionIDs.pdf">gain access to your site</a>. Usually when you want to make something hard to guess, you start with a secret and mix that with something that changes a lot and hash the whole shebang. So I went in search of this other secret.</p>
<p>What I found was that Rails calls <a href="http://corelib.rubyonrails.org/classes/CGI/Session.html#M000366">CGI::Session#create_new_id</a> to generate new session id&#8217;s. That routine uses no secrete per se. It hashes (MD5) a combination of:</p>
<ol>
<li>the current date and time (expressed as a human-readable string)</li>
<li>the microseconds elapsed since the last second (expressed as a human-readable string)</li>
<li>a pseudo-random number greater than zero and less than one (from Kernel#rand)</li>
<li>the current process id number</li>
<li>the string &#8216;foobar&#8217;</li>
</ol>
<p>Notice there is no secret keying material there. &#8220;But what about the Kernel#rand call Bill!&#8221; I hear you saying. If you go have a look at <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005977">Kernel#rand</a> and <a href="http://www.ruby-doc.org/core/classes/Kernel.html#M005976">Kernel#srand</a> you&#8217;ll see that if rand is called before srand is called with a number parameter then the random number will be generated from a combination of:</p>
<ol>
<li>the current time</li>
<li>the process id number</li>
</ol>
<p>So the security of these session ids hinges on the secrecy of current time (on the server running Ruby) and the process id. Given that the system time is returned in HTTP headers and process id&#8217;s are often in the hundreds or thousands, it&#8217;s only really the microseconds that are hard to guess here, from a statistical standpoint. <a href="http://www.nycbsdcon.org/2006/files/BSDRailsBenninger.pdf">Others have expressed</a> similar concerns.</p>
<p>If you&#8217;re worried about this two suggestions come to mind:</p>
<ul>
<li>time out sessions on the server so that an attacker has to guess faster</li>
<li>monkey-patch <a href="http://corelib.rubyonrails.org/classes/CGI/Session.html#M000366">CGI::Session#create_new_id</a> to hash its result with a great big old 128 character secret</li>
</ul>
<p><strong>Updated</strong>: October 15, 2008 expanded analysis of Kernel#rand and Kernel#srand and updated suggestions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/110/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/110/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/110/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=110&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2008/10/14/are-ruby-session-ids-secure/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby Performance on Various VM&#8217;s</title>
		<link>http://memerocket.com/2007/09/17/ruby-performance-on-various-vms/</link>
		<comments>http://memerocket.com/2007/09/17/ruby-performance-on-various-vms/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 18:36:54 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[diversion]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2007/09/17/ruby-performance-on-various-vms/</guid>
		<description><![CDATA[What started a few days ago as a little tinkering with a Google Code Jam practice problem (Big City Skyline) turned into a mini-benchmark of three Ruby VM&#8217;s on my MacBook Pro 2.2GHz. The program (a solution to the &#8220;Big &#8230; <a href="http://memerocket.com/2007/09/17/ruby-performance-on-various-vms/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=87&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What started a few days ago as a little tinkering with a <a href="http://googleblog.blogspot.com/2007/09/our-plans-for-code-jam.html">Google Code Jam</a> practice problem (Big City Skyline) turned into a mini-benchmark of three Ruby VM&#8217;s on my MacBook Pro 2.2GHz. The program (a solution to the &#8220;Big City Skyline&#8221; problem) is an O( N log( N ) ) in-memory search with a little integer math.</p>
<p>Quickie findings: the in-development Ruby 1.9 VM performed best &#8212; beating 1.8.6 by a factor of two. For the numbers (comparing 1.8.6, 1.9 pre-release, and Rubinius pre-release) have a look at the <a href="http://spreadsheets.google.com/pub?key=p1qlnCJRXgyIG-9uhSAnHBw">spreadsheet and chart</a> over on Google Docs. Also of note: the Ruby solution did beat the four minute time limit for N=10MM given in the <a href="http://services.google.com/blog_resources/Google_CodeJam_Practice.pdf">problem statement</a>. This was on random input. Worst-case performance would not be as good.</p>
<p>It makes me happy that the <a href="http://pastie.caboo.se/98009">Ruby solution</a> had adequate performance. Also it was interesting to see how the Ruby language fit for a problem you&#8217;d usually see done in LISP. I would have liked to have dynamic scope to do a cleaner implementation of @@largest_so_far. On the other hand, &#8220;memoization&#8221; is pretty natural in an OO language like Ruby &#8212; you create an instance (of Skyline) for each context and simply use instance variables to hold previous results.</p>
<p><strong>update</strong> Nov 15, 2007: Reader Sumudu points out that <a href="http://pastie.caboo.se/98009">version 5</a> neglects to reset the timer between pruning and non-pruning variations. <a href="http://pastie.caboo.se/118616">Version 6</a> rectifies this error. With that change it&#8217;s apparent that the pruning has no positive effect. In fact non-pruning actually wins by a small amount for N=1 to N=100,000 on my MacBook Pro.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/87/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/87/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=87&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2007/09/17/ruby-performance-on-various-vms/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby Module#include at Odds with Duck Typing.</title>
		<link>http://memerocket.com/2006/09/28/ruby-moduleinclude-at-odds-with-duck-typing/</link>
		<comments>http://memerocket.com/2006/09/28/ruby-moduleinclude-at-odds-with-duck-typing/#comments</comments>
		<pubDate>Thu, 28 Sep 2006 23:11:05 +0000</pubDate>
		<dc:creator>Bill Burcham</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.meme-rocket.com/2006/09/28/ruby-moduleinclude-at-odds-with-duck-typing/</guid>
		<description><![CDATA[Ruby Module#include is at odds with Duck Typing. Imagine I&#8217;ve got a perfectly good class that produces the numbers 1 thru 5: I can of course invoke each with a block and print the numbers out: With predictable results. But &#8230; <a href="http://memerocket.com/2006/09/28/ruby-moduleinclude-at-odds-with-duck-typing/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=22&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ruby Module#include is at odds with <a title="Duck Typing" target="_blank" href="http://en.wikipedia.org/wiki/Duck_typing">Duck Typing</a>. Imagine I&#8217;ve got a perfectly good class that produces the numbers 1 thru 5:</p>
<p> </iframe>I can of course invoke each with a block and print the numbers out:</p>
<p> </iframe></p>
<p>With predictable results.  But I cannot use a Nums as if it were Enumerable (unless I include Enumerable in the definition).  So this:</p>
<p> </iframe></p>
<p>Yields &#8220;<span style="font-family:courier new,monospace;">undefined method `collect&#8217; for # (NoMethodError) </span>&#8220;</p>
<p>Folks who know Ruby will say &#8220;well &#8212; you have to include Enumerable&#8221;.  To which I say &#8220;Nums already quacks like an Enumerable doesn&#8217;t it?&#8221;  Or, more accurately &#8212; Nums quacks like something that satisfies the (un-named) interface that an object must implement in order to include Enumerable (to <span style="font-style:italic;">be</span> enumerable).  Nums implements the each method, which is all that Enumerable needs (so long as no one calls the ordering methods on Enumerable).</p>
<p>It just seems kind of wrong that I have to either include Enumerable directly in my class &#8212; or I have to explicitly add the interface after the fact using one of Object#extend (on a Nums instance), Object#instance_eval (on Nums), Module#include or Module#append_features on Nums, or by writing another class decl for Nums to extend it that way.)</p>
<p>The underlying issue here is that there&#8217;s no <a target="_blank" href="http://en.wikipedia.org/wiki/Generic_function">generic functions</a> in Ruby.  Topher Cyll has implemented a  <a target="_blank" href="http://multi.rubyforge.org/">multiple dispatch</a> gem for Ruby that does something similar.  It&#8217;s not quite generic functions though because dispatch is scoped to a target object (receiver of message) whereas generic functions (in general) pattern match on all parameters &#8212; including message target.</p>
<p>So I got to playing around a little.  I reasoned I could use method_missing to mixin Enumerable and others at runtime like this:</p>
<p> </iframe></p>
<p>Then I could just &#8220;<span style="font-family:courier new,monospace;">include RespondsToGenerics</span>&#8221; in classes I wanted to have this behavior.  It&#8217;s still ugly that I have to include anything, but hey &#8212; it&#8217;s a start.  &#8216;course what I got then was:</p>
<div style="margin-left:40px;"><span style="font-family:courier new,monospace;"> in `bind&#8217;: bind argument must be an instance of Enumerable (TypeError)</span></div>
<p>Cuz Ruby won&#8217;t let me bind an Enumerable method to an Object that doesn&#8217;t include Enumerable.  Augh!!  In what way is that behavior aligned with the <strong>Zen of Duck Typing</strong>?  I quack like a duck!  Trust me Ruby.  Back to the drawing board.</p>
<p>So to make this work I think I need to create a full-fledged proxy object (that includes all the interfaces in question).  Then I can wrap each object (in method_missing) with the wrapper and the wrapper can forward the message using Object#send.  But hang on, if the wrapper includes all the interfaces in question then I&#8217;ll have to use Module#undef_method to undef all the methods of the included interfaces so that method_missing gets called.  Double-ugh.  Thinking.  Thinking&#8230;</p>
<p>What I really want is for the Nums class definition to be devoid of any code pertaining to (what should be) the generic mixins.  What I really want is to introspect when Nums is defined &#8212; and if Nums implements the required protocol: namely, that Nums implements an each method, then Nums should get &#8220;tagged&#8221; with the Enumerable interface.  Something like this say:</p>
<p> </iframe></p>
<p>The idea is that I should be able to explicitly and in one place declare in any mixin module the <em>requirements</em> that module has on classes you might wish to mix it into.  If I could do that then maybe I could make the actual mixing happen automatically &#8212; yielding mixins that are composed environmentally &#8212; not at each point of use.  I really like the fact that this approach reifies the requirements on the target class.  For example you can see that to mix in Enumerable the &#8220;each&#8221; method must be defined.  It&#8217;s in code now &#8212; not just buried in the Pick Axe book.</p>
<p>Now implementing mix_in_when is pretty straightforward.  We define it in class Module and we keep track of the predicate passed.  Then some time <em>later</em> we want to do the mixing.  That&#8217;s where the questions arise.</p>
<p>When should we do the mixing? I was initially tempted to try and redefine Class::new (a class method.)  See, I could just hook creations of instances of class Class and at that point I&#8217;d have control and I could evaluate the predicates for the new class and inject the modules as appropriate.  This turned out to be problematic for a couple reasons.</p>
<p>First off, hooking Class::new doesn&#8217;t work in <a title="ruby list thread 23318" href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/23318">all cases</a>.  In particular Class::new doesn&#8217;t get invoked when the class Foo;end syntax is used.  Class::new is invoked only when the Class.new syntax is used.  Then there&#8217;s the Class::inherited approach which <a title="ruby list thread 194052" href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/194052">does get</a> called in all cases but it still wouldn&#8217;t really be what we want.  Again I hear the crescendo of the Ruby cognescenti.  Ruby class definition is <em>dynamic</em>.  The various syntactic forms used to define program elements such as methods, instance variables and the like are mostly method invocations &#8212; evaluated not at compile time as those of us brutalized by long years of C, C++ and Java have been conditioned to expect (bell dings, Bill drools) &#8212; but evaluated at runtime.  As a result, even if you hooked Class::initialize the actual class of interest wouldn&#8217;t have its methods defined yet.  The method definition code runs in the context of the newly created Class object.  And let&#8217;s say you could get a hook called after that initial method definition code ran.  You wouldn&#8217;t be sure even then that the class wasn&#8217;t going to change on you &#8212; since idiomatic Rubyists are continually modifying other peoples&#8217; classes at runtime &#8212; adding methods, adding variables.</p>
<p>Nope, there&#8217;s no easy way around the fact that you the programmer are going to have to choose when to perform the Big Mixing Act.  For some applications you may even want to do it repeatedly.  So here&#8217;s what the code actually looks like (I call it auto_mixins.rb):</p>
<p> </iframe></p>
<p>With that code required in your project you can call Module.AddAutomaticMixins and begin using any conformant object as though it were Enumerable &#8212; without ever including Enumerable in the class yourself.  Similarly for Comparable.  Here&#8217;s an example:</p>
<p> </iframe></p>
<p>Run it yourself and see.  Is it something I&#8217;m dying to use in my next project?  Well I&#8217;m not sure.  My head is still spinning. In a good way.  At this point it&#8217;s more of a thought experiment.  I&#8217;m curious what other folks think about the general idea.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/memerocket.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/memerocket.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/memerocket.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/memerocket.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/memerocket.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/memerocket.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/memerocket.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/memerocket.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/memerocket.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/memerocket.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/memerocket.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/memerocket.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/memerocket.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/memerocket.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/memerocket.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/memerocket.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=memerocket.com&#038;blog=5432592&#038;post=22&#038;subd=memerocket&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://memerocket.com/2006/09/28/ruby-moduleinclude-at-odds-with-duck-typing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a88a8da103044de18418f303bf0c1507?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">bburcham</media:title>
		</media:content>
	</item>
	</channel>
</rss>
