<?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/"
	>

<channel>
	<title>Push cx &#187; Perl</title>
	<atom:link href="http://push.cx/tag/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://push.cx</link>
	<description>A traveling geek&#039;s blog on development, games, and the web</description>
	<lastBuildDate>Fri, 14 Oct 2011 10:24:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Developing With Evil</title>
		<link>http://push.cx/2006/developing-with-evil</link>
		<comments>http://push.cx/2006/developing-with-evil#comments</comments>
		<pubDate>Thu, 15 Jun 2006 19:50:06 +0000</pubDate>
		<dc:creator>Peter Harkins</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://push.cx/2006/developing-with-evil</guid>
		<description><![CDATA[allaryin: whee&#8230; allaryin: i&#8217;ve been given a job to put a simple email address subscription form on a site Harkins: sounds pretty easy allaryin: and&#8230; as far as i can tell, the server has neither php nor perl :P allaryin: i&#8217;m running out of options :P Harkins: cgi, baby allaryin: for db access? Harkins: Or [...]]]></description>
			<content:encoded><![CDATA[<p>
<span style="color: red">allaryin</span>: whee&#8230;<br />
<span style="color: red">allaryin</span>: i&#8217;ve been given a job to put a simple email address subscription form on a site<br />
<span style="color: blue">Harkins</span>: sounds pretty easy<br />
<span style="color: red">allaryin</span>: and&#8230; as far as i can tell, the server has neither php nor perl :P<br />
<span style="color: red">allaryin</span>: i&#8217;m running out of options :P<br />
<span style="color: blue">Harkins</span>: cgi, baby<br />
<span style="color: red">allaryin</span>: for db access?<br />                  <span style="color: blue">Harkins</span>: Or change the target of the form to a server you control running PHP/perl that saves the data and redirects back to the other server.<br />
<span style="color: red">allaryin</span>: yeah&#8230;<br />                         <span style="color: red">allaryin</span>: but i really don&#8217;t want to commit any of our server resources to their site :P<br />
<span style="color: green">BSDCat</span>: I think a &#8216;simplicity&#8217; fairy just lost its wings<br />
<span style="color: blue">Harkins</span>: Or make the form GET and write a cron job to scrape access.log.<br />
<span style="color: red">allaryin</span>: &#8230;<br />
<span style="color: red">allaryin</span>: wow.<br />
<span style="color: blue">Harkins</span>: Yes, I&#8217;m evil.<br />
<span style="color: red">allaryin</span>: it&#8217;s beautiful really<br />
<span style="color: blue">Harkins</span>: bwa<br />
<span style="color: red">allaryin</span>: but yes, evil<br />
</p>
 <img src="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=129" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://push.cx/2006/developing-with-evil/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strings are a Domain-Specific Language</title>
		<link>http://push.cx/2006/strings-are-a-domain-specific-language</link>
		<comments>http://push.cx/2006/strings-are-a-domain-specific-language#comments</comments>
		<pubDate>Sat, 27 May 2006 23:11:26 +0000</pubDate>
		<dc:creator>Peter Harkins</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://push.cx/2006/strings-are-a-domain-specific-language</guid>
		<description><![CDATA[Question: Isn&#8217;t a domain-specific language just the same thing as a library? Source: Pretty much everyone the first time they hear of DSLs. Answer: No, a DSL is much more than a library, and I have an example that won&#8217;t make you say, &#8220;Well, sure, if you&#8217;re doing something that esoteric&#8230;&#8221; My example of a [...]]]></description>
			<content:encoded><![CDATA[<blockquote>
Question: Isn&#8217;t a domain-specific language just the same thing as a library?
<p style="font-size: 75%; text-align: right">Source: Pretty much everyone the first time they hear of DSLs.</p>
</blockquote>

<p>
Answer: No, a DSL is much more than a library, and I have an example that won&#8217;t make you say, &#8220;Well, sure, if you&#8217;re doing something <i>that</i> esoteric&#8230;&#8221;
</p>

<p>
My example of a domain-specific language is strings. No, seriously. Let&#8217;s figure out the length of a string in <a href="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5pbnQ4MGgub3JnL3N0cmxlbi8=">x86 assembly</a>:
</p>

<pre>&nbsp;
strlen:
	<span style="color: #00007f;">push</span>	<span style="color: #46aa03; font-weight:bold;">edi</span>
	<span style="color: #00007f;">sub</span>	<span style="color: #46aa03; font-weight:bold;">ecx</span>, <span style="color: #46aa03; font-weight:bold;">ecx</span>
	<span style="color: #00007f;">mov</span>	<span style="color: #46aa03; font-weight:bold;">edi</span>, <span style="color: #66cc66;">&#91;</span><span style="color: #46aa03; font-weight:bold;">esp</span>+<span style="color: #ff0000;">8</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #00007f;">not</span>	<span style="color: #46aa03; font-weight:bold;">ecx</span>
	<span style="color: #00007f;">sub</span>	<span style="color: #46aa03; font-weight:bold;">al</span>, <span style="color: #46aa03; font-weight:bold;">al</span>
	<span style="color: #00007f;">cld</span>
<span style="color: #00007f;">repne</span>	<span style="color: #00007f;">scasb</span>
	<span style="color: #00007f;">not</span>	<span style="color: #46aa03; font-weight:bold;">ecx</span>
	<span style="color: #00007f;">pop</span>	<span style="color: #46aa03; font-weight:bold;">edi</span>
	<span style="color: #00007f;">lea</span>	<span style="color: #46aa03; font-weight:bold;">eax</span>, <span style="color: #66cc66;">&#91;</span>ecx-<span style="color: #ff0000;">1</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #00007f;">ret</span></pre>

<p>
Computer memory is one big linear stream of bytes we can scan through, looking for the null that terminates our string. Boy, is that some fast code &#8212; we might even call it efficient, if we ignore the fact that we&#8217;ll reach the eventual heat death of the universe before we finish our <a href="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5jZXJhZG8uY29tL3dlYjIwcXVpei5odG0=">web 2.0</a> app.
</p>

<p>
So we move up in abstraction to C, which has arrays. And you can pretend a string is an array and walk it looking for that null terminator:
</p>

<pre>&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> my_strlen<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> *c<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #993333;">int</span> l = <span style="color: #cc66cc;">0</span>;
    <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>*c++<span style="color: #66cc66;">&#41;</span> l++;
    <span style="color: #b1b100;">return</span> l;
<span style="color: #66cc66;">&#125;</span></pre>

<p>
This code is basically the same as in assembly, but it must be nicer to read because it uses all that stylish punctuation. Well, it&#8217;s not really nicer, maybe a string isn&#8217;t really just an array. So let&#8217;s look at Python:
</p>

<pre>&nbsp;
<span style="color: #b1b100;">len</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Hello, world!"</span><span style="color: #66cc66;">&#41;</span></pre>

<p>
Now that&#8217;s downright human-readable. And I&#8217;ll admit I&#8217;m fudging here by just calling the built-in <kbd>len()</kbd> instead of writing one, but it just works and there&#8217;s none of this messing around with null bytes.
</p>

<p>
Well, maybe there&#8217;s messing around with null bytes. I don&#8217;t have to know how Python implements <kbd>len()</kbd> and, more importantly, I don&#8217;t have to pretend a string is only an array or a small bit of sequentially-addressed memory.
</p>

<p>
To continue the example let&#8217;s look at regular expressions, a powerful way to search strings. We&#8217;ll write a pirate detector in Python:
</p>

<pre>&nbsp;
<span style="color: #b1b100;">import</span> re
matches = re.<span style="color: #202020;">search</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"ar+g+h"</span>, <span style="color: #ff0000;">"Oim a poirate, arrrgh!"</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">if</span> matches:
    <span style="color: #b1b100;">print</span> <span style="color: #ff0000;">"There must be a pirate, I heard someone say '%s'."</span> % matches.<span style="color: #202020;">group</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">else</span>:
    <span style="color: #b1b100;">print</span> <span style="color: #ff0000;">"No pirates detected."</span></pre>

<p>
This is important code, as pirates hide <a href="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL29zdGVlbGUuY29tL2FyY2hpdmVzLzIwMDUvMTIvYWFyZ2g=">all over the web</a>. But it&#8217;s pretty clunky, we have to import a library and call functions and evaluating responses and save objects&#8230; It&#8217;d sure be handy if regular expressions were part of the language like in Ruby:
</p>

<pre>&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #ff0000;">"Oim a poirate, arrrgh!"</span> =~ /ar+g+h/ <span style="color: #b1b100;">then</span>
  puts <span style="color: #ff0000;">"There must be a pirate, I heard someone say '#{$&amp;}'."</span>
<span style="color: #b1b100;">else</span>
  puts <span style="color: #ff0000;">"No pirates detected."</span>
<span style="color: #b1b100;">end</span></pre>

<p>
This code is even nicer, our regexp is a first-class type and tightly integrated into the language. The increase in stylish puncutation might make for a higher learning curve, but we can express ourselves much more naturally.
</p>

<p>
A DSL is all about moving up in abstraction until your code directly reflects the high-level concepts you&#8217;re working in. You don&#8217;t have to peer through a haze of bits and pointers, your actions become synonymous with your intentions.
</p> <img src="http://push.cx/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=110" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://push.cx/2006/strings-are-a-domain-specific-language/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

