<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
	<channel>
		<title>GFX Monk</title>
		
		<link>http://gfxmonk.net</link>
		<description />
		<generator>http://chyrp.net/</generator>
		<language>en</language>
		<pubDate>Sat, 02 May 2009 01:33:20 +1000</pubDate>
		<docs>http://backend.userland.com/rss2</docs>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/gfxmonk" type="application/rss+xml" /><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.</feedburner:browserFriendly><item>
			<title>Entirely too much investigation into ruby's match operator</title>
						<link>http://feedproxy.google.com/~r/gfxmonk/~3/kgWEmSBoXjo/</link>
			
			<description>&lt;p&gt;(how could a title like that &lt;em&gt;not&lt;/em&gt; excite you! ;P)&lt;/p&gt;

&lt;p&gt;So yesterday I had this weird regex issue in ruby. I wanted to get a regular expression containing a given string, but didn't want to have to manually escape all the special characters. &lt;code&gt;Regexp.escape&lt;/code&gt; to the rescue! It escapes all regex metacharacters in any given string, and returns it as a regex. In fact, the docs assure me:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;For any string, &lt;code&gt;Regexp.escape(str)=~str&lt;/code&gt; will be true.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But not so much in practice?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; str = "123"            
=&amp;gt; "123"
&amp;gt;&amp;gt; Regexp.escape(str)=~str
TypeError: type mismatch: String given
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;br /&gt;
So, problem one: &lt;strong&gt;Regexp.escape is broken&lt;/strong&gt;. It returns not a Regexp, but a string. Oddly enough it also seems to escape spaces and other innocuous characters, but at least you get the right result if you pump it through &lt;code&gt;Regexp.compile()&lt;/code&gt;. However, that wasn't my only discovery.&lt;/p&gt;

&lt;p&gt;I mentioned this to Matt, and he couldn't make much sense of it either. He noticed that the type error is specific to strings - if you use a number it just returns false:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; 123 =~ 'foo'
=&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Seems a bit odd, really. Fixnum doesn't implement &lt;code&gt;=~&lt;/code&gt;, nor does Integer.&lt;/p&gt;

&lt;p&gt;So I went doc spelunking. I found implementations for &lt;code&gt;=~&lt;/code&gt; in the following three important classes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regexp&lt;/strong&gt;: &lt;code&gt;regexp =~ str&lt;/code&gt;: do a regex match, as you might expect&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt;: &lt;code&gt;str =~ obj&lt;/code&gt;: Call obj =~ str (i.e swap the order of your operands). Not mentioned in the docs but clearly apparent in the source (and experimentation): raise a TypeError if both arguments are strings. Without this, matching one string to another would very quickly run out of stack space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object&lt;/strong&gt;: &lt;code&gt;obj =~ other_obj&lt;/code&gt;: return false&lt;/p&gt;

&lt;p&gt;So the Regexp implementation is fine. The String implementation is a little odd. I guess it's there to allow people to write matching statements either way, but it seems like a dangerous (and confusing) habit to condone.&lt;/p&gt;

&lt;p&gt;But the Object implementation? &lt;em&gt;Why???&lt;/em&gt; What possible reason could one have for doing a match operation against two objects, neither of which implement any matching behaviour? This has the painful side effect of giving every single object I inspect a "=~" method which does nothing. No wonder &lt;code&gt;Object.new()&lt;/code&gt; has over 120 methods on it &lt;sup&gt;&amp;#42;&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;For comparison, python's &lt;code&gt;object&lt;/code&gt; only has 12 methods / attributes. And they're all &lt;em&gt;&lt;strong&gt;special&lt;/strong&gt;&lt;/em&gt; names, so there's no pollution of regular names going on.&lt;/p&gt;

&lt;p&gt;So there you go, two spoonfuls of broken in the one discovery!&lt;/p&gt;

&lt;p&gt;(this is ruby 1.8.6, if that matters)&lt;/p&gt;

&lt;p&gt;&lt;sub&gt;* I exaggerate, over 120 methods on object are just what you get in a rails app. Vanilla ruby only has 41 by my count. but it's still completely unnecessary, and adds noise to inflate that number&lt;/sub&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gfxmonk/~4/kgWEmSBoXjo" height="1" width="1"/&gt;</description>
			<pubDate>Sat, 02 May 2009 01:33:20 +1000</pubDate>
						<guid isPermaLink="false">http://gfxmonk.net/?action=view&amp;url=entirely-too-much-investigation-into-rubys-match-operator</guid>
			<dc:creator>Tim Cuthbertson</dc:creator>
		<feedburner:origLink>http://gfxmonk.net/?action=view&amp;url=entirely-too-much-investigation-into-rubys-match-operator</feedburner:origLink></item>
		<item>
			<title>ruby dataflow library</title>
						<link>http://feedproxy.google.com/~r/gfxmonk/~3/mOywRO1_lH4/</link>
			
			<description>&lt;a href="http://github.com/larrytheliquid/dataflow/tree/master"&gt;ruby dataflow library&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Pretty cool, I worry that such things can't easily be done so cleanly in python...&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gfxmonk/~4/mOywRO1_lH4" height="1" width="1"/&gt;</description>
			<pubDate>Tue, 28 Apr 2009 21:28:33 +1000</pubDate>
						<guid isPermaLink="false">http://gfxmonk.net/?action=view&amp;url=link.324</guid>
			<dc:creator>Tim Cuthbertson</dc:creator>
		<feedburner:origLink>http://gfxmonk.net/?action=view&amp;url=link.324</feedburner:origLink></item>
		<item>
			<title>Germany Institutes Censorship Infrastructure</title>
						<link>http://feedproxy.google.com/~r/gfxmonk/~3/CiHXMokFkK8/</link>
			
			<description>&lt;a href="http://yro.slashdot.org/article.pl?sid=09/04/23/0319217&amp;from=rss"&gt;Germany Institutes Censorship Infrastructure&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;At least our ISPs have a bit more guts, apparently in Germany &lt;a href="http://www.dw-world.de/dw/article/0,,4185666,00.html"&gt;five of the largest ISPs have already agreed to voluntarily submit to the process even without a law in place&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Or maybe Australian ISPs are just too lazy to implement internet filtering until they have to ;)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gfxmonk/~4/CiHXMokFkK8" height="1" width="1"/&gt;</description>
			<pubDate>Mon, 27 Apr 2009 20:43:14 +1000</pubDate>
						<guid isPermaLink="false">http://gfxmonk.net/?action=view&amp;url=link.323</guid>
			<dc:creator>Tim Cuthbertson</dc:creator>
		<feedburner:origLink>http://gfxmonk.net/?action=view&amp;url=link.323</feedburner:origLink></item>
		<item>
			<title>Windows 7 Starter Edition Only Runs 3 Applications At Once</title>
						<link>http://feedproxy.google.com/~r/gfxmonk/~3/EWOmK3ER7pw/</link>
			
			<description>&lt;a href="http://www.cyberciti.biz/tips/windows-7-starter-edition.html"&gt;Windows 7 Starter Edition Only Runs 3 Applications At Once&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;A bunch of people respond that the only app they need is firefox. So why the crap are they still using windows? o_O&lt;/p&gt;

&lt;p&gt;Along with some other brilliant suggestions: &lt;em&gt;just run virtualbox with linux on it!&lt;/em&gt;. ugh...&lt;/p&gt;

&lt;p&gt;Gruber &lt;a href="http://daringfireball.net/linked/2009/04/21/windows-7-starter"&gt;calls it&lt;/a&gt; "Windows 7: We Hold You in Contempt and Dare You, Fucking Dare You, to Try Something Else Edition". Not far off, and yet I'm sure there will be many "happy" (is oblivious a better term?) customers.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gfxmonk/~4/EWOmK3ER7pw" height="1" width="1"/&gt;</description>
			<pubDate>Fri, 24 Apr 2009 08:27:25 +1000</pubDate>
						<guid isPermaLink="false">http://gfxmonk.net/?action=view&amp;url=link.322</guid>
			<dc:creator>Tim Cuthbertson</dc:creator>
		<feedburner:origLink>http://gfxmonk.net/?action=view&amp;url=link.322</feedburner:origLink></item>
		<item>
			<title>Introduction to GNU Screen</title>
						<link>http://feedproxy.google.com/~r/gfxmonk/~3/0eiUKmtAOmA/</link>
			
			<description>&lt;a href="http://www.nixtutor.com/linux/introduction-to-gnu-screen/"&gt;Introduction to GNU Screen&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I've always felt it would be great to use this screen, but never had the cause nor the dedication. Now I'm kinda excited about it...&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/gfxmonk/~4/0eiUKmtAOmA" height="1" width="1"/&gt;</description>
			<pubDate>Wed, 22 Apr 2009 21:55:29 +1000</pubDate>
						<guid isPermaLink="false">http://gfxmonk.net/?action=view&amp;url=link.321</guid>
			<dc:creator>Tim Cuthbertson</dc:creator>
		<feedburner:origLink>http://gfxmonk.net/?action=view&amp;url=link.321</feedburner:origLink></item>
	</channel>
</rss>
